Skip to content

Unit Testing for CheckIns Router #1906

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

Merged
merged 8 commits into from
Jun 17, 2025

Conversation

jng34
Copy link
Member

@jng34 jng34 commented Apr 22, 2025

Fixes #1886

What changes did you make and why did you make them ?

  • Wrote unit tests for checkIns.router.js that isolate the behavior of the router from its dependencies

Screenshot of passed tests

image

@jng34 jng34 requested a review from dannyprikaz April 22, 2025 19:40
Copy link
Member

@dannyprikaz dannyprikaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @jng34

Great work on this. Nice job in particular with mocking the populate method on the response to User.findById in the test for findEvent/:id. Just two little issues:

  1. I think the way you're describing the behavior of /api/checkins/findEvent/:id is incorrect. Based on my reading of the code (checkins.router.js lines 30-24), this endpoint finds all of the checkins whose eventId field match the id passed in the url. Then they populate those documents with with the corresponding users by the userId field. So what this endpoint should really return is "a list of users who have checked in to a specified event." I went hunting through the client to see where this endpoint is used, and it's only ever called from ProjectLeaderDashboard.jsx, which you worked on in issue #1713 . At that time @trillium said that this component is unused. So all in all, the stakes are low for having a super good test on this endpoint, but I think we should correct the description of what it returns and there seem to be some unneeded complexities to the test you wrote. I put more specific comments for those.
  2. In the create test, it would be ideal if we could make sure Checkin.create is actually called with newCheckin and not that it's just called at all. I know that my PR does the same thing. I should figure out a way to fix that. It seems to be a slightly different issue when the request is being passed to a controller, but in this case, configuring body parser middleware seems to be the solution. See my comments on the code.

I'm learning a lot as I go through this, so again, I just want to say great work.

@jng34
Copy link
Member Author

jng34 commented May 27, 2025

Hey @dannyprikaz,

Thank you for thoroughly reviewing the PR and for the detailed feedback.

You are correct in the description for the /api/checkins/findEvent/:id test and for properly testing to see if the info passed in the body for the CheckIn.create method.

All changes have been made.

As always, I appreciate the guidance.

@jng34 jng34 closed this May 27, 2025
@jng34 jng34 reopened this May 27, 2025
Copy link
Member Author

@jng34 jng34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see updated changes.

@jng34 jng34 requested a review from dannyprikaz May 27, 2025 15:36
@JackHaeg
Copy link
Member

@dannyprikaz Can you please review the updates from @jng34 on this PR and potentially approve when you have a moment this week?

Copy link
Member

@dannyprikaz dannyprikaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! thanks

@dannyprikaz dannyprikaz merged commit ddcf194 into hackforla:development Jun 17, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create New Unit Tests for ./backend/routers/checkIns.router.js
3 participants