forked from codeceptjs/CodeceptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphQL_test.js
99 lines (90 loc) · 2.15 KB
/
GraphQL_test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require('path');
const fs = require('fs');
const TestHelper = require('../support/TestHelper');
const GraphQL = require('../../lib/helper/GraphQL');
const graphql_url = TestHelper.graphQLServerUrl();
let I;
const dbFile = path.join(__dirname, '/../data/graphql/db.json');
const data = {
users: [
{
id: 0,
age: 31,
name: 'john doe',
email: '[email protected]',
},
],
};
describe('GraphQL', () => {
before((done) => {
try {
fs.writeFileSync(dbFile, JSON.stringify(data));
} catch (err) {
console.error(err);
}
setTimeout(done, 1500);
});
beforeEach((done) => {
I = new GraphQL({
endpoint: graphql_url,
defaultHeaders: {
'X-Test': 'test',
},
});
done();
});
describe('basic queries', () => {
it('should send a query: read', async () => {
const resp = await I.sendQuery('{ user(id: 0) { id name email }}');
const { user } = resp.data.data;
user.should.eql({
id: '0',
name: 'john doe',
email: '[email protected]',
});
});
});
describe('basic mutations', () => {
it('should send a mutation: create', async () => {
const mutation = `
mutation CreateUser($input: UserInput!) {
createUser(input: $input) {
id
name
email
age
}
}
`;
const variables = {
input: {
id: 111,
name: 'Sourab',
email: '[email protected]',
age: 23,
},
};
const resp = await I.sendMutation(mutation, variables);
const { createUser } = resp.data.data;
createUser.should.eql({
id: '111',
name: 'Sourab',
email: '[email protected]',
age: 23,
});
});
it('should send a mutation: delete', async () => {
const mutation = `
mutation deleteUser($id: ID) {
deleteUser(id: $id)
}
`;
const variables = {
id: 111,
};
const resp = await I.sendMutation(mutation, variables);
const { deleteUser } = resp.data.data;
deleteUser.should.eql('111');
});
});
});