forked from restify/node-restify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.test.js
More file actions
100 lines (86 loc) · 2.56 KB
/
Copy pathcontext.test.js
File metadata and controls
100 lines (86 loc) · 2.56 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
/* eslint-disable func-names */
// external requires
var assert = require('chai').assert;
var restify = require('../../lib/index.js');
var restifyClients = require('restify-clients');
// local files
var helper = require('../lib/helper');
// local globals
var SERVER;
var CLIENT;
var PORT;
describe('accept parser', function() {
before(function(done) {
SERVER = restify.createServer({
dtrace: helper.dtrace,
log: helper.getLog('server')
});
SERVER.use(restify.plugins.pre.context());
SERVER.listen(0, '127.0.0.1', function() {
PORT = SERVER.address().port;
CLIENT = restifyClients.createJsonClient({
url: 'http://127.0.0.1:' + PORT,
dtrace: helper.dtrace,
retry: false
});
done();
});
});
after(function(done) {
CLIENT.close();
SERVER.close(done);
});
it('should use context', function(done) {
SERVER.get('/', [
function one(req, res, next) {
req.set('foo', {
a: 1
});
return next();
},
function two(req, res, next) {
assert.deepEqual(req.get('foo'), {
a: 1
});
req.get('foo').b = 2;
req.set('bar', [1]);
return next();
},
function three(req, res, next) {
assert.deepEqual(req.get('foo'), {
a: 1,
b: 2
});
assert.deepEqual(req.get('bar'), [1]);
assert.deepEqual(req.getAll(), {
foo: {
a: 1,
b: 2
},
bar: [1]
});
res.send();
return next();
}
]);
CLIENT.get('/', function(err, _, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
return done();
});
});
it('should not share context', function(done) {
SERVER.get('/1', function one(req, res, next) {
// ensure we don't get context from previous request
assert.equal(req.get('foo', null));
res.end();
return next();
});
CLIENT.get('/1', function(err, _, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
return done();
});
});
});