UNPKG

1.35 kBJavaScriptView Raw
1'use strict';
2
3const Fs = require('fs');
4const Path = require('path');
5const { expect } = require('code');
6const { graphql } = require('graphi');
7const Hapi = require('hapi');
8const Lab = require('lab');
9const CloudApiGql = require('../lib/');
10const schema = Fs.readFileSync(Path.join(__dirname, '../lib/schema.graphql'));
11
12const lab = exports.lab = Lab.script();
13const it = lab.it;
14
15
16const register = {
17 plugin: CloudApiGql,
18 options: {
19 keyPath: Path.join(__dirname, 'test.key'),
20 keyId: 'test',
21 apiBaseUrl: 'http://localhost'
22 }
23};
24
25it('can be registered with hapi', async () => {
26 const server = new Hapi.Server();
27 await server.register(register);
28});
29
30it('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