Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mingyang143
Copy link
Contributor

Part of #12048

Outline of Solution
Change GetSessionResultsActionTest.java to ensure compatibility with the PostgreSQL database following the database migration.

@mingyang143 mingyang143 force-pushed the branch-migrate-tests-week-4-2 branch from 47b048c to 199f09c Compare February 8, 2025 05:06
FeedbackParticipantType.INSTRUCTORS, FeedbackParticipantType.OWN_TEAM, 0,
new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new FeedbackMcqQuestionDetails());
questionsStub.add(questionStub);
SqlSessionResultsBundle resultsStub = new SqlSessionResultsBundle(questionsStub,
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor

@dishenggg dishenggg left a 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:

  1. Logged in as instructor with PREVIEWAS, can access
  2. Logged in as student with PREVIEWAS, cannot access

Comment on lines +41 to +44
String googleId = "user-googleId";
Course course;

FeedbackSession session;
Copy link
Contributor

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

Comment on lines +220 to +221
when(mockLogic.getSessionResultsForCourse(any(FeedbackSession.class), any(String.class), any(String.class),
any(UUID.class), any(String.class), any(FeedbackResultFetchType.class))).thenReturn(resultsStub);
Copy link
Contributor

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

Comment on lines +77 to +84
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<>()));
Copy link
Contributor

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

Comment on lines +330 to +342
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);
Copy link
Contributor

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

Comment on lines +360 to +372
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);
Copy link
Contributor

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(),
Copy link
Contributor

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(),
Copy link
Contributor

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(),
Copy link
Contributor

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

Comment on lines +242 to +252
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);
}
Copy link
Contributor

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

Comment on lines +130 to +132
assertEquals(resultsStub.getQuestions().size(), output.getQuestions().size());
assertEquals(resultsStub.getQuestions().get(0).getDescription(),
output.getQuestions().get(0).getFeedbackQuestion().getQuestionDescription());
Copy link
Contributor

@dishenggg dishenggg Feb 19, 2025

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?

Copy link
Contributor

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

@dishenggg dishenggg added the s.Ongoing The PR is being worked on by the author(s) label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s.Ongoing The PR is being worked on by the author(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants