forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpressextensions.test.js
33 lines (24 loc) · 924 Bytes
/
expressextensions.test.js
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
'use strict';
require('should');
var extensionsMiddleware = require('../lib/middleware/express-extension-to-accept.js');
var acceptJsonRequests = extensionsMiddleware(['json']);
describe('Express extension middleware', function ( ) {
it('Valid json request should be given accept header for application/json', function () {
var entriesRequest = {
path: '/api/v1/entries.json',
url: '/api/v1/entries.json',
headers: {}
};
acceptJsonRequests(entriesRequest, {}, () => {});
entriesRequest.headers.accept.should.equal('application/json');
});
it('Invalid json request should NOT be given accept header', function () {
var invalidEntriesRequest = {
path: '/api/v1/entriesXjson',
url: '/api/v1/entriesXjson',
headers: {}
};
acceptJsonRequests(invalidEntriesRequest, {}, () => {});
should(invalidEntriesRequest.headers.accept).not.be.ok;
});
});