UNPKG

1.25 kBJavaScriptView Raw
1'use strict';
2
3const Path = require('path');
4const { expect } = require('code');
5const Hapi = require('hapi');
6const Lab = require('lab');
7const StandIn = require('stand-in');
8const CloudApiGql = require('../lib/');
9const CloudApi = require('../lib/cloudapi');
10
11
12const lab = exports.lab = Lab.script();
13const { describe, it, afterEach } = lab;
14
15
16describe('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});