diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:29:57 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 14:29:57 +0100 |
commit | eec63bbc0f4fdb39e56f37127b35c449f90a135f (patch) | |
tree | 2403f5efea3e281698ae4a6b550fea9dfc52e390 /server/tests/utils/requests/requests.ts | |
parent | c5d31dba56d669c0df0209761c43c5a6ac7cec4a (diff) | |
download | PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.tar.gz PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.tar.zst PeerTube-eec63bbc0f4fdb39e56f37127b35c449f90a135f.zip |
Improve check follow params tests
Diffstat (limited to 'server/tests/utils/requests/requests.ts')
-rw-r--r-- | server/tests/utils/requests/requests.ts | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index 52b7a4c29..eb02cf9e6 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts | |||
@@ -1,11 +1,43 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | 2 | ||
3 | function makeGetRequest (url: string, path: string) { | 3 | function makeGetRequest (options: { |
4 | return request(url) | 4 | url: string, |
5 | .get(path) | 5 | path: string, |
6 | query?: any, | ||
7 | token?: string, | ||
8 | statusCodeExpected?: number | ||
9 | }) { | ||
10 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | ||
11 | |||
12 | const req = request(options.url) | ||
13 | .get(options.path) | ||
6 | .set('Accept', 'application/json') | 14 | .set('Accept', 'application/json') |
7 | .expect(200) | 15 | |
16 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | ||
17 | if (options.query) req.query(options.query) | ||
18 | |||
19 | return req | ||
8 | .expect('Content-Type', /json/) | 20 | .expect('Content-Type', /json/) |
21 | .expect(options.statusCodeExpected) | ||
22 | } | ||
23 | |||
24 | function makeDeleteRequest (options: { | ||
25 | url: string, | ||
26 | path: string, | ||
27 | token?: string, | ||
28 | statusCodeExpected?: number | ||
29 | }) { | ||
30 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | ||
31 | |||
32 | const req = request(options.url) | ||
33 | .delete(options.path) | ||
34 | .set('Accept', 'application/json') | ||
35 | |||
36 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | ||
37 | |||
38 | return req | ||
39 | .expect('Content-Type', /json/) | ||
40 | .expect(options.statusCodeExpected) | ||
9 | } | 41 | } |
10 | 42 | ||
11 | function makePostUploadRequest (options: { | 43 | function makePostUploadRequest (options: { |
@@ -48,9 +80,10 @@ function makePostBodyRequest (options: { | |||
48 | url: string, | 80 | url: string, |
49 | path: string, | 81 | path: string, |
50 | token?: string, | 82 | token?: string, |
51 | fields: { [ fieldName: string ]: any }, | 83 | fields?: { [ fieldName: string ]: any }, |
52 | statusCodeExpected?: number | 84 | statusCodeExpected?: number |
53 | }) { | 85 | }) { |
86 | if (!options.fields) options.fields = {} | ||
54 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 87 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 |
55 | 88 | ||
56 | const req = request(options.url) | 89 | const req = request(options.url) |
@@ -88,5 +121,6 @@ export { | |||
88 | makeGetRequest, | 121 | makeGetRequest, |
89 | makePostUploadRequest, | 122 | makePostUploadRequest, |
90 | makePostBodyRequest, | 123 | makePostBodyRequest, |
91 | makePutBodyRequest | 124 | makePutBodyRequest, |
125 | makeDeleteRequest | ||
92 | } | 126 | } |