-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-52] jest tests for pantries controller/service files #55
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
base: main
Are you sure you want to change the base?
Conversation
Juwang110
left a comment
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.
Overall structure looks good! requires some refactoring though based on comments and using jest-mock-extended
| }); | ||
|
|
||
| // Get pantries with pending status | ||
| describe('getPendingPantries', () => { |
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.
Add a pantry that is not pending to assert this only gets pending ones
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.
On second glance I don't think this is possible/easy since we are relying on repository filtering logic with "where", so this test is fine
…k/SSF-52-backend-pantries-tests
…/Code-4-Community/ssf into sk/SSF-52-backend-pantries-tests
Juwang110
left a comment
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.
besides one comment lgtm
sam-schu
left a comment
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.
Looking good!
| import { mock } from 'jest-mock-extended'; | ||
| import { PantryApplicationDto } from './dtos/pantry-application.dto'; | ||
|
|
||
| jest.mock('../utils/validation.utils', () => ({ |
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 validateId is a basic utils function that doesn't rely on the database, we shouldn't have to mock it in tests
Leaving the below here as a note for the future - don't worry about doing this now since service tests will have to be updated later to use the mock database
Also, for the service functions that call validateId, can we check that calling them with an ID that causes (the real implementation of) validateId to throw an error also causes the service function to error?
|
|
||
| await service.addPantry(mockPantryApplication); | ||
|
|
||
| expect(mockRepository.save).toHaveBeenCalledWith( |
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.
Can we add the rest of the application fields here?
ℹ️ Issue SSF-52
Closes https://vidushimisra.atlassian.net/browse/SSF-52
📝 Description
Added jest tests to the backend for /pantries, specifically for pantries.controller.ts and pantries.service.ts.
✔️ Verification
Ensured all tests are passing