-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update privileges in Action class * Refactor UpdateInstructorPrivilegeAction class and add test for UpdateInstructorActionTest * Fix lint * Move method to InstructorsLogic and add test * Update test * Fix lint * Remove space changes * Remove redundant test data * Fix lint * Add description for test cases * Add more test cases * Remove databundle code * Fix lint
- Loading branch information
1 parent
524f88c
commit be2edf0
Showing
6 changed files
with
96 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ public void testAll() throws Exception { | |
testGetCoOwnersForCourse(); | ||
testUpdateInstructorByGoogleIdCascade(); | ||
testUpdateInstructorByEmail(); | ||
testUpdateToEnsureValidityOfInstructorsForTheCourse(); | ||
} | ||
|
||
private void testAddInstructor() throws Exception { | ||
|
@@ -646,4 +647,44 @@ private void testGetCoOwnersForCourse() { | |
&& generatedCoOwnersEmails.containsAll(coOwnersEmailsFromDataBundle)); | ||
} | ||
|
||
private void testUpdateToEnsureValidityOfInstructorsForTheCourse() { | ||
______TS("Should not grant the currently being edited instructor the privilege of modifying instructors"); | ||
|
||
______TS("The course has more than 1 instructor with modifying instructor privilege"); | ||
String courseId = "idOfTypicalCourse1"; | ||
InstructorAttributes instructorToUpdate = | ||
InstructorAttributes.builder(courseId, "[email protected]") | ||
.withGoogleId("idOfInstructor4") | ||
.withPrivileges( | ||
new InstructorPrivileges( | ||
Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_TUTOR | ||
) | ||
).build(); | ||
instructorsLogic.updateToEnsureValidityOfInstructorsForTheCourse(courseId, instructorToUpdate); | ||
|
||
assertFalse(instructorToUpdate.privileges.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
|
||
______TS("The course has 1 registered instructor with modifying instructor privilege"); | ||
courseId = "idOfArchivedCourse"; | ||
instructorsLogic.updateToEnsureValidityOfInstructorsForTheCourse(courseId, instructorToUpdate); | ||
|
||
assertFalse(instructorToUpdate.privileges.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
|
||
______TS("Should grant the currently being edited instructor the privilege of modifying instructors"); | ||
|
||
______TS("The course only has 1 instructor with modifying instructor privilege which is being edited"); | ||
courseId = "idOfCourseNoEvals"; | ||
instructorsLogic.updateToEnsureValidityOfInstructorsForTheCourse(courseId, instructorToUpdate); | ||
|
||
assertTrue(instructorToUpdate.privileges.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
|
||
______TS("The course only has 1 instructor with modifying instructor privilege which is not registered"); | ||
instructorToUpdate.privileges.updatePrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR, false); | ||
courseId = "idOfSampleCourse-demo"; | ||
instructorsLogic.deleteInstructorCascade(courseId, "[email protected]"); | ||
instructorsLogic.updateToEnsureValidityOfInstructorsForTheCourse(courseId, instructorToUpdate); | ||
|
||
assertTrue(instructorToUpdate.privileges.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,10 @@ protected void testExecute() { | |
|
||
String newInstructorName = "newName"; | ||
String newInstructorEmail = "[email protected]"; | ||
String newInstructorRole = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_TUTOR; | ||
|
||
InstructorCreateRequest reqBody = new InstructorCreateRequest(instructorId, newInstructorName, | ||
newInstructorEmail, instructorToEdit.role, | ||
newInstructorEmail, newInstructorRole, | ||
instructorDisplayName, instructorToEdit.isDisplayedToStudents); | ||
|
||
UpdateInstructorAction updateInstructorAction = getAction(reqBody, submissionParams); | ||
|
@@ -61,10 +62,10 @@ protected void testExecute() { | |
assertEquals(newInstructorName, response.getName()); | ||
assertEquals(newInstructorEmail, editedInstructor.email); | ||
assertEquals(newInstructorEmail, response.getEmail()); | ||
assertTrue(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_COURSE)); | ||
assertTrue(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
assertTrue(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_SESSION)); | ||
assertTrue(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_STUDENT)); | ||
assertFalse(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_COURSE)); | ||
assertFalse(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_INSTRUCTOR)); | ||
assertFalse(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_SESSION)); | ||
assertFalse(editedInstructor.isAllowedForPrivilege(Const.InstructorPermissions.CAN_MODIFY_STUDENT)); | ||
|
||
______TS("Failure case: edit failed due to invalid parameters"); | ||
|
||
|