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('webconsole-cloudapi-client');
|
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 | routes: {
|
30 | prefix: '/test'
|
31 | }
|
32 | };
|
33 |
|
34 | it('can get all configs', async () => {
|
35 | const config = {
|
36 | default_network: '45607081-4cd2-45c8-baf7-79da760fffaa'
|
37 | };
|
38 |
|
39 | const server = new Hapi.Server();
|
40 | StandIn.replaceOnce(CloudApi.prototype, 'fetch', (stand) => {
|
41 | return config;
|
42 | });
|
43 |
|
44 | const query = QueryString.stringify({ query: 'query { config { name value } }' });
|
45 | await server.register(register);
|
46 | await server.initialize();
|
47 | const res = await server.inject({
|
48 | url: `/test/graphql?${query}`
|
49 | });
|
50 |
|
51 | expect(res.statusCode).to.equal(200);
|
52 | expect(res.result.data.config).to.exist();
|
53 | expect(res.result.data.config[0].name).to.equal('default_network');
|
54 | expect(res.result.data.config[0].value).to.equal('45607081-4cd2-45c8-baf7-79da760fffaa');
|
55 | });
|
56 | });
|