All files / test headers.spec.js

100% Statements 22/22
100% Branches 0/0
100% Functions 13/13
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66    1x   1x 1x 6x     1x 6x     1x 1x 1x                 1x 1x 1x               1x 1x           1x 1x 1x         1x 1x             1x 1x 1x              
'use strict';
 
const path = require('path');
 
describe("Headers", function() {
  beforeEach(function(done) {
    this.startServer({ dataPath: 'test/data/headers' }).then(done, done.fail);
  });
 
  afterEach(function(done) {
    this.stopServer().then(done, done.fail);
  });
 
  describe("X-Mockiji-Url", function() {
    it('should return the requested path', function(done) {
      this.checkPaths('GET', {
        'api/': {headers: {'X-Mockiji-Url': '/api'}},
        'api/test': {headers: {'X-Mockiji-Url': '/api/test'}},
        'api/subdir1': {headers: {'X-Mockiji-Url': '/api/subdir1'}},
        'api/subdir1/test': {headers: {'X-Mockiji-Url': '/api/subdir1/test'}},
      }).then(done, done.fail);
    });
  });
 
  describe("X-Mockiji-File", function() {
    it('should return the mock file path if found', function(done) {
      this.checkPaths('GET', {
        'api/': {headers: {'X-Mockiji-File': path.resolve(__dirname, 'data/headers/api/get.json')}},
        'api/test': {headers: {'X-Mockiji-File': path.resolve(__dirname, 'data/headers/api/get_test.json')}},
        'api/subdir1': {headers: {'X-Mockiji-File': path.resolve(__dirname, 'data/headers/api/subdir1/get.json')}},
        'api/subdir1/test': {headers: {'X-Mockiji-File': path.resolve(__dirname, 'data/headers/api/subdir1/get_test.json')}},
      }).then(done, done.fail);
    });
 
    it('should not be present if a mock file was not found', function(done) {
      this.checkPaths('GET', {
        'api/missing_mock': {headers: {'X-Mockiji-File': undefined}}, // eslint-disable-line no-undefined
      }).then(done, done.fail);
    });
  });
 
  describe("X-Mockiji-Not-Found", function() {
    it('should be set if a mock file was not found', function(done) {
      this.checkPaths('GET', {
        'api/missing_mock': {headers: {'X-Mockiji-Not-Found': 'true'}},
      }).then(done, done.fail);
    });
 
    it('should not be present if a mock file has been found', function(done) {
      this.checkPaths('GET', {
        'api/': {headers: {'X-Mockiji-Not-Found': undefined}}, // eslint-disable-line no-undefined
        'api/test': {headers: {'X-Mockiji-Not-Found': undefined}}, // eslint-disable-line no-undefined
      }).then(done, done.fail);
    });
  });
 
  describe("X-Mockiji-Notices", function() {
    it('should contain additional information if needed', function(done) {
      this.checkPaths('GET', {
        'api/notices/empty_file': {headers: {'X-Mockiji-Notices': 'The mock file is empty'}},
        'api/notices/invalid_json': {headers: {'X-Mockiji-Notices': 'The mock file contains invalid JSON'}},
      }).then(done, done.fail);
    });
  });
});