aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/requests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/requests')
-rw-r--r--server/tests/utils/requests/requests.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts
index 840072430..a9b1dff9a 100644
--- a/server/tests/utils/requests/requests.ts
+++ b/server/tests/utils/requests/requests.ts
@@ -1,4 +1,5 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { buildAbsoluteFixturePath } from '../'
2 3
3function makeGetRequest (options: { 4function makeGetRequest (options: {
4 url: string, 5 url: string,
@@ -40,8 +41,9 @@ function makeDeleteRequest (options: {
40 .expect(options.statusCodeExpected) 41 .expect(options.statusCodeExpected)
41} 42}
42 43
43function makePostUploadRequest (options: { 44function makeUploadRequest (options: {
44 url: string, 45 url: string,
46 method?: 'POST' | 'PUT',
45 path: string, 47 path: string,
46 token: string, 48 token: string,
47 fields: { [ fieldName: string ]: any }, 49 fields: { [ fieldName: string ]: any },
@@ -50,9 +52,14 @@ function makePostUploadRequest (options: {
50}) { 52}) {
51 if (!options.statusCodeExpected) options.statusCodeExpected = 400 53 if (!options.statusCodeExpected) options.statusCodeExpected = 400
52 54
53 const req = request(options.url) 55 let req: request.Test
54 .post(options.path) 56 if (options.method === 'PUT') {
55 .set('Accept', 'application/json') 57 req = request(options.url).put(options.path)
58 } else {
59 req = request(options.url).post(options.path)
60 }
61
62 req.set('Accept', 'application/json')
56 63
57 if (options.token) req.set('Authorization', 'Bearer ' + options.token) 64 if (options.token) req.set('Authorization', 'Bearer ' + options.token)
58 65
@@ -70,7 +77,7 @@ function makePostUploadRequest (options: {
70 77
71 Object.keys(options.attaches).forEach(attach => { 78 Object.keys(options.attaches).forEach(attach => {
72 const value = options.attaches[attach] 79 const value = options.attaches[attach]
73 req.attach(attach, value) 80 req.attach(attach, buildAbsoluteFixturePath(value))
74 }) 81 })
75 82
76 return req.expect(options.statusCodeExpected) 83 return req.expect(options.statusCodeExpected)
@@ -119,7 +126,7 @@ function makePutBodyRequest (options: {
119 126
120export { 127export {
121 makeGetRequest, 128 makeGetRequest,
122 makePostUploadRequest, 129 makeUploadRequest,
123 makePostBodyRequest, 130 makePostBodyRequest,
124 makePutBodyRequest, 131 makePutBodyRequest,
125 makeDeleteRequest 132 makeDeleteRequest