@villedemontreal/http-request 7.4.10 → 7.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/configs.d.ts +1 -0
- package/dist/config/configs.d.ts.map +1 -0
- package/dist/src/config/configs.d.ts +1 -0
- package/dist/src/config/configs.d.ts.map +1 -0
- package/dist/src/config/configs.js.map +1 -1
- package/dist/src/config/constants.d.ts +1 -0
- package/dist/src/config/constants.d.ts.map +1 -0
- package/dist/src/config/init.d.ts +1 -0
- package/dist/src/config/init.d.ts.map +1 -0
- package/dist/src/config/init.js +2 -3
- package/dist/src/config/init.js.map +1 -1
- package/dist/src/httpUtils.d.ts +1 -0
- package/dist/src/httpUtils.d.ts.map +1 -0
- package/dist/src/httpUtils.js +71 -82
- package/dist/src/httpUtils.js.map +1 -1
- package/dist/src/httpUtils.test.d.ts +1 -0
- package/dist/src/httpUtils.test.d.ts.map +1 -0
- package/dist/src/httpUtils.test.js +145 -158
- package/dist/src/httpUtils.test.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/utils/logger.d.ts +1 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +2 -3
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/utils/testingConfigurations.d.ts +1 -0
- package/dist/src/utils/testingConfigurations.d.ts.map +1 -0
- package/dist/src/utils/testingConfigurations.js +1 -2
- package/dist/src/utils/testingConfigurations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +33 -31
- package/dist/scripts/index.d.ts +0 -2
- package/dist/scripts/index.js +0 -14
- package/dist/scripts/index.js.map +0 -1
- package/dist/scripts/lint.d.ts +0 -6
- package/dist/scripts/lint.js +0 -31
- package/dist/scripts/lint.js.map +0 -1
- package/dist/scripts/lintFix.d.ts +0 -6
- package/dist/scripts/lintFix.js +0 -40
- package/dist/scripts/lintFix.js.map +0 -1
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
// Ok in test files :
|
|
3
3
|
// tslint:disable:no-string-literal
|
|
4
4
|
// tslint:disable: max-func-body-length
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
const src_1 = require("@villedemontreal/general-utils/dist/src");
|
|
16
7
|
const chai_1 = require("chai");
|
|
@@ -30,50 +21,50 @@ const superagentMocker = require('superagent-mocker');
|
|
|
30
21
|
(0, testingConfigurations_1.setTestingConfigurations)();
|
|
31
22
|
describe('httpUtils', () => {
|
|
32
23
|
describe('urlJoin', () => {
|
|
33
|
-
it('single param with slash', () =>
|
|
24
|
+
it('single param with slash', async () => {
|
|
34
25
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/'), 'http://google.com');
|
|
35
|
-
})
|
|
36
|
-
it('single param no slash', () =>
|
|
26
|
+
});
|
|
27
|
+
it('single param no slash', async () => {
|
|
37
28
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com'), 'http://google.com');
|
|
38
|
-
})
|
|
39
|
-
it('with slashes', () =>
|
|
29
|
+
});
|
|
30
|
+
it('with slashes', async () => {
|
|
40
31
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', 'foo/', '/bar/'), 'http://google.com/foo/bar');
|
|
41
|
-
})
|
|
42
|
-
it('without slashes', () =>
|
|
32
|
+
});
|
|
33
|
+
it('without slashes', async () => {
|
|
43
34
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com', 'foo', 'bar'), 'http://google.com/foo/bar');
|
|
44
|
-
})
|
|
45
|
-
it('without double slashes', () =>
|
|
35
|
+
});
|
|
36
|
+
it('without double slashes', async () => {
|
|
46
37
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', '//foo/', '//bar/'), 'http://google.com/foo/bar');
|
|
47
|
-
})
|
|
48
|
-
it('with slashes without text', () =>
|
|
38
|
+
});
|
|
39
|
+
it('with slashes without text', async () => {
|
|
49
40
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', '///', '//bar/'), 'http://google.com/bar');
|
|
50
|
-
})
|
|
51
|
-
it('with slashes and empty text', () =>
|
|
41
|
+
});
|
|
42
|
+
it('with slashes and empty text', async () => {
|
|
52
43
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', '', '//bar/'), 'http://google.com/bar');
|
|
53
|
-
})
|
|
54
|
-
it('with slashes and null text', () =>
|
|
44
|
+
});
|
|
45
|
+
it('with slashes and null text', async () => {
|
|
55
46
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', null, '//bar/'), 'http://google.com/bar');
|
|
56
|
-
})
|
|
57
|
-
it('with slashes and undefined text', () =>
|
|
47
|
+
});
|
|
48
|
+
it('with slashes and undefined text', async () => {
|
|
58
49
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://google.com/', undefined, '//bar/'), 'http://google.com/bar');
|
|
59
|
-
})
|
|
60
|
-
it('with http 2 slashes', () =>
|
|
50
|
+
});
|
|
51
|
+
it('with http 2 slashes', async () => {
|
|
61
52
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://', 'google.com', 'foo', 'bar'), 'http://google.com/foo/bar');
|
|
62
|
-
})
|
|
63
|
-
it('with http 1 slash', () =>
|
|
53
|
+
});
|
|
54
|
+
it('with http 1 slash', async () => {
|
|
64
55
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http:/', 'google.com', 'foo', 'bar'), 'http://google.com/foo/bar');
|
|
65
|
-
})
|
|
66
|
-
it('with http no slash', () =>
|
|
56
|
+
});
|
|
57
|
+
it('with http no slash', async () => {
|
|
67
58
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http:', 'google.com', 'foo', 'bar'), 'http://google.com/foo/bar');
|
|
68
|
-
})
|
|
69
|
-
it('another example', () =>
|
|
59
|
+
});
|
|
60
|
+
it('another example', async () => {
|
|
70
61
|
chai_1.assert.equal(httpUtils_1.httpUtils.urlJoin('http://api.montreal.ca/accounts/', '/inum', '@5441521452', 'tickets'), 'http://api.montreal.ca/accounts/inum/@5441521452/tickets');
|
|
71
|
-
})
|
|
62
|
+
});
|
|
72
63
|
});
|
|
73
64
|
describe('send', () => {
|
|
74
65
|
describe('mocked', () => {
|
|
75
66
|
let mock;
|
|
76
|
-
before(() =>
|
|
67
|
+
before(async () => {
|
|
77
68
|
mock = superagentMocker(superagent);
|
|
78
69
|
mock.get('http://localhost/test', (req) => {
|
|
79
70
|
return {
|
|
@@ -82,25 +73,25 @@ describe('httpUtils', () => {
|
|
|
82
73
|
},
|
|
83
74
|
};
|
|
84
75
|
});
|
|
85
|
-
})
|
|
86
|
-
after(() =>
|
|
76
|
+
});
|
|
77
|
+
after(async () => {
|
|
87
78
|
mock.clearRoutes();
|
|
88
79
|
mock.unmock(superagent);
|
|
89
|
-
})
|
|
90
|
-
it('URL must have a hostname', () =>
|
|
80
|
+
});
|
|
81
|
+
it('URL must have a hostname', async () => {
|
|
91
82
|
const request = superagent.get('/test');
|
|
92
83
|
try {
|
|
93
|
-
|
|
84
|
+
await httpUtils_1.httpUtils.send(request);
|
|
94
85
|
chai_1.assert.fail('expected send to throw an error');
|
|
95
86
|
}
|
|
96
87
|
catch (err) {
|
|
97
88
|
chai_1.assert.strictEqual(err.message, 'The URL in your request MUST have a protocol and a hostname. Received: /test');
|
|
98
89
|
}
|
|
99
|
-
})
|
|
100
|
-
it('The Correlation Id is set automatically', () =>
|
|
90
|
+
});
|
|
91
|
+
it('The Correlation Id is set automatically', async () => {
|
|
101
92
|
const currentCid = configs_1.configs.correlationId;
|
|
102
93
|
const request = superagent.get('http://localhost/test').set('titi', '123');
|
|
103
|
-
const response =
|
|
94
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
104
95
|
chai_1.assert.isOk(response);
|
|
105
96
|
chai_1.assert.isOk(response.status);
|
|
106
97
|
chai_1.assert.strictEqual(response.status, 200);
|
|
@@ -109,8 +100,8 @@ describe('httpUtils', () => {
|
|
|
109
100
|
const headers = response.body.headers;
|
|
110
101
|
chai_1.assert.strictEqual(headers.titi, '123');
|
|
111
102
|
chai_1.assert.strictEqual(headers[http_header_fields_typed_1.default.X_CORRELATION_ID.toLowerCase()], currentCid);
|
|
112
|
-
})
|
|
113
|
-
it('Regular response response', () =>
|
|
103
|
+
});
|
|
104
|
+
it('Regular response response', async () => {
|
|
114
105
|
for (const status of [200, 201, 301, 400, 404, 500, 501]) {
|
|
115
106
|
mock.get('http://localhost/test', (req) => {
|
|
116
107
|
return {
|
|
@@ -121,48 +112,48 @@ describe('httpUtils', () => {
|
|
|
121
112
|
};
|
|
122
113
|
});
|
|
123
114
|
const request = superagent.get('http://localhost/test');
|
|
124
|
-
const response =
|
|
115
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
125
116
|
chai_1.assert.isOk(response);
|
|
126
117
|
chai_1.assert.isOk(response.status);
|
|
127
118
|
chai_1.assert.strictEqual(response.status, status);
|
|
128
119
|
chai_1.assert.isObject(response.body);
|
|
129
120
|
chai_1.assert.strictEqual(response.body.msg, 'titi');
|
|
130
121
|
}
|
|
131
|
-
})
|
|
132
|
-
it('Timeouts are added, if not already set', () =>
|
|
122
|
+
});
|
|
123
|
+
it('Timeouts are added, if not already set', async () => {
|
|
133
124
|
const request = superagent.get('http://localhost/test').set('titi', '123');
|
|
134
125
|
chai_1.assert.isUndefined(request['_responseTimeout']);
|
|
135
126
|
chai_1.assert.isUndefined(request['_timeout']);
|
|
136
|
-
const response =
|
|
127
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
137
128
|
chai_1.assert.isOk(response);
|
|
138
129
|
chai_1.assert.strictEqual(request['_responseTimeout'], constants_1.constants.request.timeoutsDefault.response);
|
|
139
130
|
chai_1.assert.strictEqual(request['_timeout'], constants_1.constants.request.timeoutsDefault.deadline);
|
|
140
|
-
})
|
|
141
|
-
it('Response timeout already set', () =>
|
|
131
|
+
});
|
|
132
|
+
it('Response timeout already set', async () => {
|
|
142
133
|
const request = superagent.get('http://localhost/test').set('titi', '123');
|
|
143
134
|
request.timeout({
|
|
144
135
|
response: 55555,
|
|
145
136
|
});
|
|
146
137
|
chai_1.assert.strictEqual(request['_responseTimeout'], 55555);
|
|
147
138
|
chai_1.assert.isUndefined(request['_timeout']);
|
|
148
|
-
const response =
|
|
139
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
149
140
|
chai_1.assert.isOk(response);
|
|
150
141
|
chai_1.assert.strictEqual(request['_responseTimeout'], 55555);
|
|
151
142
|
chai_1.assert.strictEqual(request['_timeout'], constants_1.constants.request.timeoutsDefault.deadline);
|
|
152
|
-
})
|
|
153
|
-
it('Deadline timeout already set', () =>
|
|
143
|
+
});
|
|
144
|
+
it('Deadline timeout already set', async () => {
|
|
154
145
|
const request = superagent.get('http://localhost/test').set('titi', '123');
|
|
155
146
|
request.timeout({
|
|
156
147
|
deadline: 55555,
|
|
157
148
|
});
|
|
158
149
|
chai_1.assert.isUndefined(request['_responseTimeout']);
|
|
159
150
|
chai_1.assert.strictEqual(request['_timeout'], 55555);
|
|
160
|
-
const response =
|
|
151
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
161
152
|
chai_1.assert.isOk(response);
|
|
162
153
|
chai_1.assert.strictEqual(request['_responseTimeout'], constants_1.constants.request.timeoutsDefault.response);
|
|
163
154
|
chai_1.assert.strictEqual(request['_timeout'], 55555);
|
|
164
|
-
})
|
|
165
|
-
it('Both timeouts timeout already set', () =>
|
|
155
|
+
});
|
|
156
|
+
it('Both timeouts timeout already set', async () => {
|
|
166
157
|
const request = superagent.get('http://localhost/test').set('titi', '123');
|
|
167
158
|
request.timeout({
|
|
168
159
|
deadline: 55555,
|
|
@@ -170,34 +161,34 @@ describe('httpUtils', () => {
|
|
|
170
161
|
});
|
|
171
162
|
chai_1.assert.strictEqual(request['_responseTimeout'], 66666);
|
|
172
163
|
chai_1.assert.strictEqual(request['_timeout'], 55555);
|
|
173
|
-
const response =
|
|
164
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
174
165
|
chai_1.assert.isOk(response);
|
|
175
166
|
chai_1.assert.strictEqual(request['_responseTimeout'], 66666);
|
|
176
167
|
chai_1.assert.strictEqual(request['_timeout'], 55555);
|
|
177
|
-
})
|
|
168
|
+
});
|
|
178
169
|
});
|
|
179
170
|
describe('Network/Server error', () => {
|
|
180
|
-
it('Network/Server error', () =>
|
|
171
|
+
it('Network/Server error', async () => {
|
|
181
172
|
const mock = superagentMocker(superagent);
|
|
182
173
|
mock.get('http://localhost/test', (req) => {
|
|
183
174
|
throw new Error('Network error');
|
|
184
175
|
});
|
|
185
176
|
try {
|
|
186
177
|
const request = superagent.get('http://localhost/test');
|
|
187
|
-
const response =
|
|
178
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
188
179
|
chai_1.assert.isNotOk(response);
|
|
189
180
|
chai_1.assert.fail();
|
|
190
181
|
}
|
|
191
182
|
catch (err) {
|
|
192
183
|
/* ok */
|
|
193
184
|
}
|
|
194
|
-
})
|
|
185
|
+
});
|
|
195
186
|
});
|
|
196
187
|
describe('not mocked', () => {
|
|
197
|
-
it('Errors are handled properly', () =>
|
|
188
|
+
it('Errors are handled properly', async () => {
|
|
198
189
|
try {
|
|
199
190
|
const request = superagent.get('httttp://nope').timeout(100);
|
|
200
|
-
const response =
|
|
191
|
+
const response = await httpUtils_1.httpUtils.send(request);
|
|
201
192
|
chai_1.assert.isNotOk(response);
|
|
202
193
|
chai_1.assert.fail();
|
|
203
194
|
}
|
|
@@ -206,7 +197,7 @@ describe('httpUtils', () => {
|
|
|
206
197
|
chai_1.assert.isTrue('msg' in err);
|
|
207
198
|
chai_1.assert.isTrue('originalError' in err);
|
|
208
199
|
}
|
|
209
|
-
})
|
|
200
|
+
});
|
|
210
201
|
});
|
|
211
202
|
});
|
|
212
203
|
describe(`Express request related tests`, () => {
|
|
@@ -214,38 +205,34 @@ describe('httpUtils', () => {
|
|
|
214
205
|
let server;
|
|
215
206
|
let port;
|
|
216
207
|
let expressRequest;
|
|
217
|
-
function startServer(caseSensitive) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
res.sendStatus(HttpStatusCodes.OK);
|
|
224
|
-
}));
|
|
225
|
-
port = yield src_1.utils.findFreePort();
|
|
226
|
-
server = yield app.listen(port);
|
|
208
|
+
async function startServer(caseSensitive) {
|
|
209
|
+
app = express();
|
|
210
|
+
app.set('case sensitive routing', caseSensitive);
|
|
211
|
+
app.get('/', async (req, res, next) => {
|
|
212
|
+
expressRequest = req;
|
|
213
|
+
res.sendStatus(HttpStatusCodes.OK);
|
|
227
214
|
});
|
|
215
|
+
port = await src_1.utils.findFreePort();
|
|
216
|
+
server = await app.listen(port);
|
|
228
217
|
}
|
|
229
|
-
function send(pathAndQueryString) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
chai_1.assert.strictEqual(response.status, HttpStatusCodes.OK);
|
|
234
|
-
});
|
|
218
|
+
async function send(pathAndQueryString) {
|
|
219
|
+
const superagentRequest = superagent.get(`http://localhost:${port}${pathAndQueryString}`);
|
|
220
|
+
const response = await httpUtils_1.httpUtils.send(superagentRequest);
|
|
221
|
+
chai_1.assert.strictEqual(response.status, HttpStatusCodes.OK);
|
|
235
222
|
}
|
|
236
223
|
describe(`Query params functions - Case sensitive`, () => {
|
|
237
|
-
before(() =>
|
|
224
|
+
before(async () => {
|
|
238
225
|
// ==========================================
|
|
239
226
|
// Set the configs for case sensitivity!
|
|
240
227
|
// ==========================================
|
|
241
228
|
(0, testingConfigurations_1.setTestingConfigurations)(true);
|
|
242
|
-
|
|
243
|
-
})
|
|
229
|
+
await startServer(true);
|
|
230
|
+
});
|
|
244
231
|
after(() => {
|
|
245
232
|
server.close();
|
|
246
233
|
});
|
|
247
|
-
it(`no query params`, () =>
|
|
248
|
-
|
|
234
|
+
it(`no query params`, async () => {
|
|
235
|
+
await send(`/`);
|
|
249
236
|
const values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
250
237
|
chai_1.assert.deepEqual(values, []);
|
|
251
238
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -256,9 +243,9 @@ describe('httpUtils', () => {
|
|
|
256
243
|
chai_1.assert.deepEqual(value, undefined);
|
|
257
244
|
value = httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
258
245
|
chai_1.assert.deepEqual(value, undefined);
|
|
259
|
-
})
|
|
260
|
-
it(`one query params - simple string`, () =>
|
|
261
|
-
|
|
246
|
+
});
|
|
247
|
+
it(`one query params - simple string`, async () => {
|
|
248
|
+
await send(`/?k=toto`);
|
|
262
249
|
let values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
263
250
|
chai_1.assert.deepEqual(values, ['toto']);
|
|
264
251
|
values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'K'); // case sensitive
|
|
@@ -313,10 +300,10 @@ describe('httpUtils', () => {
|
|
|
313
300
|
return 123;
|
|
314
301
|
});
|
|
315
302
|
chai_1.assert.deepEqual(value, 123);
|
|
316
|
-
})
|
|
317
|
-
it('one query params - date string', () =>
|
|
303
|
+
});
|
|
304
|
+
it('one query params - date string', async () => {
|
|
318
305
|
const dateStr = '2020-04-21T17:13:33.107Z';
|
|
319
|
-
|
|
306
|
+
await send(`/?k=${encodeURIComponent(dateStr)}`);
|
|
320
307
|
const values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
321
308
|
chai_1.assert.deepEqual(values, [dateStr]);
|
|
322
309
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -371,10 +358,10 @@ describe('httpUtils', () => {
|
|
|
371
358
|
chai_1.assert.fail();
|
|
372
359
|
}
|
|
373
360
|
chai_1.assert.deepEqual(error.message, `Custom Error`);
|
|
374
|
-
})
|
|
375
|
-
it('one query params - number string', () =>
|
|
361
|
+
});
|
|
362
|
+
it('one query params - number string', async () => {
|
|
376
363
|
const testNumber = 123;
|
|
377
|
-
|
|
364
|
+
await send(`/?k=${testNumber}`);
|
|
378
365
|
const values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
379
366
|
chai_1.assert.deepEqual(values, [testNumber + '']);
|
|
380
367
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -401,18 +388,18 @@ describe('httpUtils', () => {
|
|
|
401
388
|
if (!error) {
|
|
402
389
|
chai_1.assert.fail();
|
|
403
390
|
}
|
|
404
|
-
})
|
|
405
|
-
it(`one query params - boolean`, () =>
|
|
406
|
-
|
|
391
|
+
});
|
|
392
|
+
it(`one query params - boolean`, async () => {
|
|
393
|
+
await send(`/?k=true`);
|
|
407
394
|
let value = httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
408
395
|
chai_1.assert.deepEqual(value, true);
|
|
409
|
-
|
|
396
|
+
await send(`/?k=TrUe`);
|
|
410
397
|
value = httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
411
398
|
chai_1.assert.deepEqual(value, true);
|
|
412
|
-
|
|
399
|
+
await send(`/?k=false`);
|
|
413
400
|
value = httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
414
401
|
chai_1.assert.deepEqual(value, false);
|
|
415
|
-
|
|
402
|
+
await send(`/?k=0`);
|
|
416
403
|
let error;
|
|
417
404
|
try {
|
|
418
405
|
httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
@@ -423,7 +410,7 @@ describe('httpUtils', () => {
|
|
|
423
410
|
if (!error) {
|
|
424
411
|
chai_1.assert.fail();
|
|
425
412
|
}
|
|
426
|
-
|
|
413
|
+
await send(`/?k=1`);
|
|
427
414
|
try {
|
|
428
415
|
httpUtils_1.httpUtils.getQueryParamOneAsBoolean(expressRequest, 'k');
|
|
429
416
|
}
|
|
@@ -433,9 +420,9 @@ describe('httpUtils', () => {
|
|
|
433
420
|
if (!error) {
|
|
434
421
|
chai_1.assert.fail();
|
|
435
422
|
}
|
|
436
|
-
})
|
|
437
|
-
it('two different query params', () =>
|
|
438
|
-
|
|
423
|
+
});
|
|
424
|
+
it('two different query params', async () => {
|
|
425
|
+
await send(`/?k1=123&k2=titi`);
|
|
439
426
|
let values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k1');
|
|
440
427
|
chai_1.assert.deepEqual(values, ['123']);
|
|
441
428
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k1');
|
|
@@ -444,9 +431,9 @@ describe('httpUtils', () => {
|
|
|
444
431
|
chai_1.assert.deepEqual(values, ['titi']);
|
|
445
432
|
value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k2');
|
|
446
433
|
chai_1.assert.deepEqual(value, 'titi');
|
|
447
|
-
})
|
|
448
|
-
it('two different query params, different only by casing!', () =>
|
|
449
|
-
|
|
434
|
+
});
|
|
435
|
+
it('two different query params, different only by casing!', async () => {
|
|
436
|
+
await send(`/?k=123&K=titi`);
|
|
450
437
|
let values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
451
438
|
chai_1.assert.deepEqual(values, ['123']);
|
|
452
439
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -455,11 +442,11 @@ describe('httpUtils', () => {
|
|
|
455
442
|
chai_1.assert.deepEqual(values, ['titi']);
|
|
456
443
|
value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'K');
|
|
457
444
|
chai_1.assert.deepEqual(value, 'titi');
|
|
458
|
-
})
|
|
459
|
-
it('One query param with multiple values - first value is a number, second value is a date', () =>
|
|
445
|
+
});
|
|
446
|
+
it('One query param with multiple values - first value is a number, second value is a date', async () => {
|
|
460
447
|
const dateStr = '2020-04-21T17:13:33.107Z';
|
|
461
448
|
const testNumber = 123;
|
|
462
|
-
|
|
449
|
+
await send(`/?k=${testNumber}&k=${encodeURIComponent(dateStr)}`);
|
|
463
450
|
const values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
464
451
|
chai_1.assert.deepEqual(values, [testNumber + '', dateStr]);
|
|
465
452
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -478,11 +465,11 @@ describe('httpUtils', () => {
|
|
|
478
465
|
if (!error) {
|
|
479
466
|
chai_1.assert.fail();
|
|
480
467
|
}
|
|
481
|
-
})
|
|
482
|
-
it('One query param with multiple values - first value is a date, second value is a number', () =>
|
|
468
|
+
});
|
|
469
|
+
it('One query param with multiple values - first value is a date, second value is a number', async () => {
|
|
483
470
|
const dateStr = '2020-04-21T17:13:33.107Z';
|
|
484
471
|
const testNumber = 123;
|
|
485
|
-
|
|
472
|
+
await send(`/?k=${encodeURIComponent(dateStr)}&k=${testNumber}`);
|
|
486
473
|
const values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k');
|
|
487
474
|
chai_1.assert.deepEqual(values, [dateStr, testNumber + '']);
|
|
488
475
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k');
|
|
@@ -494,21 +481,21 @@ describe('httpUtils', () => {
|
|
|
494
481
|
// last value wins and can be parsed to a number
|
|
495
482
|
value = httpUtils_1.httpUtils.getQueryParamOneAsNumber(expressRequest, 'k');
|
|
496
483
|
chai_1.assert.deepEqual(value, testNumber);
|
|
497
|
-
})
|
|
484
|
+
});
|
|
498
485
|
});
|
|
499
486
|
describe('Query params functions - Case insensitive', () => {
|
|
500
|
-
before(() =>
|
|
487
|
+
before(async () => {
|
|
501
488
|
// ==========================================
|
|
502
489
|
// Set the configs for case insensitivity!
|
|
503
490
|
// ==========================================
|
|
504
491
|
(0, testingConfigurations_1.setTestingConfigurations)(false);
|
|
505
|
-
|
|
506
|
-
})
|
|
492
|
+
await startServer(false);
|
|
493
|
+
});
|
|
507
494
|
after(() => {
|
|
508
495
|
server.close();
|
|
509
496
|
});
|
|
510
|
-
it('two different query params, different by casing!', () =>
|
|
511
|
-
|
|
497
|
+
it('two different query params, different by casing!', async () => {
|
|
498
|
+
await send(`/?k=123&K=titi`);
|
|
512
499
|
let values = httpUtils_1.httpUtils.getQueryParamAll(expressRequest, 'k'); // lowercase
|
|
513
500
|
chai_1.assert.deepEqual(values, ['123', 'titi']);
|
|
514
501
|
let value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'k'); // lowercase
|
|
@@ -517,30 +504,30 @@ describe('httpUtils', () => {
|
|
|
517
504
|
chai_1.assert.deepEqual(values, ['123', 'titi']);
|
|
518
505
|
value = httpUtils_1.httpUtils.getQueryParamOne(expressRequest, 'K'); // uppercase
|
|
519
506
|
chai_1.assert.deepEqual(value, 'titi'); // last value wins
|
|
520
|
-
})
|
|
507
|
+
});
|
|
521
508
|
});
|
|
522
509
|
describe('getOrderBys - Case insensitive', () => {
|
|
523
|
-
before(() =>
|
|
510
|
+
before(async () => {
|
|
524
511
|
(0, testingConfigurations_1.setTestingConfigurations)(false);
|
|
525
|
-
|
|
526
|
-
})
|
|
512
|
+
await startServer(false);
|
|
513
|
+
});
|
|
527
514
|
after(() => {
|
|
528
515
|
server.close();
|
|
529
516
|
});
|
|
530
|
-
it('Nil', () =>
|
|
531
|
-
|
|
517
|
+
it('Nil', async () => {
|
|
518
|
+
await send(`/`);
|
|
532
519
|
let orderBys = httpUtils_1.httpUtils.getOrderBys(null);
|
|
533
520
|
chai_1.assert.deepEqual(orderBys, []);
|
|
534
521
|
orderBys = httpUtils_1.httpUtils.getOrderBys(undefined);
|
|
535
522
|
chai_1.assert.deepEqual(orderBys, []);
|
|
536
|
-
})
|
|
537
|
-
it('No orderBys', () =>
|
|
538
|
-
|
|
523
|
+
});
|
|
524
|
+
it('No orderBys', async () => {
|
|
525
|
+
await send(`/`);
|
|
539
526
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
540
527
|
chai_1.assert.deepEqual(orderBys, []);
|
|
541
|
-
})
|
|
542
|
-
it('one orderBy, default is asc', () =>
|
|
543
|
-
|
|
528
|
+
});
|
|
529
|
+
it('one orderBy, default is asc', async () => {
|
|
530
|
+
await send(`/?orderBy=name`);
|
|
544
531
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
545
532
|
chai_1.assert.deepEqual(orderBys, [
|
|
546
533
|
{
|
|
@@ -548,9 +535,9 @@ describe('httpUtils', () => {
|
|
|
548
535
|
direction: src_1.OrderByDirection.ASC,
|
|
549
536
|
},
|
|
550
537
|
]);
|
|
551
|
-
})
|
|
552
|
-
it('one orderBy, explicit asc', () =>
|
|
553
|
-
|
|
538
|
+
});
|
|
539
|
+
it('one orderBy, explicit asc', async () => {
|
|
540
|
+
await send(`/?orderBy=+name`);
|
|
554
541
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
555
542
|
chai_1.assert.deepEqual(orderBys, [
|
|
556
543
|
{
|
|
@@ -558,9 +545,9 @@ describe('httpUtils', () => {
|
|
|
558
545
|
direction: src_1.OrderByDirection.ASC,
|
|
559
546
|
},
|
|
560
547
|
]);
|
|
561
|
-
})
|
|
562
|
-
it('one orderBy, desc', () =>
|
|
563
|
-
|
|
548
|
+
});
|
|
549
|
+
it('one orderBy, desc', async () => {
|
|
550
|
+
await send(`/?orderBy=-name`);
|
|
564
551
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
565
552
|
chai_1.assert.deepEqual(orderBys, [
|
|
566
553
|
{
|
|
@@ -568,9 +555,9 @@ describe('httpUtils', () => {
|
|
|
568
555
|
direction: src_1.OrderByDirection.DESC,
|
|
569
556
|
},
|
|
570
557
|
]);
|
|
571
|
-
})
|
|
572
|
-
it('multiple orderBys', () =>
|
|
573
|
-
|
|
558
|
+
});
|
|
559
|
+
it('multiple orderBys', async () => {
|
|
560
|
+
await send(`/?orderBy=-name,age,+nick,-color`);
|
|
574
561
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
575
562
|
chai_1.assert.deepEqual(orderBys, [
|
|
576
563
|
{
|
|
@@ -590,9 +577,9 @@ describe('httpUtils', () => {
|
|
|
590
577
|
direction: src_1.OrderByDirection.DESC,
|
|
591
578
|
},
|
|
592
579
|
]);
|
|
593
|
-
})
|
|
594
|
-
it('The case sensitivity of the "orderBy" key is not important', () =>
|
|
595
|
-
|
|
580
|
+
});
|
|
581
|
+
it('The case sensitivity of the "orderBy" key is not important', async () => {
|
|
582
|
+
await send(`/?ORDERBY=-name`);
|
|
596
583
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
597
584
|
chai_1.assert.deepEqual(orderBys, [
|
|
598
585
|
{
|
|
@@ -600,9 +587,9 @@ describe('httpUtils', () => {
|
|
|
600
587
|
direction: src_1.OrderByDirection.DESC,
|
|
601
588
|
},
|
|
602
589
|
]);
|
|
603
|
-
})
|
|
604
|
-
it('The case sensitivity of the orderBy *value* is kept', () =>
|
|
605
|
-
|
|
590
|
+
});
|
|
591
|
+
it('The case sensitivity of the orderBy *value* is kept', async () => {
|
|
592
|
+
await send(`/?orderBy=-NAME`);
|
|
606
593
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
607
594
|
chai_1.assert.deepEqual(orderBys, [
|
|
608
595
|
{
|
|
@@ -610,23 +597,23 @@ describe('httpUtils', () => {
|
|
|
610
597
|
direction: src_1.OrderByDirection.DESC,
|
|
611
598
|
},
|
|
612
599
|
]);
|
|
613
|
-
})
|
|
600
|
+
});
|
|
614
601
|
});
|
|
615
602
|
describe('getOrderBys - Case sensitive', () => {
|
|
616
|
-
before(() =>
|
|
603
|
+
before(async () => {
|
|
617
604
|
(0, testingConfigurations_1.setTestingConfigurations)(true);
|
|
618
|
-
|
|
619
|
-
})
|
|
605
|
+
await startServer(true);
|
|
606
|
+
});
|
|
620
607
|
after(() => {
|
|
621
608
|
server.close();
|
|
622
609
|
});
|
|
623
|
-
it('The case sensitivity of the "orderBy" key is important', () =>
|
|
624
|
-
|
|
610
|
+
it('The case sensitivity of the "orderBy" key is important', async () => {
|
|
611
|
+
await send(`/?ORDERBY=-name`);
|
|
625
612
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
626
613
|
chai_1.assert.deepEqual(orderBys, []);
|
|
627
|
-
})
|
|
628
|
-
it('The case sensitivity of the orderBy *value* is kept', () =>
|
|
629
|
-
|
|
614
|
+
});
|
|
615
|
+
it('The case sensitivity of the orderBy *value* is kept', async () => {
|
|
616
|
+
await send(`/?orderBy=-NAME`);
|
|
630
617
|
const orderBys = httpUtils_1.httpUtils.getOrderBys(expressRequest);
|
|
631
618
|
chai_1.assert.deepEqual(orderBys, [
|
|
632
619
|
{
|
|
@@ -634,7 +621,7 @@ describe('httpUtils', () => {
|
|
|
634
621
|
direction: src_1.OrderByDirection.DESC,
|
|
635
622
|
},
|
|
636
623
|
]);
|
|
637
|
-
})
|
|
624
|
+
});
|
|
638
625
|
});
|
|
639
626
|
});
|
|
640
627
|
});
|