|
| 1 | +'use strict' |
| 2 | + |
| 3 | +/* global describe, it, afterEach */ |
| 4 | +const expect = require('chai').expect |
| 5 | +const request = require('supertest') |
| 6 | +const fastGateway = require('../index') |
| 7 | +const config = require('./config') |
| 8 | + |
| 9 | +describe('enableServicesEndpoint option', () => { |
| 10 | + let gateway |
| 11 | + |
| 12 | + afterEach(async () => { |
| 13 | + if (gateway && gateway.close) await gateway.close() |
| 14 | + gateway = null |
| 15 | + }) |
| 16 | + |
| 17 | + it('should enable services endpoint by default', async () => { |
| 18 | + const customConfig = await config() |
| 19 | + gateway = await fastGateway(customConfig).start(8090) |
| 20 | + await request(gateway) |
| 21 | + .get('/services.json') |
| 22 | + .expect(200) |
| 23 | + .then((response) => { |
| 24 | + expect(response.body).to.be.an('array') |
| 25 | + /* eslint-disable-next-line no-unused-expressions */ |
| 26 | + expect(response.body.find((service) => service.prefix === '/users') !== null).to.be.ok |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should enable services endpoint when enableServicesEndpoint=true', async () => { |
| 31 | + const customConfig = await config() |
| 32 | + gateway = await fastGateway(Object.assign({}, customConfig, { enableServicesEndpoint: true })).start(8091) |
| 33 | + await request(gateway) |
| 34 | + .get('/services.json') |
| 35 | + .expect(200) |
| 36 | + .then((response) => { |
| 37 | + expect(response.body).to.be.an('array') |
| 38 | + /* eslint-disable-next-line no-unused-expressions */ |
| 39 | + expect(response.body.find((service) => service.prefix === '/users') !== null).to.be.ok |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + it('should disable services endpoint when enableServicesEndpoint=false', async () => { |
| 44 | + const customConfig = await config() |
| 45 | + gateway = await fastGateway(Object.assign({}, customConfig, { enableServicesEndpoint: false })).start(8092) |
| 46 | + await request(gateway) |
| 47 | + .get('/services.json') |
| 48 | + .expect(404) |
| 49 | + }) |
| 50 | +}) |
0 commit comments