Search in sources :

Example 1 with InstructorCourseJoinAction

use of teammates.ui.controller.InstructorCourseJoinAction in project teammates by TEAMMATES.

the class InstructorCourseJoinActionTest method testExecuteAndPostProcess.

@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    InstructorsDb instrDb = new InstructorsDb();
    // Reassign to let "key" variable in "instructor" not to be null
    instructor = instrDb.getInstructorForGoogleId(instructor.courseId, instructor.googleId);
    String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("Invalid key, redirect for confirmation again");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
    InstructorCourseJoinAction confirmAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "idOfInstructor1OfCourse1", invalidEncryptedKey), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    String expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + invalidEncryptedKey;
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
    ______TS("Already registered instructor, redirect straight to authentication page");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
    confirmAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN_AUTHENTICATED, StringHelper.encrypt(instructor.key), false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("", redirectResult.getStatusMessage());
    expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(instructor.key);
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
    ______TS("Typical case: unregistered instructor, redirect to confirmation page");
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAT.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAT.instr";
    AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    gaeSimulation.loginUser(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    confirmAction = getAction(submissionParams);
    pageResult = getShowPageResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "ICJAT.instr", StringHelper.encrypt(newInstructor.key)), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(newInstructor.key);
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) ShowPageResult(teammates.ui.controller.ShowPageResult) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorCourseJoinAction(teammates.ui.controller.InstructorCourseJoinAction) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 InstructorsDb (teammates.storage.api.InstructorsDb)1 InstructorCourseJoinAction (teammates.ui.controller.InstructorCourseJoinAction)1 RedirectResult (teammates.ui.controller.RedirectResult)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1