/
easygraphql-tester.js
78 lines (68 loc) · 1.78 KB
/
easygraphql-tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
const fs = require('fs')
const path = require('path')
const { yesno } = require('yesno-http');
const { expect } = require('chai');
const EasygraphqlTester = require('easygraphql-tester')
const { getMe, getUsers } = require('../src/api-client');
const { getMeQuery, getUsersQuery } = require('../src/queries')
const schema = fs.readFileSync(path.join(__dirname, '..', 'src', 'schema.gql'), 'utf8')
const easygraphqlTester = new EasygraphqlTester(schema)
describe('User', () => {
before(() => {
yesno.restore()
})
beforeEach(() => {
yesno.restore()
})
it('should get GetMe', async () => {
yesno.mock([
{
request: {
host: 'localhost',
method: 'POST',
path: '/',
port: 3000,
protocol: 'http',
},
response: {
body: {
data: {
getMe: easygraphqlTester.mock(getMeQuery)
}
},
statusCode: 200,
},
}
]);
await getMe();
const response = yesno.matching(/\//).response()
expect(response.body.data.getMe).to.be.a('object')
expect(response.body.data.getMe.email).to.be.a('string')
expect(response.body.data.getMe.apiKey).not.to.exist
});
it('should get GetUsers', async () => {
yesno.mock([
{
request: {
host: 'localhost',
method: 'POST',
path: '/',
port: 3000,
protocol: 'http',
},
response: {
body: {
data: {
getUsers: easygraphqlTester.mock(getUsersQuery)
}
},
statusCode: 200,
},
}
]);
await getUsers();
const response = yesno.matching(/\//).response()
expect(response.body.data.getUsers).to.be.a('array')
});
});