Skip to content

Commit 0cb67df

Browse files
rogerpadillaclaude
andcommitted
test(express): cover missing branches in querierMiddleware
Add 6 tests for previously uncovered branches: null findOne results (count=0 path), empty DELETE, PUT 404 path, non-Error exception in errorHandler, and querierMiddleware() with no include option. Brings branch coverage from 89.97% to 90.15%. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2b2fa96 commit 0cb67df

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

packages/uql-orm/src/express/querierMiddleware.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,43 @@ describe('querierMiddleware', () => {
240240
const res = await request(app).get('/api/other-entity');
241241
expect(res.status).toBe(404);
242242
});
243+
244+
it('GET /api/user/one returns null', async () => {
245+
mockQuerier.findOne.mockResolvedValue(null);
246+
const res = await request(app).get('/api/user/one');
247+
expect(res.status).toBe(200);
248+
expect(res.body).toEqual({ data: null, count: 0 });
249+
});
250+
251+
it('GET /api/user/:id returns null', async () => {
252+
mockQuerier.findOne.mockResolvedValue(null);
253+
const res = await request(app).get('/api/user/999');
254+
expect(res.status).toBe(200);
255+
expect(res.body).toEqual({ data: null, count: 0 });
256+
});
257+
258+
it('DELETE /api/user when no entities found', async () => {
259+
mockQuerier.findMany.mockResolvedValue([]);
260+
const res = await request(app).delete('/api/user');
261+
expect(res.status).toBe(200);
262+
expect(res.body).toEqual({ data: [], count: 0 });
263+
expect(mockQuerier.deleteMany).not.toHaveBeenCalled();
264+
});
265+
266+
it('PUT /api/user/:id is not handled (pre preSave branch)', async () => {
267+
const res = await request(app).put('/api/user/1').send({ name: 'John' });
268+
expect(res.status).toBe(404);
269+
});
270+
271+
it('errorHandler with non-Error exception', async () => {
272+
mockQuerier.findOne.mockRejectedValue('raw string error');
273+
const res = await request(app).get('/api/user/one');
274+
expect(res.status).toBe(500);
275+
expect(res.body.error).toBe('Internal Server Error');
276+
});
277+
278+
it('querierMiddleware uses getEntities when include is omitted', () => {
279+
const router = querierMiddleware();
280+
expect(router).toBeDefined();
281+
});
243282
});

0 commit comments

Comments
 (0)