bridge-node-server/node_server/dev_api/specs/catch-all-path.e2e.spec.js
Martin Donnelly 57bd6c8e6a init
2018-06-24 21:15:03 +01:00

70 lines
1.9 KiB
JavaScript

/**
* @fileOverview End-to-end testing of the catch-all rejection of paths not covered by swagger
*/
'use strict';
/* eslint-disable max-nested-callbacks */
// eslint-disable-next-line no-unused-vars
const testGlobals = require('../../tools/test/testGlobals.js');
const request = require('supertest');
const express = require('express');
const chai = require('chai');
const initDevApi = require('../dev_server.js');
const expect = chai.expect;
/**
* Correct auth method (Bearer), correct token
*/
const TOKEN_VALID = 'YTM2ZGQ1NzUtOWFmNS01MjMyLTg5MjYtM2NkZjA5ZDU2ZGU1';
const HEADER_VALID = 'Bearer ' + TOKEN_VALID;
/**
* Use supertest to make an authenticated request to the server to a path
* that doesn't exist
*
* @param {Object} app - The express app to make the request to
*
* @returns {Promise} - Promise for the result of making the request
*/
function makeAuthenticatedRequest(app) {
return request(app)
.get('/dev/v0/not-a-specified-path-in-the-swagger')
.set('Accept', 'application/json')
.set('Authorization', HEADER_VALID);
}
/**
* Tests
*/
describe('E2E: invalid path handling', () => {
describe('invalid path', () => {
let app;
/**
* Initialise the app before running any tests
*/
before(() => {
app = express();
const devApiRouter = initDevApi.init();
app.use('/dev', devApiRouter);
});
it('responds with 404', () => {
return makeAuthenticatedRequest(app)
.expect(404);
});
it('responds with error body', () => {
return makeAuthenticatedRequest(app)
.expect(404)
.then((response) => {
return expect(response.body).to.deep.equal({
code: 30000,
description: 'API path not found'
});
});
});
});
});