-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#12048] Migrate tests for GetDeadlineExtensionActionTest #13266
Merged
jasonqiu212
merged 6 commits into
TEAMMATES:master
from
InfinityTwo:db-migration-deadline-ext
Mar 22, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1880d1
Add initial code for GetDeadlineExtensionActionTest
InfinityTwo ea3c982
Fix success case
InfinityTwo a4665f3
Merge branch 'master' into db-migration-deadline-ext
InfinityTwo 48f041d
Add instructor deadline extension for coverage
InfinityTwo 1c5b57d
Merge branch 'master' into db-migration-deadline-ext
InfinityTwo 3ea2190
Merge branch 'master' into db-migration-deadline-ext
jasonqiu212 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
171 changes: 171 additions & 0 deletions
171
src/test/java/teammates/sqlui/webapi/GetDeadlineExtensionActionTest.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,171 @@ | ||
package teammates.sqlui.webapi; | ||
|
||
import static org.mockito.ArgumentMatchers.isA; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.attributes.DeadlineExtensionAttributes; | ||
import teammates.common.util.Const; | ||
import teammates.storage.sqlentity.FeedbackSession; | ||
import teammates.storage.sqlentity.User; | ||
import teammates.ui.output.DeadlineExtensionData; | ||
import teammates.ui.webapi.EntityNotFoundException; | ||
import teammates.ui.webapi.GetDeadlineExtensionAction; | ||
import teammates.ui.webapi.JsonResult; | ||
|
||
/** | ||
* SUT: {@link GetDeadlineExtensionAction}. | ||
*/ | ||
public class GetDeadlineExtensionActionTest extends BaseActionTest<GetDeadlineExtensionAction> { | ||
private DeadlineExtensionAttributes deadlineExtension; | ||
|
||
@Override | ||
protected String getActionUri() { | ||
return Const.ResourceURIs.DEADLINE_EXTENSION; | ||
} | ||
|
||
@Override | ||
protected String getRequestMethod() { | ||
return GET; | ||
} | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
logoutUser(); | ||
deadlineExtension = getTypicalDeadlineExtensionAttributesStudent(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_admin_cannotAccess() { | ||
loginAsAdmin(); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_maintainers_cannotAccess() { | ||
loginAsMaintainer(); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_instructor_cannotAccess() { | ||
loginAsInstructor(Const.ParamsNames.INSTRUCTOR_ID); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_student_cannotAccess() { | ||
loginAsStudent(Const.ParamsNames.STUDENT_ID); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_loggedOut_cannotAccess() { | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testAccessControl_unregistered_cannotAccess() { | ||
loginAsUnregistered(Const.ParamsNames.USER_ID); | ||
verifyCannotAccess(); | ||
} | ||
|
||
@Test | ||
void testExecute_noParameters_shouldFail() { | ||
verifyHttpParameterFailure(); | ||
} | ||
|
||
@Test | ||
void testExecute_missingParameter_shouldFail() { | ||
/* Loops through each parameter pairs and removes each parameter pair to test for that | ||
* missing parameter pair case. | ||
*/ | ||
for (int i = 0; i < getNormalParams().length / 2; i++) { | ||
ArrayList<String> params = new ArrayList<>(Arrays.asList(getNormalParams())); | ||
params.remove(i * 2); | ||
params.remove(i * 2); | ||
String[] paramsArray = params.toArray(new String[0]); | ||
verifyHttpParameterFailure(paramsArray); | ||
} | ||
} | ||
|
||
@Test | ||
void testExecute_deadlineExtensionMissing_shouldFail() { | ||
String[] params = getNormalParams(); | ||
|
||
when(mockLogic.getFeedbackSession(deadlineExtension.getFeedbackSessionName(), deadlineExtension.getCourseId())) | ||
.thenReturn(getTypicalDeadlineExtensionStudent().getFeedbackSession()); | ||
when(mockLogic.getExtendedDeadlineForUser(isA(FeedbackSession.class), isA(User.class))) | ||
.thenReturn(null); | ||
|
||
EntityNotFoundException enfe = verifyEntityNotFound(params); | ||
assertEquals("Deadline extension for course id: " + deadlineExtension.getCourseId() + " and " | ||
+ "feedback session name: " + deadlineExtension.getFeedbackSessionName() + " and student " | ||
+ "email: " + deadlineExtension.getUserEmail() + " not found.", | ||
enfe.getMessage()); | ||
} | ||
|
||
@Test | ||
void testExecute_typicalCaseStudent_shouldSucceed() { | ||
String[] params = getNormalParams(); | ||
|
||
when(mockLogic.getFeedbackSession(deadlineExtension.getFeedbackSessionName(), deadlineExtension.getCourseId())) | ||
.thenReturn(getTypicalDeadlineExtensionStudent().getFeedbackSession()); | ||
when(mockLogic.getStudentForEmail(deadlineExtension.getCourseId(), deadlineExtension.getUserEmail())) | ||
.thenReturn(getTypicalStudent()); | ||
when(mockLogic.getExtendedDeadlineForUser(isA(FeedbackSession.class), isA(User.class))) | ||
.thenReturn(deadlineExtension.getEndTime()); | ||
|
||
GetDeadlineExtensionAction a = getAction(params); | ||
JsonResult r = getJsonResult(a); | ||
|
||
DeadlineExtensionData response = (DeadlineExtensionData) r.getOutput(); | ||
compareOutput(response); | ||
} | ||
|
||
@Test | ||
void testExecute_typicalCaseInstructor_shouldSucceed() { | ||
deadlineExtension = getTypicalDeadlineExtensionAttributesInstructor(); | ||
String[] params = getNormalParams(); | ||
|
||
when(mockLogic.getFeedbackSession(deadlineExtension.getFeedbackSessionName(), deadlineExtension.getCourseId())) | ||
.thenReturn(getTypicalDeadlineExtensionInstructor().getFeedbackSession()); | ||
when(mockLogic.getInstructorForEmail(deadlineExtension.getCourseId(), deadlineExtension.getUserEmail())) | ||
.thenReturn(getTypicalInstructor()); | ||
when(mockLogic.getExtendedDeadlineForUser(isA(FeedbackSession.class), isA(User.class))) | ||
.thenReturn(deadlineExtension.getEndTime()); | ||
|
||
GetDeadlineExtensionAction a = getAction(params); | ||
JsonResult r = getJsonResult(a); | ||
|
||
DeadlineExtensionData response = (DeadlineExtensionData) r.getOutput(); | ||
|
||
compareOutput(response); | ||
} | ||
|
||
private String[] getNormalParams() { | ||
return new String[] { | ||
Const.ParamsNames.COURSE_ID, deadlineExtension.getCourseId(), | ||
Const.ParamsNames.FEEDBACK_SESSION_NAME, deadlineExtension.getFeedbackSessionName(), | ||
Const.ParamsNames.USER_EMAIL, deadlineExtension.getUserEmail(), | ||
Const.ParamsNames.IS_INSTRUCTOR, Boolean.toString(deadlineExtension.getIsInstructor()), | ||
}; | ||
} | ||
|
||
private void compareOutput(DeadlineExtensionData response) { | ||
assertEquals(deadlineExtension.getCourseId(), response.getCourseId()); | ||
assertEquals(deadlineExtension.getFeedbackSessionName(), response.getFeedbackSessionName()); | ||
assertEquals(deadlineExtension.getUserEmail(), response.getUserEmail()); | ||
assertEquals(deadlineExtension.getIsInstructor(), response.getIsInstructor()); | ||
assertEquals(deadlineExtension.getEndTime().toEpochMilli(), | ||
Instant.ofEpochMilli(response.getEndTime()).toEpochMilli()); | ||
assertEquals(deadlineExtension.getSentClosingSoonEmail(), response.getSentClosingSoonEmail()); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!