-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (43 loc) · 1.58 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
const hapi = require('hapi');
const lib = require('./index');
const cls = require('continuation-local-storage');
describe('hapi-cls', function () {
let server;
beforeEach(function () {
server = new hapi.Server();
server.connection();
});
it('should throw an error if the namespace name isnt supplied', function () {
server.register({ register: lib, options: {}}).should.be.rejected
});
it('should not require an appVar', function (done) {
server.register({ register: lib, options: { namespace: 'namespace' }}, done);
});
describe('when the plugin has been registered', function () {
beforeEach(function (done) {
server.register({ register: lib, options: { namespace: 'foo', set: {requestId: (request) => 'dummy' }}}, done);
});
it('should exist', function () {
lib.should.exist;
});
it('should register a namespace with hapi', function () {
server.plugins.should.have.property('@plan3-relate/hapi-cls');
});
it('should execute custom setters to the namespace', function (done) {
server.route({
path: '/foo',
method: 'get',
handler: function () {
cls.getNamespace('foo').get('requestId').should.equal('dummy');
done();
}
});
server.inject('/foo');
});
});
});