UNPKG

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