fix(backend): saved-views DELETE 204 response + add route test
- DELETE /saved-views/:id now uses reply.code(204).send() for explicit empty response (Fastify 5 best practice) - Added routes.test.ts for saved-views module (verifies 2 GET, 1 POST, 1 PATCH, 1 DELETE handler registration) - Backend now at 19 tests across 11 files
This commit is contained in:
parent
d09259c42e
commit
c6aa775cd3
38
backend/src/modules/saved-views/routes.test.ts
Normal file
38
backend/src/modules/saved-views/routes.test.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { savedViewRoutes } from './routes.js';
|
||||
|
||||
const { extractAuthMock } = vi.hoisted(() => ({
|
||||
extractAuthMock: vi.fn(async () => ({ sub: 'user_1' })),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/auth.js', () => ({ extractAuth: extractAuthMock }));
|
||||
vi.mock('../../lib/product-config.js', () => ({ PRODUCT_ID: 'notelett' }));
|
||||
vi.mock('./repository.js', () => ({
|
||||
listSavedViews: vi.fn(async () => ({ items: [], total: 0 })),
|
||||
getSavedView: vi.fn(async () => null),
|
||||
createSavedView: vi.fn(async (doc: unknown) => doc),
|
||||
updateSavedView: vi.fn(async () => null),
|
||||
deleteSavedView: vi.fn(async () => false),
|
||||
}));
|
||||
|
||||
describe('savedViewRoutes', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('registers route handlers', async () => {
|
||||
const app = {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
patch: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
};
|
||||
|
||||
await savedViewRoutes(app as never);
|
||||
|
||||
expect(app.get).toHaveBeenCalledTimes(2);
|
||||
expect(app.post).toHaveBeenCalledTimes(1);
|
||||
expect(app.patch).toHaveBeenCalledTimes(1);
|
||||
expect(app.delete).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@ -104,7 +104,6 @@ export async function savedViewRoutes(app: FastifyInstance) {
|
||||
throw new NotFoundError('Saved view not found');
|
||||
}
|
||||
|
||||
reply.code(204);
|
||||
return;
|
||||
reply.code(204).send();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user