Search in sources :

Example 1 with InstructorCourseInstructorDeleteAction

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

the class InstructorCourseInstructorDeleteActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes loginInstructor = typicalBundle.instructors.get("instructor1OfCourse1");
    String loginInstructorId = loginInstructor.googleId;
    String courseId = loginInstructor.courseId;
    String adminUserId = "admin.user";
    gaeSimulation.loginAsInstructor(loginInstructorId);
    ______TS("Typical case: Delete other instructor successfully, redirect back to edit page");
    InstructorAttributes instructorToDelete = typicalBundle.instructors.get("instructor2OfCourse1");
    String instructorEmailToDelete = instructorToDelete.email;
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
    InstructorCourseInstructorDeleteAction deleteAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, redirectResult.getStatusMessage());
    assertFalse(instructorsLogic.isEmailOfInstructorOfCourse(instructorEmailToDelete, courseId));
    String expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
    AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
    ______TS("Success: delete own instructor role from course, redirect back to courses page");
    instructorEmailToDelete = loginInstructor.email;
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
    deleteAction = getAction(submissionParams);
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, redirectResult.getStatusMessage());
    assertFalse(instructorsLogic.isGoogleIdOfInstructorOfCourse(loginInstructor.googleId, courseId));
    expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
    AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
    ______TS("Masquerade mode: delete instructor failed due to last instructor in course");
    instructorToDelete = typicalBundle.instructors.get("instructor4");
    instructorEmailToDelete = instructorToDelete.email;
    courseId = instructorToDelete.courseId;
    gaeSimulation.loginAsAdmin(adminUserId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmailToDelete };
    deleteAction = getAction(addUserIdToParams(instructorToDelete.googleId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, true, "idOfInstructor4", "idOfCourseNoEvals"), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETE_NOT_ALLOWED, redirectResult.getStatusMessage());
    assertTrue(instructorsLogic.isGoogleIdOfInstructorOfCourse(instructorToDelete.googleId, courseId));
    expectedLogSegment = "Instructor <span class=\"bold\"> " + instructorEmailToDelete + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> could not be deleted " + "as there is only one instructor left to be able to modify instructors.<br>";
    AssertHelper.assertContains(expectedLogSegment, deleteAction.getLogMessage());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseInstructorDeleteAction(teammates.ui.controller.InstructorCourseInstructorDeleteAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 InstructorCourseInstructorDeleteAction (teammates.ui.controller.InstructorCourseInstructorDeleteAction)1 RedirectResult (teammates.ui.controller.RedirectResult)1