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