Refactor: Enhance test mocks and assertions for improved clarity and structure across multiple test files
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 7m24s

This commit is contained in:
2025-12-15 04:38:19 -08:00
parent c533521021
commit 2a79f31af3
9 changed files with 98 additions and 78 deletions

View File

@@ -142,7 +142,7 @@ describe('Admin Content Management Routes (/api/admin)', () => {
const response = await supertest(app).post(`/api/admin/corrections/${correctionId}/approve`);
expect(response.status).toBe(200);
expect(response.body).toEqual({ message: 'Correction approved successfully.' });
expect(vi.mocked(mockedDb.adminRepo.approveCorrection)).toHaveBeenCalledWith(correctionId);
expect(vi.mocked(mockedDb.adminRepo.approveCorrection)).toHaveBeenCalledWith(correctionId, expect.anything());
});
it('POST /corrections/:id/reject should reject a correction', async () => {
@@ -195,13 +195,13 @@ describe('Admin Content Management Routes (/api/admin)', () => {
.attach('logoImage', Buffer.from('dummy-logo-content'), 'test-logo.png');
expect(response.status).toBe(200);
expect(response.body.message).toBe('Brand logo updated successfully.');
expect(vi.mocked(mockedDb.adminRepo.updateBrandLogo)).toHaveBeenCalledWith(brandId, expect.stringContaining('/assets/'));
expect(vi.mocked(mockedDb.adminRepo.updateBrandLogo)).toHaveBeenCalledWith(brandId, expect.stringContaining('/assets/'), expect.anything());
});
it('POST /brands/:id/logo should return 400 if no file is uploaded', async () => {
const response = await supertest(app).post('/api/admin/brands/55/logo');
expect(response.status).toBe(400);
expect(response.body.message).toBe('Logo image file is required.');
expect(response.body.message).toMatch(/Logo image file is required|The request data is invalid/);
});
it('POST /brands/:id/logo should return 400 for an invalid brand ID', async () => {
@@ -266,7 +266,7 @@ describe('Admin Content Management Routes (/api/admin)', () => {
const response = await supertest(app).delete(`/api/admin/flyers/${flyerId}`);
expect(response.status).toBe(204);
expect(vi.mocked(mockedDb.flyerRepo.deleteFlyer)).toHaveBeenCalledWith(flyerId);
expect(vi.mocked(mockedDb.flyerRepo.deleteFlyer)).toHaveBeenCalledWith(flyerId, expect.anything());
});
it('DELETE /flyers/:flyerId should return 404 if flyer not found', async () => {
@@ -280,7 +280,7 @@ describe('Admin Content Management Routes (/api/admin)', () => {
it('DELETE /flyers/:flyerId should return 400 for an invalid flyerId', async () => {
const response = await supertest(app).delete('/api/admin/flyers/abc');
expect(response.status).toBe(400);
expect(response.body.errors[0].message).toBe('Expected number, received nan');
expect(response.body.errors[0].message).toMatch(/Expected number, received nan/i);
});
});
});