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('random', () => {
|
17 | afterEach(() => {
|
18 | StandIn.restoreAll();
|
19 | });
|
20 |
|
21 | it('can query for a random machine name', async () => {
|
22 | const server = new Hapi.Server();
|
23 | StandIn.replaceOnce(CloudApi.prototype, 'fetch', (stand) => {
|
24 | return [];
|
25 | });
|
26 |
|
27 | await server.register({ plugin: CloudApiGql, options: { keyPath: Path.join(__dirname, 'test.key') } });
|
28 | await server.initialize();
|
29 | const res = await server.inject({
|
30 | url: '/graphql',
|
31 | method: 'post',
|
32 | payload: { query: 'query { rndName }' }
|
33 | });
|
34 | expect(res.statusCode).to.equal(200);
|
35 | expect(res.result.data.rndName).to.exist();
|
36 | });
|
37 |
|
38 | it('can query for a random image', async () => {
|
39 | const server = new Hapi.Server();
|
40 | StandIn.replaceOnce(CloudApi.prototype, 'fetch', (stand) => {
|
41 | return [];
|
42 | });
|
43 |
|
44 | await server.register({ plugin: CloudApiGql, options: { keyPath: Path.join(__dirname, 'test.key') } });
|
45 | await server.initialize();
|
46 | const res = await server.inject({
|
47 | url: '/graphql',
|
48 | method: 'post',
|
49 | payload: { query: 'query { rndImageName }' }
|
50 | });
|
51 | expect(res.statusCode).to.equal(200);
|
52 | expect(res.result.data.rndImageName).to.exist();
|
53 | });
|
54 | });
|