-
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.
Merge branch 'master' into migrate-delete-account-request-action-test
- Loading branch information
Showing
8 changed files
with
369 additions
and
8 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
55 changes: 55 additions & 0 deletions
55
src/test/java/teammates/sqlui/webapi/DeleteAccountActionTest.java
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.InstructorPrivileges; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.Account; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.storage.sqlentity.Instructor; | ||
import teammates.ui.output.MessageOutput; | ||
import teammates.ui.webapi.DeleteAccountAction; | ||
|
||
/** | ||
* SUT: {@link DeleteAccountAction}. | ||
*/ | ||
public class DeleteAccountActionTest extends BaseActionTest<DeleteAccountAction> { | ||
String googleId = "user-googleId"; | ||
|
||
@Override | ||
protected String getActionUri() { | ||
return Const.ResourceURIs.ACCOUNT; | ||
} | ||
|
||
@Override | ||
protected String getRequestMethod() { | ||
return DELETE; | ||
} | ||
|
||
@Test | ||
protected void textExecute_nullParams_throwsInvalidHttpParameterException() { | ||
String[] params = { | ||
Const.ParamsNames.INSTRUCTOR_ID, null, | ||
}; | ||
verifyHttpParameterFailure(params); | ||
} | ||
|
||
@Test | ||
protected void testExecute_nonNullParams_success() { | ||
Course stubCourse = new Course("course-id", "name", Const.DEFAULT_TIME_ZONE, "institute"); | ||
Account stubAccount = new Account(googleId, "name", "[email protected]"); | ||
Instructor instructor = new Instructor(stubCourse, "name", "[email protected]", | ||
false, "", null, new InstructorPrivileges()); | ||
instructor.setAccount(stubAccount); | ||
String[] params = { | ||
Const.ParamsNames.INSTRUCTOR_ID, instructor.getGoogleId(), | ||
}; | ||
DeleteAccountAction action = getAction(params); | ||
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput(); | ||
assertEquals("Account is successfully deleted.", actionOutput.getMessage()); | ||
verify(mockLogic, times(1)).deleteAccountCascade(googleId); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
src/test/java/teammates/sqlui/webapi/DeleteFeedbackQuestionActionTest.java
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static teammates.common.util.Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER; | ||
|
||
import java.util.UUID; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.InstructorPrivileges; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.storage.sqlentity.FeedbackQuestion; | ||
import teammates.storage.sqlentity.FeedbackSession; | ||
import teammates.storage.sqlentity.Instructor; | ||
import teammates.ui.output.MessageOutput; | ||
import teammates.ui.webapi.DeleteFeedbackQuestionAction; | ||
|
||
/** | ||
* SUT: {@link DeleteFeedbackQuestionAction}. | ||
*/ | ||
public class DeleteFeedbackQuestionActionTest extends BaseActionTest<DeleteFeedbackQuestionAction> { | ||
|
||
private final Instructor typicalInstructor = getTypicalInstructor(); | ||
private final Course typicalCourse = typicalInstructor.getCourse(); | ||
private final FeedbackSession typicalFeedbackSession = getTypicalFeedbackSessionForCourse(typicalCourse); | ||
private final FeedbackQuestion typicalFeedbackQuestion = | ||
getTypicalFeedbackQuestionForSession(typicalFeedbackSession); | ||
|
||
@Override | ||
protected String getActionUri() { | ||
return Const.ResourceURIs.QUESTION; | ||
} | ||
|
||
@Override | ||
protected String getRequestMethod() { | ||
return DELETE; | ||
} | ||
|
||
@Test | ||
void testExecute_feedbackQuestionExists_success() { | ||
when(mockLogic.getFeedbackQuestion(typicalFeedbackQuestion.getId())).thenReturn(typicalFeedbackQuestion); | ||
|
||
String[] params = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, typicalFeedbackQuestion.getId().toString(), | ||
}; | ||
|
||
DeleteFeedbackQuestionAction action = getAction(params); | ||
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput(); | ||
|
||
assertEquals("Feedback question deleted!", actionOutput.getMessage()); | ||
} | ||
|
||
@Test | ||
void testExecute_feedbackQuestionDoesNotExist_failSilently() { | ||
UUID nonexistentQuestionId = UUID.fromString("11110000-0000-0000-0000-000000000000"); | ||
when(mockLogic.getFeedbackQuestion(nonexistentQuestionId)).thenReturn(null); | ||
|
||
String[] params = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, nonexistentQuestionId.toString(), | ||
}; | ||
|
||
DeleteFeedbackQuestionAction action = getAction(params); | ||
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput(); | ||
|
||
assertEquals("Feedback question deleted!", actionOutput.getMessage()); | ||
} | ||
|
||
@Test | ||
void testExecute_missingFeedbackQuestionId_throwsInvalidHttpParameterException() { | ||
String[] params = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, null, | ||
}; | ||
|
||
verifyHttpParameterFailure(params); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_nonExistentFeedbackQuestion_cannotAccess() { | ||
when(mockLogic.getFeedbackQuestion(typicalFeedbackQuestion.getId())).thenReturn(null); | ||
String[] submissionParams = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, typicalFeedbackQuestion.getId().toString(), | ||
}; | ||
|
||
verifyCannotAccess(submissionParams); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_withModifySessionPrivilege_canAccess() { | ||
when(mockLogic.getFeedbackQuestion(typicalFeedbackQuestion.getId())).thenReturn(typicalFeedbackQuestion); | ||
when(mockLogic.getFeedbackSession(typicalFeedbackQuestion.getFeedbackSession().getName(), | ||
typicalFeedbackQuestion.getCourseId())).thenReturn(typicalFeedbackSession); | ||
when(mockLogic.getInstructorByGoogleId(typicalCourse.getId(), typicalInstructor.getGoogleId())) | ||
.thenReturn(typicalInstructor); | ||
|
||
String[] submissionParams = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, typicalFeedbackQuestion.getId().toString(), | ||
}; | ||
|
||
loginAsInstructor(typicalInstructor.getGoogleId()); | ||
verifyCanAccess(submissionParams); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_withoutModifySessionPrivilege_cannotAccess() { | ||
// create instructor without modify session privilege | ||
Instructor instructorWithoutAccess = getTypicalInstructor(); | ||
instructorWithoutAccess.setPrivileges(new InstructorPrivileges(INSTRUCTOR_PERMISSION_ROLE_OBSERVER)); | ||
|
||
when(mockLogic.getFeedbackQuestion(typicalFeedbackQuestion.getId())).thenReturn(typicalFeedbackQuestion); | ||
when(mockLogic.getFeedbackSession(typicalFeedbackQuestion.getFeedbackSession().getName(), | ||
typicalFeedbackQuestion.getCourseId())).thenReturn(typicalFeedbackSession); | ||
when(mockLogic.getInstructorByGoogleId(typicalCourse.getId(), instructorWithoutAccess.getGoogleId())) | ||
.thenReturn(instructorWithoutAccess); | ||
|
||
String[] submissionParams = { | ||
Const.ParamsNames.FEEDBACK_QUESTION_ID, typicalFeedbackQuestion.getId().toString(), | ||
}; | ||
|
||
loginAsInstructor(instructorWithoutAccess.getGoogleId()); | ||
verifyCannotAccess(submissionParams); | ||
} | ||
|
||
} |
112 changes: 112 additions & 0 deletions
112
src/test/java/teammates/sqlui/webapi/DeleteNotificationActionTest.java
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.NotificationStyle; | ||
import teammates.common.datatransfer.NotificationTargetUser; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.Notification; | ||
import teammates.ui.output.MessageOutput; | ||
import teammates.ui.webapi.DeleteNotificationAction; | ||
|
||
/** | ||
* SUT: {@link DeleteNotificationAction}. | ||
*/ | ||
public class DeleteNotificationActionTest extends BaseActionTest<DeleteNotificationAction> { | ||
private static final String GOOGLE_ID = "user-googleId"; | ||
|
||
@Override | ||
String getActionUri() { | ||
return Const.ResourceURIs.NOTIFICATION; | ||
} | ||
|
||
@Override | ||
String getRequestMethod() { | ||
return DELETE; | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_admin_canAccess() { | ||
loginAsAdmin(); | ||
verifyCanAccess(); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_instructor_cannotAccess() { | ||
loginAsInstructor(GOOGLE_ID); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_student_cannotAccess() { | ||
loginAsStudent(GOOGLE_ID); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testSpecificAccessControl_loggedOut_cannotAccess() { | ||
logoutUser(); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testExecute_notificationExists_success() { | ||
Notification testNotification = new Notification( | ||
Instant.now(), | ||
Instant.ofEpochMilli(Instant.now().toEpochMilli() + 10000), | ||
NotificationStyle.INFO, | ||
NotificationTargetUser.GENERAL, | ||
"title", | ||
"message"); | ||
|
||
when(mockLogic.getNotification(testNotification.getId())).thenReturn(testNotification); | ||
|
||
String[] params = { | ||
Const.ParamsNames.NOTIFICATION_ID, testNotification.getId().toString(), | ||
}; | ||
|
||
DeleteNotificationAction action = getAction(params); | ||
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput(); | ||
|
||
assertEquals("Notification has been deleted.", actionOutput.getMessage()); | ||
reset(mockLogic); | ||
} | ||
|
||
@Test | ||
void testExecute_notificationDoesNotExist_failSilently() { | ||
UUID invalidUuid = UUID.randomUUID(); | ||
when(mockLogic.getNotification(invalidUuid)).thenReturn(null); | ||
|
||
String[] params = { | ||
Const.ParamsNames.NOTIFICATION_ID, invalidUuid.toString(), | ||
}; | ||
|
||
DeleteNotificationAction action = getAction(params); | ||
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput(); | ||
|
||
assertEquals("Notification has been deleted.", actionOutput.getMessage()); | ||
reset(mockLogic); | ||
} | ||
|
||
@Test | ||
void testExecute_missingNotificationUuid_throwsInvalidHttpParameterException() { | ||
String[] params = { | ||
Const.ParamsNames.NOTIFICATION_ID, null, | ||
}; | ||
|
||
verifyHttpParameterFailure(params); | ||
} | ||
|
||
@Test | ||
void testExecute_missingParameters_throwsInvalidHttpParameterException() { | ||
String[] params = {}; | ||
|
||
verifyHttpParameterFailure(params); | ||
} | ||
} |
Oops, something went wrong.