diff --git a/src/routes/user.routes.test.ts b/src/routes/user.routes.test.ts index eaed8731..259221f8 100644 --- a/src/routes/user.routes.test.ts +++ b/src/routes/user.routes.test.ts @@ -186,7 +186,7 @@ describe('User Routes (/api/users)', () => { .send({ category: 'Produce' }); expect(response.status).toBe(400); // Check the 'errors' array for the specific validation message. - expect(response.body.errors[0].message).toContain("expected string, received undefined"); + expect(response.body.errors[0].message).toBe("Field 'itemName' is required."); }); it('should return 400 if category is missing', async () => { @@ -195,7 +195,7 @@ describe('User Routes (/api/users)', () => { .send({ itemName: 'Apples' }); expect(response.status).toBe(400); // Check the 'errors' array for the specific validation message. - expect(response.body.errors[0].message).toContain("expected string, received undefined"); + expect(response.body.errors[0].message).toBe("Field 'category' is required."); }); }); @@ -240,7 +240,7 @@ describe('User Routes (/api/users)', () => { const response = await supertest(app).post('/api/users/shopping-lists').send({}); expect(response.status).toBe(400); // Check the 'errors' array for the specific validation message. - expect(response.body.errors[0].message).toContain("expected string, received undefined"); + expect(response.body.errors[0].message).toBe("Field 'name' is required."); }); it('should return 400 on foreign key constraint error', async () => { diff --git a/src/services/db/flyer.db.test.ts b/src/services/db/flyer.db.test.ts index 1ed9d152..f676a143 100644 --- a/src/services/db/flyer.db.test.ts +++ b/src/services/db/flyer.db.test.ts @@ -249,10 +249,11 @@ describe('Flyer DB Service', () => { mockClient.query .mockResolvedValueOnce({ rows: [{ store_id: 1 }] }) // findOrCreateStore .mockRejectedValueOnce(dbError); // insertFlyer fails - // The withTransaction helper will catch this and roll back - await expect(callback(mockClient as unknown as PoolClient)).rejects.toThrow(dbError); - // re-throw because withTransaction re-throws - throw dbError; + // The withTransaction helper will catch this and roll back. + // Since insertFlyer wraps the DB error, we expect the wrapped error message here. + await expect(callback(mockClient as unknown as PoolClient)).rejects.toThrow('Failed to insert flyer into database.'); + // re-throw because withTransaction re-throws (simulating the wrapped error propagating up) + throw new Error('Failed to insert flyer into database.'); }); // The transactional function re-throws the original error from the failed step.