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 | |
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')
-rw-r--r-- | server/tests/utils/requests/check-api-params.ts | 36 | ||||
-rw-r--r-- | server/tests/utils/requests/requests.ts | 46 |
2 files changed, 76 insertions, 6 deletions
diff --git a/server/tests/utils/requests/check-api-params.ts b/server/tests/utils/requests/check-api-params.ts new file mode 100644 index 000000000..fbd660629 --- /dev/null +++ b/server/tests/utils/requests/check-api-params.ts | |||
@@ -0,0 +1,36 @@ | |||
1 | import { makeGetRequest } from './requests' | ||
2 | |||
3 | function checkBadStartPagination (url: string, path: string) { | ||
4 | return makeGetRequest({ | ||
5 | url, | ||
6 | path, | ||
7 | query: { start: 'hello' }, | ||
8 | statusCodeExpected: 400 | ||
9 | }) | ||
10 | } | ||
11 | |||
12 | function checkBadCountPagination (url: string, path: string) { | ||
13 | return makeGetRequest({ | ||
14 | url, | ||
15 | path, | ||
16 | query: { count: 'hello' }, | ||
17 | statusCodeExpected: 400 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | function checkBadSortPagination (url: string, path: string) { | ||
22 | return makeGetRequest({ | ||
23 | url, | ||
24 | path, | ||
25 | query: { sort: 'hello' }, | ||
26 | statusCodeExpected: 400 | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
32 | export { | ||
33 | checkBadStartPagination, | ||
34 | checkBadCountPagination, | ||
35 | checkBadSortPagination | ||
36 | } | ||
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 | } |