From 52b19aacdb35b54e9d1920bfc1c84f3640d3fe71 Mon Sep 17 00:00:00 2001 From: Steven Oderayi Date: Wed, 9 Dec 2020 17:06:59 +0100 Subject: [PATCH] Update plugins test --- test/unit/shared/plugins.test.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/unit/shared/plugins.test.js b/test/unit/shared/plugins.test.js index b10e562ee..07eb436cd 100644 --- a/test/unit/shared/plugins.test.js +++ b/test/unit/shared/plugins.test.js @@ -1,11 +1,14 @@ 'use strict' const Test = require('tape') -const Plugins = require('../../../src/shared/plugins') const Inert = require('@hapi/inert') const Blipp = require('blipp') const Vision = require('@hapi/vision') const ErrorHandling = require('@mojaloop/central-services-error-handling') +const Config = require('../../../src/lib/config') +const Proxyquire = require('proxyquire') +const APIDocumentation = require('@mojaloop/central-services-shared').Util.Hapi.APIDocumentation +let Plugins = require('../../../src/shared/plugins') class Server { constructor () { @@ -33,5 +36,32 @@ Test('registerPlugins should', pluginsTest => { modules.forEach(x => test.ok(server.contains(x))) test.end() }) + + pluginsTest.test('not register API documentation plugin if disabled in config', async function (test) { + const ConfigStub = { ...Config } + ConfigStub.API_DOCUMENTATION_ENDPOINTS = false + + Plugins = Proxyquire('../../../src/shared/plugins', { + '../lib/config': ConfigStub + }) + const server = await new Server() + await Plugins.registerPlugins(server) + test.ok(!server.contains(APIDocumentation)) + test.end() + }) + + pluginsTest.test('register API documentation plugin if enabled in config', async function (test) { + const ConfigStub = { ...Config } + ConfigStub.API_DOCUMENTATION_ENDPOINTS = true + + Plugins = Proxyquire('../../../src/shared/plugins', { + '../lib/config': ConfigStub + }) + const server = await new Server() + await Plugins.registerPlugins(server) + test.ok(server.registrations[0].plugin.plugin.name.includes('apiDocumentation')) + test.end() + }) + pluginsTest.end() })