diff options
Diffstat (limited to 'server/tests/utils/requests.js')
-rw-r--r-- | server/tests/utils/requests.js | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/server/tests/utils/requests.js b/server/tests/utils/requests.js deleted file mode 100644 index 84cf3483f..000000000 --- a/server/tests/utils/requests.js +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | |||
5 | const requestsUtils = { | ||
6 | makePostUploadRequest, | ||
7 | makePostBodyRequest, | ||
8 | makePutBodyRequest | ||
9 | } | ||
10 | |||
11 | // ---------------------- Export functions -------------------- | ||
12 | |||
13 | function makePostUploadRequest (url, path, token, fields, attaches, done, statusCodeExpected) { | ||
14 | if (!statusCodeExpected) statusCodeExpected = 400 | ||
15 | |||
16 | const req = request(url) | ||
17 | .post(path) | ||
18 | .set('Accept', 'application/json') | ||
19 | |||
20 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
21 | |||
22 | Object.keys(fields).forEach(function (field) { | ||
23 | const value = fields[field] | ||
24 | |||
25 | if (Array.isArray(value)) { | ||
26 | for (let i = 0; i < value.length; i++) { | ||
27 | req.field(field + '[' + i + ']', value[i]) | ||
28 | } | ||
29 | } else { | ||
30 | req.field(field, value) | ||
31 | } | ||
32 | }) | ||
33 | |||
34 | Object.keys(attaches).forEach(function (attach) { | ||
35 | const value = attaches[attach] | ||
36 | req.attach(attach, value) | ||
37 | }) | ||
38 | |||
39 | req.expect(statusCodeExpected) | ||
40 | .end(done) | ||
41 | } | ||
42 | |||
43 | function makePostBodyRequest (url, path, token, fields, done, statusCodeExpected) { | ||
44 | if (!statusCodeExpected) statusCodeExpected = 400 | ||
45 | |||
46 | const req = request(url) | ||
47 | .post(path) | ||
48 | .set('Accept', 'application/json') | ||
49 | |||
50 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
51 | |||
52 | req.send(fields) | ||
53 | .expect(statusCodeExpected) | ||
54 | .end(done) | ||
55 | } | ||
56 | |||
57 | function makePutBodyRequest (url, path, token, fields, done, statusCodeExpected) { | ||
58 | if (!statusCodeExpected) statusCodeExpected = 400 | ||
59 | |||
60 | const req = request(url) | ||
61 | .put(path) | ||
62 | .set('Accept', 'application/json') | ||
63 | |||
64 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
65 | |||
66 | req.send(fields) | ||
67 | .expect(statusCodeExpected) | ||
68 | .end(done) | ||
69 | } | ||
70 | |||
71 | // --------------------------------------------------------------------------- | ||
72 | |||
73 | module.exports = requestsUtils | ||