-
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 GetStudentActionTest #13241
base: master
Are you sure you want to change the base?
[#12048] Migrate tests for GetStudentActionTest #13241
Conversation
Hi @mingyang143, thank you for your interest in contributing to TEAMMATES!
Please address the above before we proceed to review your PR. |
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.
some comments on checking the output. rest looks good!
GetStudentAction action = getAction(params); | ||
StudentData studentData = (StudentData) getJsonResult(action).getOutput(); | ||
assertEquals(studentData.getEmail(), stubStudent.getEmail()); | ||
assertEquals(studentData.getKey(), null); |
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.
maybe we can replace this with assertNull(studentData.getKey())
assertEquals(studentData.getEmail(), stubStudent.getEmail()); | ||
assertEquals(studentData.getKey(), null); |
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.
maybe we can follow the old test case and create a private method for checking if the student data matches?
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.
Logic looks good, would be good to incorporate some of the review comments, thanks for the work!
} | ||
|
||
@Test | ||
void testSpecificAccessControl_instructorWithoutPermission_cannotAccess() { |
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.
nit: please add some blank lines for better readability
/** | ||
* SUT: {@link GetStudentAction}. | ||
*/ | ||
public class GetStudentActionTest extends BaseActionTest<GetStudentAction> { |
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.
nit: please add some blank lines for better readability in some of the test methods
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 work, just some comments
loginAsInstructor(stubInstructor.getGoogleId()); | ||
String[] params = { | ||
Const.ParamsNames.COURSE_ID, stubCourse.getId(), | ||
Const.ParamsNames.STUDENT_ID, stubStudent.getGoogleId(), |
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.
I dont think the STUDENT_ID
param is being used in this action, i tried commenting it out but the test still passes
loginAsInstructor(stubInstructor.getGoogleId()); | ||
String[] params = { | ||
Const.ParamsNames.COURSE_ID, stubCourse.getId(), | ||
Const.ParamsNames.STUDENT_ID, stubStudent.getGoogleId(), |
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.
Same here regarding STUDENT_ID
String[] params = { | ||
Const.ParamsNames.COURSE_ID, stubCourse.getId(), | ||
}; |
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.
Since the typical instructor access includes STUDENT_EMAIL
param lets add it here, we also need it to reach the block that checks if an instructor has access
teammates/src/main/java/teammates/ui/webapi/GetStudentAction.java
Lines 40 to 51 in 9c2d80c
if (studentEmail != null) { | |
student = sqlLogic.getStudentForEmail(courseId, studentEmail); | |
if (student == null || userInfo == null || !userInfo.isInstructor) { | |
throw new UnauthorizedAccessException(UNAUTHORIZED_ACCESS); | |
} | |
Instructor instructor = sqlLogic.getInstructorByGoogleId(courseId, userInfo.id); | |
gateKeeper.verifyAccessible(instructor, sqlLogic.getCourse(courseId), | |
student.getTeamName(), | |
Const.InstructorPermissions.CAN_VIEW_STUDENT_IN_SECTIONS); |
Without the STUDENT_EMAIL
param we are testing this block
teammates/src/main/java/teammates/ui/webapi/GetStudentAction.java
Lines 54 to 61 in 9c2d80c
} else { | |
if (userInfo == null || !userInfo.isStudent) { | |
throw new UnauthorizedAccessException(UNAUTHORIZED_ACCESS); | |
} | |
student = sqlLogic.getStudentByGoogleId(courseId, userInfo.id); | |
gateKeeper.verifyAccessible(student, course); | |
} |
void testSpecificAccessControl_studentPublicAccess_cannotAccess() { | ||
loginAsStudent(stubStudent.getGoogleId()); | ||
when(mockLogic.getCourse(stubCourse.getId())).thenReturn(stubCourse); | ||
when(mockLogic.getStudentByGoogleId(stubCourse.getId(), stubStudent.getGoogleId())).thenReturn(stubStudent); |
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.
If i understand this test case correctly this should be
when(mockLogic.getStudentByGoogleId(stubCourse.getId(), stubStudent.getGoogleId())).thenReturn(stubStudent); | |
when(mockLogic.getStudentForEmail(stubCourse.getId(), "randomEmail")).thenReturn(null);; |
Hi @domoberzin, @dishenggg and @jasonqiu212, I have updated the PR according to the changes requested. Let me know if there are anymore issues, thanks! |
Part of #12048
Outline of Solution
Change GetStudentActionTest.java to ensure compatibility with the PostgreSQL database following the database migration.