Skip to content

Commit e87a016

Browse files
committed
fix unit test
1 parent 7da7585 commit e87a016

File tree

3 files changed

+93
-17
lines changed

3 files changed

+93
-17
lines changed

__tests__/__snapshots__/index.test.js.snap

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Array [
88
],
99
Array [
1010
"Content-Length",
11-
"252",
11+
"789",
1212
],
1313
]
1414
`;
@@ -17,24 +17,60 @@ exports[`expect res setHeader and end to match snapshot 2`] = `
1717
Object {
1818
"data": Object {
1919
"component": Object {
20-
"allVersions": null,
20+
"allVersions": Array [
21+
"1.0.0",
22+
"1.1.0",
23+
"1.1.1",
24+
"1.2.0",
25+
"1.3.0",
26+
],
2127
"author": null,
22-
"description": null,
23-
"name": null,
24-
"parameters": Array [],
28+
"description": "This component displays picture, title, description and date of the NASA's Astronomy Picture of the Day",
29+
"name": "oc-apod",
30+
"parameters": Array [
31+
Object {
32+
"description": "The NASA Open APIs key",
33+
"example": "DEMO_KEY",
34+
"key": "apiKey",
35+
"mandatory": true,
36+
"type": "string",
37+
},
38+
],
2539
"repository": null,
26-
"version": null,
40+
"version": "1.3.0",
2741
},
28-
"components": Array [],
42+
"components": Array [
43+
Object {
44+
"allVersions": Array [
45+
"4.5.4",
46+
"4.5.5",
47+
"4.5.6",
48+
],
49+
"author": null,
50+
"description": "Awesome OpenComponent",
51+
"name": "oc-a-component",
52+
"parameters": Array [
53+
Object {
54+
"description": "The Id",
55+
"example": "789",
56+
"key": "id",
57+
"mandatory": true,
58+
"type": "string",
59+
},
60+
],
61+
"repository": null,
62+
"version": "4.5.6",
63+
},
64+
],
2965
"registry": Object {
3066
"dependencies": Array [
3167
"graphql",
3268
"lodash",
3369
"moment",
3470
],
35-
"href": null,
36-
"ocVersion": null,
37-
"type": null,
71+
"href": "http://mock:3000/",
72+
"ocVersion": "1.2.3",
73+
"type": "mock-registry",
3874
},
3975
},
4076
}

__tests__/index.test.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fetch = require('node-fetch');
22
const factory = require('../src');
33

44
const options = {
5-
baseUrl: 'https://pink-pineapple.herokuapp.com/',
5+
baseUrl: 'http://mock:3000/',
66
graphiql: true,
77
dependencies: ['graphql', 'lodash', 'moment']
88
};
@@ -17,7 +17,7 @@ const query = `
1717
type
1818
dependencies
1919
}
20-
components {
20+
component(name: "oc-apod") {
2121
name
2222
description
2323
version
@@ -38,7 +38,7 @@ const query = `
3838
description
3939
}
4040
}
41-
component(name: "oc-apod") {
41+
components {
4242
name
4343
description
4444
version
@@ -67,7 +67,50 @@ test('expect type of middleware to be function', () => {
6767
});
6868

6969
test('expect res setHeader and end to match snapshot', async () => {
70-
fetch.mockResponse(JSON.stringify({}));
70+
fetch.mockResponses(
71+
[JSON.stringify({
72+
href: options.baseUrl,
73+
ocVersion: '1.2.3',
74+
type: 'mock-registry'
75+
})],
76+
[JSON.stringify({
77+
name: 'oc-apod',
78+
description: 'This component displays picture, title, description and date of the NASA\'s Astronomy Picture of the Day',
79+
version: '1.3.0',
80+
allVersions: ['1.0.0', '1.1.0', '1.1.1', '1.2.0', '1.3.0'],
81+
oc: {
82+
parameters: {
83+
apiKey: {
84+
type: 'string',
85+
mandatory: true,
86+
example: 'DEMO_KEY',
87+
description: 'The NASA Open APIs key'
88+
}
89+
}
90+
}
91+
})],
92+
[JSON.stringify({
93+
components: [
94+
`${options.baseUrl}oc-a-component`
95+
]
96+
})],
97+
[JSON.stringify({
98+
name: 'oc-a-component',
99+
description: 'Awesome OpenComponent',
100+
version: '4.5.6',
101+
allVersions: ['4.5.4', '4.5.5', '4.5.6'],
102+
oc: {
103+
parameters: {
104+
id: {
105+
type: 'string',
106+
mandatory: true,
107+
example: '789',
108+
description: 'The Id'
109+
}
110+
}
111+
}
112+
})]
113+
);
71114

72115
const req = {
73116
method: 'GET',

src/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ const root = (options) => {
8787
return fetch(options.baseUrl)
8888
.then(response => response.json())
8989
.then((data) => {
90-
if (!data.components) {
91-
return [];
92-
}
9390
return data.components
9491
.map((component) => {
9592
const name = component.replace(options.baseUrl, '');

0 commit comments

Comments
 (0)