-
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 GetSessionResultsActionTest #13216
base: master
Are you sure you want to change the base?
[#12048] Migrate tests for GetSessionResultsActionTest #13216
Conversation
47b048c
to
199f09c
Compare
FeedbackParticipantType.INSTRUCTORS, FeedbackParticipantType.OWN_TEAM, 0, | ||
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new FeedbackMcqQuestionDetails()); | ||
questionsStub.add(questionStub); | ||
SqlSessionResultsBundle resultsStub = new SqlSessionResultsBundle(questionsStub, |
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.
Great work, but perhaps you could abstract the instantiation of resultsStub to a different function as you are using it more than once?
|
||
@Test | ||
void testCheckSpecificAccessControl_studentResultIntentUnpublishedSession_cannotAccess() { | ||
loginAsStudent(googleId); |
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.
Great coverage for test cases but perhaps you could abstract out the first few lines that are similar throughout each method into before each?
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.
Thanks for the PR!, some small changes and most of them are just changing to getTypicalXXX
which should help to simply the code since we need a lot of different objects for this test and
I think we should add 2 more access control cases:
- Logged in as instructor with PREVIEWAS, can access
- Logged in as student with PREVIEWAS, cannot access
String googleId = "user-googleId"; | ||
Course course; | ||
|
||
FeedbackSession session; |
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.
Lets private these for consistency
when(mockLogic.getSessionResultsForCourse(any(FeedbackSession.class), any(String.class), any(String.class), | ||
any(UUID.class), any(String.class), any(FeedbackResultFetchType.class))).thenReturn(resultsStub); |
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 think it would be better if we try to narrow down the allowed args instead of using any
to ensure that the params are parsed and passed to the method properly or, we can add a verify statement as well
Lets try and do this everywhere possible eg in prepareMocksBasicParams
too
List<FeedbackQuestion> questionsStub = new ArrayList<>(); | ||
questionsStub.add(new FeedbackMcqQuestion(session, 1, "description", | ||
FeedbackParticipantType.INSTRUCTORS, FeedbackParticipantType.OWN_TEAM, 0, | ||
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new FeedbackMcqQuestionDetails())); | ||
SqlSessionResultsBundle resultsStub = new SqlSessionResultsBundle(questionsStub, | ||
new HashSet<>(), new HashSet<>(), new ArrayList<>(), | ||
new ArrayList<>(), new HashMap<>(), new HashMap<>(), | ||
new HashMap<>(), new HashMap<>(), new SqlCourseRoster(new ArrayList<>(), new ArrayList<>())); |
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.
Lets use the getTypicalXXX
methods for this so our mock data is more realistic
FeedbackSession unpublishedSession = new FeedbackSession( | ||
"session-name", | ||
course, | ||
"[email protected]", | ||
null, | ||
Instant.parse("2020-01-01T00:00:00.000Z"), | ||
Instant.parse("2020-10-01T00:00:00.000Z"), | ||
Instant.parse("2020-01-01T00:00:00.000Z"), | ||
Instant.MAX, | ||
null, | ||
false, | ||
false, | ||
false); |
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.
Lets use the getTypicalFeedbackSessionForCourse
method for this and change the publish time with the setter after
FeedbackSession unpublishedSession = new FeedbackSession( | ||
"session-name", | ||
course, | ||
"[email protected]", | ||
null, | ||
Instant.parse("2020-01-01T00:00:00.000Z"), | ||
Instant.parse("2020-10-01T00:00:00.000Z"), | ||
Instant.parse("2020-01-01T00:00:00.000Z"), | ||
Instant.MAX, | ||
null, | ||
false, | ||
false, | ||
false); |
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.
Lets use the getTypicalFeedbackSessionForCourse
method here too
Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getName(), | ||
Const.ParamsNames.COURSE_ID, session.getCourseId(), | ||
Const.ParamsNames.INTENT, Intent.STUDENT_RESULT.name(), | ||
Const.ParamsNames.PREVIEWAS, student.getEmail(), |
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.
Lets remove the PREVIEWAS
param from here and test it separately
Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getName(), | ||
Const.ParamsNames.COURSE_ID, session.getCourseId(), | ||
Const.ParamsNames.INTENT, FULL_DETAIL.name(), | ||
Const.ParamsNames.PREVIEWAS, instructor.getEmail(), |
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.
Lets remove the PREVIEWAS
param from here and test it separately
Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getName(), | ||
Const.ParamsNames.COURSE_ID, session.getCourseId(), | ||
Const.ParamsNames.INTENT, Intent.INSTRUCTOR_RESULT.name(), | ||
Const.ParamsNames.PREVIEWAS, instructor.getEmail(), |
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.
Lets remove the PREVIEWAS
param from here and test it separately
void testCheckSpecificAccessControl_nullInstructor_cannotAccess() { | ||
loginAsInstructor(googleId); | ||
String[] params = { | ||
Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getName(), | ||
Const.ParamsNames.COURSE_ID, session.getCourseId(), | ||
Const.ParamsNames.INTENT, Intent.INSTRUCTOR_RESULT.name(), | ||
}; | ||
when(mockLogic.getFeedbackSession(session.getName(), session.getCourseId())).thenReturn(session); | ||
when(mockLogic.getInstructorByGoogleId(session.getCourseId(), googleId)).thenReturn(null); | ||
verifyCannotAccess(params); | ||
} |
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 I am missing something but this test case feels a bit off when we are logged in as an Instructor and yet getInstructorByGoogleId
returns null, maybe we can replace this with Instructor from another course? or/and Instructor without permissions
assertEquals(resultsStub.getQuestions().size(), output.getQuestions().size()); | ||
assertEquals(resultsStub.getQuestions().get(0).getDescription(), | ||
output.getQuestions().get(0).getFeedbackQuestion().getQuestionDescription()); |
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.
Hmmm, cant quite figure out if this 2 asserts are enough maybe you or anyone else can share some insights on this?
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.
lets follow the old test case and go and do something similar to checking if 2 objects are equal better to be safe then sorry
Part of #12048
Outline of Solution
Change GetSessionResultsActionTest.java to ensure compatibility with the PostgreSQL database following the database migration.