diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-20 14:35:18 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:04:05 +0200 |
commit | d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch) | |
tree | 4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/tests/api/check-params | |
parent | 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff) | |
download | PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip |
Add videos list filters
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/search.ts | 122 |
2 files changed, 123 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index c0e0302df..820dde889 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -10,3 +10,4 @@ import './video-captions' | |||
10 | import './video-channels' | 10 | import './video-channels' |
11 | import './video-comments' | 11 | import './video-comments' |
12 | import './videos' | 12 | import './videos' |
13 | import './search' | ||
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts new file mode 100644 index 000000000..d35eac7fe --- /dev/null +++ b/server/tests/api/check-params/search.ts | |||
@@ -0,0 +1,122 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | |||
5 | import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils' | ||
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | ||
7 | |||
8 | describe('Test videos API validator', function () { | ||
9 | const path = '/api/v1/search/videos/' | ||
10 | let server: ServerInfo | ||
11 | |||
12 | // --------------------------------------------------------------- | ||
13 | |||
14 | before(async function () { | ||
15 | this.timeout(30000) | ||
16 | |||
17 | await flushTests() | ||
18 | |||
19 | server = await runServer(1) | ||
20 | }) | ||
21 | |||
22 | describe('When searching videos', function () { | ||
23 | const query = { | ||
24 | search: 'coucou' | ||
25 | } | ||
26 | |||
27 | it('Should fail with a bad start pagination', async function () { | ||
28 | await checkBadStartPagination(server.url, path, null, query) | ||
29 | }) | ||
30 | |||
31 | it('Should fail with a bad count pagination', async function () { | ||
32 | await checkBadCountPagination(server.url, path, null, query) | ||
33 | }) | ||
34 | |||
35 | it('Should fail with an incorrect sort', async function () { | ||
36 | await checkBadSortPagination(server.url, path, null, query) | ||
37 | }) | ||
38 | |||
39 | it('Should success with the correct parameters', async function () { | ||
40 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) | ||
41 | }) | ||
42 | |||
43 | it('Should fail with an invalid category', async function () { | ||
44 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) | ||
45 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) | ||
46 | |||
47 | const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) | ||
48 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | ||
49 | }) | ||
50 | |||
51 | it('Should succeed with a valid category', async function () { | ||
52 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) | ||
53 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) | ||
54 | |||
55 | const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) | ||
56 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | ||
57 | }) | ||
58 | |||
59 | it('Should fail with an invalid licence', async function () { | ||
60 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) | ||
61 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) | ||
62 | |||
63 | const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) | ||
64 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | ||
65 | }) | ||
66 | |||
67 | it('Should succeed with a valid licence', async function () { | ||
68 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) | ||
69 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) | ||
70 | |||
71 | const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) | ||
72 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | ||
73 | }) | ||
74 | |||
75 | it('Should succeed with a valid language', async function () { | ||
76 | const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) | ||
77 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) | ||
78 | |||
79 | const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) | ||
80 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | ||
81 | }) | ||
82 | |||
83 | it('Should succeed with valid tags', async function () { | ||
84 | const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) | ||
85 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) | ||
86 | |||
87 | const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) | ||
88 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | ||
89 | |||
90 | const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) | ||
91 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) | ||
92 | |||
93 | const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) | ||
94 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) | ||
95 | }) | ||
96 | |||
97 | it('Should fail with invalid durations', async function () { | ||
98 | const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) | ||
99 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) | ||
100 | |||
101 | const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) | ||
102 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | ||
103 | }) | ||
104 | |||
105 | it('Should fail with invalid dates', async function () { | ||
106 | const customQuery1 = immutableAssign(query, { startDate: 'hello' }) | ||
107 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) | ||
108 | |||
109 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | ||
110 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | ||
111 | }) | ||
112 | }) | ||
113 | |||
114 | after(async function () { | ||
115 | killallServers([ server ]) | ||
116 | |||
117 | // Keep the logs if the test failed | ||
118 | if (this['ok']) { | ||
119 | await flushTests() | ||
120 | } | ||
121 | }) | ||
122 | }) | ||