-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresolvers.test.js
48 lines (40 loc) · 1.3 KB
/
resolvers.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
import resolvers from '../src/resolvers';
describe('XKCD resolvers', () => {
it('returns valid resolvers', () => {
expect(Object.keys(resolvers)).toEqual(['Query', 'XKCD_Comic']);
});
describe('queryResolvers', () => {
const mockContext = {
model: {
// Mock a response so we can actually test it.
getLatestComic: () => Promise.resolve('latest'),
// For testing, we mock the model to simply return the ID.
getComicById: id => Promise.resolve(id),
},
};
describe('getLatestComic()', () => {
it('loads the latest comic', () => {
expect.assertions(1);
return expect(
resolvers.Query.getLatestComic(null, null, mockContext),
).resolves.toEqual('latest');
});
});
describe('getComicById()', () => {
it('loads a comic by its ID', () => {
expect.assertions(1);
return expect(
resolvers.Query.getComicById(null, { id: 1234 }, mockContext),
).resolves.toEqual(1234);
});
});
});
describe('dataResolvers', () => {
describe('XKCD_Comic', () => {
const resolver = resolvers.XKCD_Comic;
it('creates a link if none is provided', () => {
expect(resolver.link({ num: 1234 })).toEqual('https://xkcd.com/1234/');
});
});
});
});