Search in sources :

Example 71 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateStudentCourseJoinEmail.

@Test
public void testGenerateStudentCourseJoinEmail() throws IOException {
    ______TS("student course join email");
    CourseAttributes course = CourseAttributes.builder("idOfTypicalCourse1", "Course Name", ZoneId.of("UTC")).build();
    StudentAttributes student = StudentAttributes.builder("", "Student Name", "student@email.tmt").withKey("skxxxxxxxxxks").build();
    EmailWrapper email = new EmailGenerator().generateStudentCourseJoinEmail(course, student);
    String subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithCoOwnersJoinEmail.html");
    ______TS("student course with co-owners join email after Google ID reset");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithCoOwnersRejoinAfterGoogleIdResetEmail.html");
    ______TS("student course (without co-owners) join email");
    course = CourseAttributes.builder("course-id", "Course Name", ZoneId.of("UTC")).build();
    email = new EmailGenerator().generateStudentCourseJoinEmail(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithoutCoOwnersJoinEmail.html");
    ______TS("student course (without-co-owners) join email after Google ID reset");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithoutCoOwnersRejoinAfterGoogleIdResetEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 72 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateStudentCourseJoinEmail_testSanitization.

@Test
public void testGenerateStudentCourseJoinEmail_testSanitization() throws IOException {
    ______TS("student course join email: sanitization required");
    CourseAttributes course = coursesLogic.getCourse("idOfTestingSanitizationCourse");
    StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "normal@sanitization.tmt");
    EmailWrapper email = new EmailGenerator().generateStudentCourseJoinEmail(course, student1);
    String subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/studentCourseJoinEmailTestingSanitization.html");
    ______TS("student course join email after Google ID reset: sanitization required");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student1);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/studentCourseRejoinAfterGoogleIdResetEmailTestingSanitization.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 73 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateFeedbackSessionEmails.

@Test
public void testGenerateFeedbackSessionEmails() throws IOException {
    FeedbackSessionAttributes session = fsLogic.getFeedbackSession("First feedback session", "idOfTypicalCourse1");
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "student1InCourse1@gmail.tmt");
    InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail(course.getId(), "instructor1@course1.tmt");
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(session.getCourseId());
    List<InstructorAttributes> instructors = instructorsLogic.getInstructorsForCourse(session.getCourseId());
    InstructorAttributes instructorToNotify = instructorsLogic.getInstructorForGoogleId(session.getCourseId(), instructor1.getGoogleId());
    ______TS("feedback session opening emails");
    List<EmailWrapper> emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(session);
    assertEquals(10, emails.size());
    String subject = String.format(EmailType.FEEDBACK_OPENING.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionOpeningEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionOpeningEmailForInstructor.html");
    ______TS("feedback session reminders");
    emails = new EmailGenerator().generateFeedbackSessionReminderEmails(session, students, instructors, instructorToNotify);
    // (5 instructors, 5 students reminded) and (1 instructor to be notified)
    assertEquals(11, emails.size());
    subject = String.format(EmailType.FEEDBACK_SESSION_REMINDER.getSubject(), course.getName(), session.getFeedbackSessionName());
    String lineInEmailCopyToInstructor = "The email below has been sent to students of course:";
    // Verify the student reminder email
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionReminderEmailForStudent.html");
    // Verify the Student email copy send to the instructor
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionReminderEmailCopyToInstructor.html", lineInEmailCopyToInstructor);
    // Verify the instructor reminder email
    String lineInEmailToInstructor = "/page/instructorFeedbackSubmissionEditPage?courseid=idOfTypicalCourse1&fsname=First+feedback+session";
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionReminderEmailForInstructor.html", lineInEmailToInstructor);
    ______TS("feedback session closing alerts");
    emails = new EmailGenerator().generateFeedbackSessionClosingEmails(session);
    assertEquals(8, emails.size());
    subject = String.format(EmailType.FEEDBACK_CLOSING.getSubject(), course.getName(), session.getFeedbackSessionName());
    // student1 has completed the feedback session and closing alert is only sent for those who are
    // yet to complete, so we resort to student5
    StudentAttributes student5 = studentsLogic.getStudentForEmail(course.getId(), "student5InCourse1@gmail.tmt");
    for (EmailWrapper email : emails) {
        if (email.getRecipient().equals(student1.email)) {
            fail("student1 has completed the session and are not supposed to receive email");
        }
    }
    verifyEmailReceivedCorrectly(emails, student5.email, subject, "/sessionClosingEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosingEmailForInstructor.html");
    ______TS("feedback session closed alerts");
    emails = new EmailGenerator().generateFeedbackSessionClosedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_CLOSED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionClosedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosedEmailForInstructor.html");
    ______TS("feedback session published alerts");
    emails = new EmailGenerator().generateFeedbackSessionPublishedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_PUBLISHED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionPublishedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionPublishedEmailForInstructor.html");
    ______TS("feedback session unpublished alerts");
    emails = new EmailGenerator().generateFeedbackSessionUnpublishedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_UNPUBLISHED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionUnpublishedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionUnpublishedEmailForInstructor.html");
    ______TS("send summary of all feedback sessions of course email");
    EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(session.getCourseId(), student1);
    subject = String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/summaryOfFeedbackSessionsOfCourseEmailForStudent.html");
    ______TS("feedback session submission email");
    Instant time = TimeHelper.parseInstant("2016-09-04 05:30 AM +0000");
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, student1.email, subject, "/sessionSubmissionConfirmationEmailPositiveTimeZone.html");
    setTimeZoneButMaintainLocalDate(session, ZoneId.of("Pacific/Marquesas"));
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailNegativeTimeZone.html");
    setTimeZoneButMaintainLocalDate(session, ZoneId.of("UTC"));
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailZeroTimeZone.html");
    ______TS("no email alerts sent for sessions not answerable/viewable for students");
    FeedbackSessionAttributes privateSession = fsLogic.getFeedbackSession("Private feedback session", "idOfTypicalCourse2");
    emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionClosingEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionClosedEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionPublishedEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionUnpublishedEmails(privateSession);
    assertTrue(emails.isEmpty());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) Instant(java.time.Instant) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 74 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateUserCourseRegisterEmail.

