unit test fixes + error refactor
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 10m52s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 10m52s
This commit is contained in:
@@ -5,6 +5,7 @@ import express, { Request, Response, NextFunction } from 'express';
|
||||
import { errorHandler } from '../middleware/errorHandler';
|
||||
import flyerRouter from './flyer.routes';
|
||||
import { createMockFlyer, createMockFlyerItem } from '../tests/utils/mockFactories';
|
||||
import { NotFoundError } from '../services/db/errors.db';
|
||||
|
||||
// 1. Mock the Service Layer directly.
|
||||
vi.mock('../services/db/index.db', () => ({
|
||||
@@ -78,8 +79,9 @@ describe('Flyer Routes (/api/flyers)', () => {
|
||||
});
|
||||
|
||||
it('should return 404 if the flyer is not found', async () => {
|
||||
vi.mocked(db.flyerRepo.getFlyerById).mockResolvedValue(undefined);
|
||||
vi.mocked(db.flyerRepo.getFlyerById).mockRejectedValue(new NotFoundError('Flyer not found'));
|
||||
const response = await supertest(app).get('/api/flyers/999');
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
expect(response.body.message).toContain('not found');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user