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

This commit is contained in:
2025-12-11 18:23:59 -08:00
parent 5f1901b93d
commit 0bc65574c2
22 changed files with 112 additions and 676 deletions

View File

@@ -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');
});