1 | 'use strict';
|
2 |
|
3 | const Fs = require('fs');
|
4 | const Path = require('path');
|
5 | const { expect } = require('code');
|
6 | const { graphql } = require('graphi');
|
7 | const Hapi = require('hapi');
|
8 | const Lab = require('lab');
|
9 | const CloudApiGql = require('../lib/');
|
10 | const schema = Fs.readFileSync(Path.join(__dirname, '../lib/schema.graphql'));
|
11 |
|
12 | const lab = exports.lab = Lab.script();
|
13 | const it = lab.it;
|
14 |
|
15 |
|
16 | const register = {
|
17 | plugin: CloudApiGql,
|
18 | options: {
|
19 | keyPath: Path.join(__dirname, 'test.key'),
|
20 | keyId: 'test',
|
21 | apiBaseUrl: 'http://localhost'
|
22 | }
|
23 | };
|
24 |
|
25 | it('can be registered with hapi', async () => {
|
26 | const server = new Hapi.Server();
|
27 | await server.register(register);
|
28 | });
|
29 |
|
30 | it('has a resolver for every query and mutation in the schema', async () => {
|
31 | const fields = [];
|
32 | const parsed = graphql.parse(schema.toString());
|
33 | for (const def of parsed.definitions) {
|
34 | if (def.kind !== 'ObjectTypeDefinition' || (def.name.value !== 'Query' && def.name.value !== 'Mutation')) {
|
35 | continue;
|
36 | }
|
37 |
|
38 | for (const field of def.fields) {
|
39 | fields.push(field.name.value);
|
40 | }
|
41 | }
|
42 |
|
43 | const server = new Hapi.Server();
|
44 | await server.register(register);
|
45 | await server.initialize();
|
46 | const paths = server.table().map((route) => {
|
47 | return route.path.substr(1);
|
48 | });
|
49 |
|
50 | for (const field of fields) {
|
51 | expect(paths).to.contain(field);
|
52 | }
|
53 | });
|
54 |
|
55 |
|