route testing refactoring using zod - ADR-003
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m3s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m3s
This commit is contained in:
@@ -153,12 +153,6 @@ describe('Admin Content Management Routes (/api/admin)', () => {
|
||||
expect(vi.mocked(mockedDb.adminRepo.approveCorrection)).toHaveBeenCalledWith(correctionId);
|
||||
});
|
||||
|
||||
it('POST /corrections/:id/approve should return 400 for an invalid ID', async () => {
|
||||
const response = await supertest(app).post('/api/admin/corrections/abc/approve');
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.body.message).toBe('Invalid correction ID provided.');
|
||||
});
|
||||
|
||||
it('POST /corrections/:id/reject should reject a correction', async () => {
|
||||
const correctionId = 789;
|
||||
vi.mocked(mockedDb.adminRepo.rejectCorrection).mockResolvedValue(undefined);
|
||||
@@ -167,12 +161,6 @@ describe('Admin Content Management Routes (/api/admin)', () => {
|
||||
expect(response.body).toEqual({ message: 'Correction rejected successfully.' });
|
||||
});
|
||||
|
||||
it('PUT /corrections/:id should return 400 if suggested_value is missing', async () => {
|
||||
const response = await supertest(app).put('/api/admin/corrections/101').send({});
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.body.message).toBe('A new suggested_value is required.');
|
||||
});
|
||||
|
||||
it('PUT /corrections/:id should update a correction', async () => {
|
||||
const correctionId = 101;
|
||||
const requestBody = { suggested_value: 'A new corrected value' };
|
||||
@@ -229,16 +217,6 @@ describe('Admin Content Management Routes (/api/admin)', () => {
|
||||
expect(response.body).toEqual(mockUpdatedRecipe);
|
||||
});
|
||||
|
||||
it('PUT /recipes/:id/status should return 400 for an invalid status', async () => {
|
||||
// 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: 'public' });
|
||||
expect(response.status).toBe(404);
|
||||
expect(response.body.message).toBe('Recipe with ID 201 not found.');
|
||||
});
|
||||
|
||||
it('PUT /comments/:id/status should update a comment status', async () => {
|
||||
const commentId = 301;
|
||||
const requestBody = { status: 'hidden' as const };
|
||||
@@ -249,15 +227,6 @@ describe('Admin Content Management Routes (/api/admin)', () => {
|
||||
expect(response.body).toEqual(mockUpdatedComment);
|
||||
});
|
||||
|
||||
it('PUT /comments/:id/status should return 400 for an invalid status', async () => {
|
||||
// For this test, we do NOT mock the database call. The route handler should
|
||||
// validate the 'status' from the request body and return a 400 Bad Request
|
||||
// *before* any database interaction is attempted. If the mock were called,
|
||||
// it would indicate a logic error in the route.
|
||||
const response = await supertest(app).put('/api/admin/comments/301').send({ status: 'invalid-status' });
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.body.message).toContain('A valid status');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unmatched Items Route', () => {
|
||||
@@ -289,11 +258,6 @@ describe('Admin Content Management Routes (/api/admin)', () => {
|
||||
expect(vi.mocked(mockedDb.flyerRepo.deleteFlyer)).toHaveBeenCalledWith(flyerId);
|
||||
});
|
||||
|
||||
it('DELETE /flyers/:flyerId should return 400 for an invalid ID', async () => {
|
||||
const response = await supertest(app).delete('/api/admin/flyers/abc');
|
||||
expect(response.status).toBe(400);
|
||||
});
|
||||
|
||||
it('DELETE /flyers/:flyerId should return 404 if flyer not found', async () => {
|
||||
const flyerId = 999;
|
||||
vi.mocked(mockedDb.flyerRepo.deleteFlyer).mockRejectedValue(new NotFoundError('Flyer with ID 999 not found.'));
|
||||
|
||||
Reference in New Issue
Block a user