imp(@integration): added validator for postUser$ effect
MODIFY
packages/@integration/src/effects/user.effects.ts
packages/@integration/src/effects/user.effects.ts
@@ -11,6 +11,14 @@ const getUserValidator$ = validator$({
},
}, { allowUnknown: true });
+const postUserValidator$ = validator$({
+ body: {
+ user: Joi.object({
+ id: Joi.string().required(),
+ })
+ },
+});
+
const getUserList$ = EffectFactory
.matchPath('/')
.matchType('GET')
@@ -38,9 +46,10 @@ const postUser$ = EffectFactory
.matchPath('/')
.matchType('POST')
.use(req$ => req$.pipe(
+ use(postUserValidator$),
map(req => req.body),
mergeMap(Dao.postUser),
- map(response => ({ body: response })),
+ map(body => ({ body })),
));
export const user$ = combineRoutes('/user', {

MODIFY
packages/@integration/src/fakes/dao.fake.ts
packages/@integration/src/fakes/dao.fake.ts
@@ -13,7 +13,7 @@ export namespace Dao {
? of({ id, firstName: 'Bob', lastName: 'Collins' })
: throwError(new Error());
- export const postUser = (data: any) => of({
+ export const postUser = <T>(data: T) => of({
data,
});

MODIFY
packages/@integration/test/integration.spec.ts
packages/@integration/test/integration.spec.ts
@@ -73,8 +73,8 @@ describe('API integration', () => {
request(app)
.post('/api/v1/user')
.set('Authorization', 'Bearer FAKE')
- .send({ test: 'test' })
- .expect(200, { data: {test: 'test' } }));
+ .send({ user: { id: 'test_id' } })
+ .expect(200, { data: { user: { id: 'test_id' } } }));
test(`returns static file as ${ContentType.TEXT_HTML}: /api/v1/static/index.html`, async () =>
request(app)

imp(@integration): added validator for postUser$ effect