refactor(middleware-io): integration with
MODIFY
packages/middleware-io/package.json
packages/middleware-io/package.json
"io-ts": "~2.2.1"
},
"devDependencies": {
- "@marblejs/core": "^3.2.0"
+ "@marblejs/core": "^3.2.0",
+ "@marblejs/testing": "^3.2.0"
},
"publishConfig": {
"access": "public"

MODIFY
packages/middleware-io/test/io-http.integration.spec.ts
packages/middleware-io/test/io-http.integration.spec.ts
-import * as request from 'supertest';
-import { createServer } from '@marblejs/core';
-import { createHttpServerTestBed } from '@marblejs/core/dist/+internal/testing';
+import { createHttpTestBed, createTestBedSetup } from '@marblejs/testing';
+import { pipe } from 'fp-ts/lib/pipeable';
import { listener } from './io-http.integration';
+const testBed = createHttpTestBed({ listener });
+const useTestBedSetup = createTestBedSetup({ testBed });
+
describe('@marblejs/middleware-io - HTTP integration', () => {
- const server = createServer({ listener });
- const httpTestBed = createHttpServerTestBed(server);
+ const testBedSetup = useTestBedSetup();
+
+ afterEach(async () => {
+ await testBedSetup.cleanup();
+ });
test('POST / returns 200 with user object', async () => {
+ const { request } = await testBedSetup.useTestBed();
const user = { id: 'id', name: 'name', age: 100 };
- return request(httpTestBed.getInstance())
- .post('/')
- .send({ user })
- .expect(200, user);
+
+ const response = await pipe(
+ request('POST'),
+ request.withPath('/'),
+ request.withBody({ user }),
+ request.send,
+ );
+
+ expect(response.statusCode).toEqual(200);
+ expect(response.body).toEqual(user);
});
test('POST / returns 400 with validation error object', async () => {
+ const { request } = await testBedSetup.useTestBed();
const user = { id: 'id', name: 'name', age: '100' };
- return request(httpTestBed.getInstance())
- .post('/')
- .send({ user })
- .expect(400)
- .then(({ body: { error } }) => {
- expect(error).toBeDefined();
- expect(error.status).toEqual(400);
- expect(error.message).toEqual('Validation error');
- expect(error.context).toEqual('body');
- expect(error.data).toEqual([{
+
+ const response = await pipe(
+ request('POST'),
+ request.withPath('/'),
+ request.withBody({ user }),
+ request.send,
+ );
+
+ expect(response.statusCode).toEqual(400);
+ expect(response.body).toEqual({
+ error: {
+ status: 400,
+ message: 'Validation error',
+ context: 'body',
+ data: [{
path: 'user.age',
expected: 'number',
- got: '"100"'
- }]);
+ got: '"100"',
+ }]
+ }
});
});
});

refactor(middleware-io): integration with @marblejs/testing