Skip to content

Commit

Permalink
Update plugins test
Browse files Browse the repository at this point in the history
  • Loading branch information
oderayi committed Dec 9, 2020
1 parent 5b99746 commit 52b19aa
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/unit/shared/plugins.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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()
})

0 comments on commit 52b19aa

Please sign in to comment.