-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathgraphql.test.js
72 lines (62 loc) · 1.96 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
'use strict';
const assert = require('assert');
const mm = require('egg-mock');
describe('test/plugin.test.js', () => {
let app;
before(() => {
app = mm.app({
baseDir: 'apps/graphql-app',
});
return app.ready();
});
after(mm.restore);
it('should return empty array', async () => {
const ctx = app.mockContext();
const query = JSON.stringify({
query: '{ projects }',
});
const resp = await ctx.graphql.query(query);
assert.deepEqual(resp.data.projects, []);
});
it('should return user with no projects', async () => {
const ctx = app.mockContext();
const query = JSON.stringify({
query: '{ user(id: 3) { projects } }',
});
const resp = await ctx.graphql.query(query);
assert.deepEqual(resp.data, { user: { projects: [] } });
});
it('should return error', async () => {
const ctx = app.mockContext();
const resp = await ctx.graphql.query('');
assert.deepEqual(resp.data, {});
assert.equal(resp.errors[0].message, 'Unexpected end of JSON input');
});
it("should return name's upperCase with @upper directive", async () => {
const ctx = app.mockContext();
const resp = await ctx.graphql.query(
JSON.stringify({
query: '{ user(id: 1) { upperName } }',
})
);
assert.deepEqual(resp.data, { user: { upperName: 'NAME1' } });
});
it('should return createAt with @date directive', async () => {
const ctx = app.mockContext();
const resp = await ctx.service.graphql.query(
JSON.stringify({
query: '{ user(id: 1) { createAt } }',
})
);
assert.deepEqual(resp.data, { user: { createAt: '2018-6-7' } });
});
it("should return name's lowerCase with schemaDirectives", async () => {
const ctx = app.mockContext();
const resp = await ctx.graphql.query(
JSON.stringify({
query: '{ user(id: 1) { lowerName } }',
})
);
assert.deepEqual(resp.data, { user: { lowerName: 'name1' } });
});
});