Skip to content

Commit

Permalink
Refactor integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehbraheem committed May 20, 2020
1 parent 7189083 commit bcab67f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import application, {
} from '../../test/utils/requestHelper';

import '../../test/factories/{{{scaffold_factory}}}';
import { verify{{{scaffold_entity_capitalise}}}, verifyResponse } from '../../test/helpers/{{{scaffold_entities}}}';

import { ROUTE_NAME } from './routes';

const { response: { CREATED, JSON_TYPE , BAD_REQUEST} } = http;
Expand Down
14 changes: 9 additions & 5 deletions scaffold/service/src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ export const arraySchema = (template: object): object => ({
},
});

export const responseDocumentSchema = (template: object): object => ({
export const responseDocumentSchema = (template): object => ({
type: 'object',
properties: {
data: {
type: 'array',
items: {
...template,
id: {
type: 'string',
type: 'object',
required: template.required,
properties: {
...template.properties,
id: {
type: 'string',
},
...metaResponseSchema,
},
...metaResponseSchema,
},
},
...errorResponseSchema,
Expand Down
13 changes: 13 additions & 0 deletions scaffold/test/helpers/{{{scaffold_entities}}}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const attrs = ['name' 'meta.active'];

export const verify{{{scaffold_entity_capitalise}}} = (resource): void => {
attrs.forEach(attr => {
expect(resource).toHaveProperty(attr);
});
};

export const verifyResponse = ({ resource, payload }): void => {
attrs.forEach(attr => {
expect(resource[attr]).toEqual(payload[attr]);
});
};

0 comments on commit bcab67f

Please sign in to comment.