-
Notifications
You must be signed in to change notification settings - Fork 21
/
main_spec.js
155 lines (128 loc) · 3.53 KB
/
main_spec.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var assert = require('assert'),
http = require('http'),
app = require('./app'),
session = require('../index');
function isTestCookie (c) {
return c.name === 'supertest-session';
}
describe('supertest-session', function () {
var sess = null;
beforeEach(function (done) {
sess = session(app);
sess.request('get', '/')
.expect(200)
.expect('GET,,1')
.end(done);
});
it('should increment session counter', function (done) {
sess.request('get', '/')
.expect(200)
.expect('GET,,2')
.end(done);
});
it('should expose cookies', function () {
expect(sess.cookies.some(isTestCookie)).toBeTruthy();
});
it('should destroy session', function (done) {
sess.destroy();
sess.get('/')
.expect(200)
.expect('GET,,1')
.end(done);
});
describe('method sugar', function () {
var methods = {
'del' : 'DELETE',
'get' : 'GET',
'post' : 'POST',
'put' : 'PUT',
'patch' : 'PATCH'
};
Object.keys(methods).forEach(function (key) {
it('should support ' + key, function (done) {
sess[key]('/')
.expect(200)
.expect(methods[key] + ',,2')
.end(done);
});
});
});
describe('(#16) requesting URL of existing app', function () {
var sess,
server = http.createServer(app);
beforeEach(function (done) {
server.listen(0, function (err) {
if (err) {
return done(err);
}
sess = session('http://127.0.0.1:' + server.address().port);
done();
});
});
afterEach(function (done) {
server.close(done);
});
it('behaves correctly', function (done) {
sess
.get('/')
.expect(200)
.expect('GET,,1')
.end(done);
});
});
describe('(#30) requesting URL of instantiated app', function () {
it('behaves correctly', function (done) {
var server = http.createServer(app);
var sess = session(server);
sess
.get('/')
.expect(200)
.expect('GET,,1')
.end(done);
});
});
});
describe('Session with a .before hook', function () {
var sess = null;
beforeEach(function (done) {
sess = session(app, {
before: function (req) {
req.set('authorization', 'bearer TEST_SESSION_TOKEN');
}
});
sess.request('get', '/token')
.expect(200)
.expect('GET,token,1')
.end(done);
});
it('should increment session counter', function (done) {
sess.request('get', '/token')
.expect(200)
.expect('GET,token,2')
.end(done);
});
});
describe('Session with a cookieConfig', function () {
it('should configure default cookieAccess', function (done) {
var sess = session(app);
assert.strictEqual(sess.cookieAccess.domain, '127.0.0.1');
assert.strictEqual(sess.cookieAccess.path, '/');
assert.strictEqual(sess.cookieAccess.secure, false);
assert.strictEqual(sess.cookieAccess.script, false);
done();
});
it('should allow to specify cookieAccess', function (done) {
var cookieAccess = {
domain: 'example.com',
path: '/testpath',
secure: true,
script: true,
};
var sess = session(app, { cookieAccess: cookieAccess });
assert.strictEqual(sess.cookieAccess.domain, cookieAccess.domain);
assert.strictEqual(sess.cookieAccess.path, cookieAccess.path);
assert.strictEqual(sess.cookieAccess.secure, cookieAccess.secure);
assert.strictEqual(sess.cookieAccess.script, cookieAccess.script);
done();
});
});