aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/requests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-04 21:21:47 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-04 21:30:18 +0200
commit0e1dc3e7c69995c691e1dd82e3c2bc68748661ca (patch)
treef2a4b5cffc72e33c902b67083bbaa35b6f22f0ca /server/tests/utils/requests.js
parentb0f9f39ed70299a208d1b388c72de8b7f3510cb7 (diff)
downloadPeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.gz
PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.zst
PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.zip
Convert tests to typescript
Diffstat (limited to 'server/tests/utils/requests.js')
-rw-r--r--server/tests/utils/requests.js73
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
3const request = require('supertest')
4
5const requestsUtils = {
6 makePostUploadRequest,
7 makePostBodyRequest,
8 makePutBodyRequest
9}
10
11// ---------------------- Export functions --------------------
12
13function 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
43function 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
57function 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
73module.exports = requestsUtils