Skip to content

Commit 09ba6f6

Browse files
test(express-wrapper): invalid requests yield a 400 response
This test asserts that sending a malformed request to the wrapped express server results in a 400 response with a decode error in the body.
1 parent 507fbb9 commit 09ba6f6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/express-wrapper/test/test-server.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,23 @@ test('should infer status code from response type', async (t) => {
178178

179179
t.like(response, { errors: 'Please do not tell me zero! I will now explode' });
180180
});
181+
182+
test('should return a 400 when request fails to decode', async (t) => {
183+
const app = createServer(ApiSpec, (app: express.Application) => {
184+
// Configure app-level middleware
185+
app.use(express.json());
186+
// Configure route-level middleware
187+
return {
188+
'hello.world': {
189+
put: [CreateHelloWorld],
190+
},
191+
};
192+
});
193+
194+
const response = await supertest(app)
195+
.put('/hello')
196+
.set('Content-Type', 'application/json')
197+
.expect(400);
198+
199+
t.true(response.body.error.startsWith('Invalid value undefined supplied to'));
200+
});

0 commit comments

Comments
 (0)