1 | 'use strict';
|
2 |
|
3 | const Path = require('path');
|
4 | const QueryString = require('querystring');
|
5 | const { expect } = require('code');
|
6 | const Hapi = require('hapi');
|
7 | const Lab = require('lab');
|
8 | const StandIn = require('stand-in');
|
9 | const CloudApiGql = require('../lib/');
|
10 | const CloudApi = require('../lib/cloudapi');
|
11 |
|
12 |
|
13 | const lab = exports.lab = Lab.script();
|
14 | const { describe, it, afterEach } = lab;
|
15 |
|
16 |
|
17 | describe('config', () => {
|
18 | afterEach(() => {
|
19 | StandIn.restoreAll();
|
20 | });
|
21 |
|
22 | const register = {
|
23 | plugin: CloudApiGql,
|
24 | options: {
|
25 | keyPath: Path.join(__dirname, 'test.key'),
|
26 | keyId: 'test',
|
27 | apiBaseUrl: 'http://localhost'
|
28 | }
|
29 | };
|
30 |
|
31 | it('can get all configs', async () => {
|
32 | const config = {
|
33 | default_network: '45607081-4cd2-45c8-baf7-79da760fffaa'
|
34 | };
|
35 |
|
36 | const server = new Hapi.Server();
|
37 | StandIn.replaceOnce(CloudApi.prototype, 'fetch', (stand) => {
|
38 | return config;
|
39 | });
|
40 |
|
41 | const query = QueryString.stringify({ query: 'query { config { name value } }' });
|
42 | await server.register(register);
|
43 | await server.initialize();
|
44 | const res = await server.inject({
|
45 | url: `/graphql?${query}`
|
46 | });
|
47 |
|
48 | expect(res.statusCode).to.equal(200);
|
49 | expect(res.result.data.config).to.exist();
|
50 | expect(res.result.data.config[0].name).to.equal('default_network');
|
51 | expect(res.result.data.config[0].value).to.equal('45607081-4cd2-45c8-baf7-79da760fffaa');
|
52 | });
|
53 | });
|