-
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 db-migrate-tests
- Loading branch information
Showing
4 changed files
with
181 additions
and
2 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
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); | ||
} | ||
|
||
} |