Skip to content

Commit e0e089e

Browse files
committed
test: refactor for new pipes, return res, not found
1 parent dbb4ff0 commit e0e089e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/e2e.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
55
import request from 'supertest';
66
import { createHandler } from './createHandler';
77
import { Body, Delete, Get, Header, HttpCode, Post, Put, Query, Req, Res, Response, SetHeader } from './decorators';
8+
import { ValidationPipe } from './pipes';
89
import { ParseBooleanPipe } from './pipes/parseBoolean.pipe';
910
import { ParseNumberPipe } from './pipes/parseNumber.pipe';
1011

@@ -56,7 +57,7 @@ class TestHandler {
5657
@HttpCode(201)
5758
@Post()
5859
@SetHeader('X-Method', 'create')
59-
public create(@Header('Content-Type') contentType: string, @Body() body: CreateDto) {
60+
public create(@Header('Content-Type') contentType: string, @Body(ValidationPipe) body: CreateDto) {
6061
return { contentType, receivedBody: body, test: this.testField, instanceOf: body instanceof CreateDto };
6162
}
6263

@@ -77,7 +78,7 @@ class TestHandler {
7778
const { 'content-type': contentType } = headers;
7879
const { id } = query;
7980

80-
res.status(200).json({ contentType, id, receivedBody: body, test: this.testField });
81+
return res.status(200).json({ contentType, id, receivedBody: body, test: this.testField });
8182
}
8283
}
8384

@@ -112,7 +113,7 @@ describe('E2E', () => {
112113
})
113114
));
114115

115-
it('read', () =>
116+
it('read without "step"', () =>
116117
request(server)
117118
.get('/?id=my-id&redirect=true')
118119
.set('Content-Type', 'application/json')
@@ -222,4 +223,16 @@ describe('E2E', () => {
222223
}
223224
})
224225
));
226+
227+
it('should throw express style 404 for an undefined http verb', () =>
228+
request(server)
229+
.patch('/')
230+
.set('Content-Type', 'application/json')
231+
.expect(404)
232+
.then(res =>
233+
expect(res.body).toMatchObject({
234+
statusCode: 404,
235+
error: 'Not Found'
236+
})
237+
));
225238
});

0 commit comments

Comments
 (0)