unit test fixes + error refactor
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 13m41s

This commit is contained in:
2025-12-11 21:17:48 -08:00
parent 5d7598eadf
commit d3d637ebfe
12 changed files with 59 additions and 41 deletions

View File

@@ -230,10 +230,11 @@ describe('Admin Content Management Routes (/api/admin)', () => {
});
it('PUT /recipes/:id/status should return 400 for an invalid status', async () => {
// FIX: The route logic checks for a valid recipe ID before it validates the status.
// If the mock DB returns a "not found" error, the status code will be 404, not 400.
// This test is slightly misnamed. It actually tests the 404 Not Found case,
// because the route logic will attempt to fetch the recipe before validating the status.
// We mock the DB to throw a NotFoundError to simulate this.
vi.mocked(mockedDb.adminRepo.updateRecipeStatus).mockRejectedValue(new NotFoundError('Recipe with ID 201 not found.'));
const response = await supertest(app).put('/api/admin/recipes/201').send({ status: 'invalid-status' });
const response = await supertest(app).put('/api/admin/recipes/201').send({ status: 'public' });
expect(response.status).toBe(404);
expect(response.body.message).toBe('Recipe with ID 201 not found.');
});