-
Notifications
You must be signed in to change notification settings - Fork 4
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
41 update get post and put endpoints for donateditem with full program and donor details #49
Conversation
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.
Once again, really solid work! Not too many notes for this sprint, just a few comments that may have been repetitive code. But those are simple changes/checks. Keep up the good work!
|
||
}); | ||
|
||
it('handles errors when the provided Program or Donor does not exist', async () => { |
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.
In the long term, will this unit test be able to work going into the future? Especially when we get to a point where we definitely have more than 30 users? I personally would consider making it a certain amount higher than the amount of users/programs we have.
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.
@truffer11 It wouldn't check in the real or actual database; it will use mock prisma client and you can see at this line that it resolves to value null
and it always resolves to null values irrespective of the size of database
mockPrismaClient.program.findUnique.mockResolvedValue(null); | ||
mockPrismaClient.donor.findUnique.mockResolvedValue(null); | ||
|
||
const donorId = 19; |
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.
Similar to what I mentioned above, you may want to consider modifying your testing to work beyond just 20 total donors
@@ -21,6 +21,7 @@ router.get('/', async (req: Request, res: Response) => { | |||
const donors = await prisma.donor.findMany(); | |||
res.json(donors); | |||
} catch (error) { | |||
console.error('Error fetching donor:', error); | |||
res.status(500).json({ message: 'Error fetching donors' }); |
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 am unable to test what both of these do, but do both of these do different things? At a glance, they seem to have the same functionality
app.use(express.json()); | ||
app.use('/donatedItem', donatedItemRoutes); | ||
|
||
describe('DonatedItem API Tests', () => { |
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.
These tests look really good and pretty extensive, good job!
programId: 1, | ||
donorId: 1, | ||
dateDonated: new Date().toISOString() | ||
}; |
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 data is this? can we move this to other relevant mock data files?
mockPrismaClient.donor.findUnique.mockResolvedValue(newDonor); | ||
mockPrismaClient.donatedItem.create.mockResolvedValue({ id: 1, ...newItem }); | ||
mockPrismaClient.donatedItem.update.mockResolvedValue({ id: 1, ...updateData }); | ||
}); |
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.
Nice! Keeping the required mock resolved values for prisma at one place seems more clear
**Fixes #41 **
What was changed?
Why was it changed?
How was it changed?
Now, the process should be updated by using validations:
Program Validation: Validated the received Program name against the Program table and retrieve its Program ID.
Donor Validation: Validated the received Donor email against the Donor table and retrieve its Donor ID.