@Test
public void testGenerateUserCourseRegisterEmail() throws IOException {
    ______TS("student course register email");
    CourseAttributes course = CourseAttributes.builder("idOfTypicalCourse1", "Course Name", ZoneId.of("UTC")).build();
    String name = "User Name";
    String emailAddress = "user@email.tmt";
    String googleId = "user.googleid";
    EmailWrapper email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, googleId, false, course);
    String subject = String.format(EmailType.USER_COURSE_REGISTER.getSubject(), course.getName(), course.getId());
    verifyEmail(email, emailAddress, subject, "/studentCourseRegisterEmail.html");
    ______TS("instructor course register email");
    email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, googleId, true, course);
    subject = String.format(EmailType.USER_COURSE_REGISTER.getSubject(), course.getName(), course.getId());
    verifyEmail(email, emailAddress, subject, "/instructorCourseRegisterEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 75 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class CoursesDbTest method testUpdateCourse.

@Test
public void testUpdateCourse() throws Exception {
    ______TS("Failure: null paramater");
    try {
        coursesDb.updateCourse(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
    ______TS("Failure: update course with invalid parameters");
    CourseAttributes invalidCourse = CourseAttributes.builder("", "", ZoneId.of("UTC")).build();
    try {
        coursesDb.updateCourse(invalidCourse);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains("The field 'course ID' is empty", e.getMessage());
        AssertHelper.assertContains("The field 'course name' is empty", e.getMessage());
    }
    ______TS("fail: non-exisitng course");
    CourseAttributes nonExistentCourse = CourseAttributes.builder("CDbT.non-exist-course", "Non existing course", ZoneId.of("UTC")).build();
    try {
        coursesDb.updateCourse(nonExistentCourse);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals(CoursesDb.ERROR_UPDATE_NON_EXISTENT_COURSE, e.getMessage());
    }
    ______TS("success: typical case");
    CourseAttributes c = createNewCourse();
    CourseAttributes updatedCourse = CourseAttributes.builder(c.getId(), c.getName() + " updated", ZoneId.of("UTC")).build();
    coursesDb.updateCourse(updatedCourse);
    CourseAttributes retrieved = coursesDb.getCourse(c.getId());
    assertEquals(c.getName() + " updated", retrieved.getName());
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4