This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
/
get-400.js
118 lines (101 loc) · 3.47 KB
/
get-400.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
define([
'intern!object',
'intern/chai!assert',
'intern/dojo/node!bluebird',
'intern/dojo/node!path',
'intern/dojo/node!sinon',
'intern/dojo/node!../../../server/lib/routes/get-400',
], function (registerSuite, assert, Promise, path, sinon, route) {
var config, instance, request, response;
registerSuite({
name: 'routes/get-400',
'route interface is correct': function () {
assert.isFunction(route);
assert.lengthOf(route, 1);
},
'initialise route': {
setup: function () {
config = {
get: sinon.spy(function () {
return 'foo';
})
};
instance = route(config);
},
'instance interface is correct': function () {
assert.isObject(instance);
assert.lengthOf(Object.keys(instance), 3);
assert.equal(instance.method, 'get');
assert.equal(instance.path, '/400.html');
assert.isFunction(instance.process);
assert.lengthOf(instance.process, 2);
},
'route.process with __400_message cookie set': {
setup: function () {
request = {
cookies: {
'__400_message': 'Invalid parameter: email'
},
gettext: function (msg) {
return msg;
}
};
response = {
clearCookie: sinon.spy(),
removeHeader: sinon.spy(),
render: sinon.spy()
};
instance.process(request, response);
},
'x-frame-options headers are removed': function () {
assert.isTrue(response.removeHeader.calledOnce);
assert.isTrue(response.removeHeader.calledWith('x-frame-options'));
},
'the __400_message cookie is cleared': function () {
assert.isTrue(response.clearCookie.calledOnce);
assert.isTrue(response.clearCookie.calledWith('__400_message', { path: '/400.html' }));
},
'response.render was called correctly': function () {
assert.equal(response.render.callCount, 1);
var args = response.render.args[0];
assert.lengthOf(args, 2);
assert.equal(args[0], '400');
assert.isObject(args[1]);
assert.lengthOf(Object.keys(args[1]), 2);
assert.equal(args[1].message, 'Invalid parameter: email');
assert.equal(args[1].staticResourceUrl, 'foo');
}
},
'route.process without __400_message cookie set': {
setup: function () {
request = {
cookies: {
},
gettext: function (msg) {
return msg;
}
};
response = {
clearCookie: sinon.spy(),
removeHeader: sinon.spy(),
render: sinon.spy()
};
instance.process(request, response);
},
'response.render was called correctly': function () {
assert.equal(response.render.callCount, 1);
var args = response.render.args[0];
assert.lengthOf(args, 2);
assert.equal(args[0], '400');
assert.isObject(args[1]);
assert.lengthOf(Object.keys(args[1]), 2);
assert.equal(args[1].message, 'Unexpected error');
assert.equal(args[1].staticResourceUrl, 'foo');
}
}
}
});
});