-
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
| import { Pantry } from './pantries.entity'; | ||
| import { User } from '../users/user.entity'; | ||
| import { Role } from '../users/types'; | ||
|
|
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.
Take a look at https://github.com/Code-4-Community/ssf/pull/40/files or other similar testing code changes. Sorry if this wasn't made clear but to be consistent we are using { mock } from 'jest-mock-extended' to construct type safe mocks with easier creation. You will need to refactor this and the service test file to do this but it shouldn't be that much effort.
| questions: '', | ||
| itemsInStock: '', | ||
| needMoreOptions: '', | ||
| } as unknown as Pantry; |
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.
What does as unknown do? Is this necessary
| import { NotFoundException } from '@nestjs/common'; | ||
| import { User } from '../users/user.entity'; | ||
| import { Role } from '../users/types'; | ||
|
|
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 thing, refactor to use 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
|
|
||
| await expect(controller.denyPantry(999)).rejects.toThrow(); | ||
| expect(service.deny).toHaveBeenCalledWith(999); | ||
| }); |
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.
Test for submitPantryApplication?
| await expect(service.findSSFRep(999)).rejects.toThrow(NotFoundException); | ||
| await expect(service.findSSFRep(999)).rejects.toThrow( | ||
| 'Pantry 999 not found', | ||
| ); |
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 test for addPantry
ℹ️ 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