Search in sources :

Example 1 with StudentCourseJoinAction

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

the class StudentCourseJoinActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    StudentCourseJoinAction joinAction;
    RedirectResult redirectResult;
    String[] submissionParams;
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    StudentsDb studentsDb = new StudentsDb();
    student1InCourse1 = studentsDb.getStudentForGoogleId(student1InCourse1.course, student1InCourse1.googleId);
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("not enough parameters");
    verifyAssumptionFailure();
    ______TS("typical case");
    String idOfNewStudent = "idOfNewStudent";
    StudentAttributes newStudentData = StudentAttributes.builder(student1InCourse1.course, "nameOfNewStudent", "newStudent@course1.com").withSection(student1InCourse1.section).withTeam(student1InCourse1.team).withComments("This is a new student").build();
    studentsDb.createEntity(newStudentData);
    gaeSimulation.loginUser(idOfNewStudent);
    String newStudentKey = StringHelper.encrypt(studentsDb.getStudentForEmail(newStudentData.course, newStudentData.email).key);
    /*
         * Reason why get student attributes for student just added again from
         * StudentsDb:below test needs the student's key, which is auto
         * generated when creating the student instance.So the reg key needs to
         * be obtained by calling the getter from logic to retrieve again
         */
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE };
    joinAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(joinAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_COURSE_JOIN_CONFIRMATION, false, idOfNewStudent), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_COURSE_JOIN_AUTHENTICATED, newStudentKey, Const.ActionURIs.STUDENT_PROFILE_PAGE), ((StudentCourseJoinConfirmationPageData) pageResult.data).getConfirmUrl());
    assertEquals("", pageResult.getStatusMessage());
    ______TS("skip confirmation");
    gaeSimulation.logoutUser();
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE, Const.ParamsNames.STUDENT_EMAIL, newStudentData.email, Const.ParamsNames.COURSE_ID, newStudentData.course };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.STUDENT_COURSE_JOIN_AUTHENTICATED, newStudentKey, Const.ActionURIs.STUDENT_PROFILE_PAGE.replace("/", "%2F"), false), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    // delete the new student
    studentsDb.deleteStudentWithoutDocument(newStudentData.course, newStudentData.email);
    ______TS("Non-existent student attempting to join course displays error");
    gaeSimulation.loginUser(idOfNewStudent);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, newStudentKey, Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_PROFILE_PAGE, Const.ParamsNames.STUDENT_EMAIL, newStudentData.email, Const.ParamsNames.COURSE_ID, newStudentData.course };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(Const.ActionURIs.STUDENT_HOME_PAGE, redirectResult.destination);
    assertEquals(String.format(Const.StatusMessages.NON_EXISTENT_STUDENT_ATTEMPTING_TO_JOIN_COURSE, newStudentData.course), redirectResult.getStatusMessage());
    assertEquals("warning", redirectResult.getStatusMessageColor());
    assertTrue(redirectResult.isError);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) RedirectResult(teammates.ui.controller.RedirectResult) StudentCourseJoinAction(teammates.ui.controller.StudentCourseJoinAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 StudentsDb (teammates.storage.api.StudentsDb)1 RedirectResult (teammates.ui.controller.RedirectResult)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 StudentCourseJoinAction (teammates.ui.controller.StudentCourseJoinAction)1