aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/search.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-20 14:35:18 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commitd525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch)
tree4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/tests/api/check-params/search.ts
parent57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff)
downloadPeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip
Add videos list filters
Diffstat (limited to 'server/tests/api/check-params/search.ts')
-rw-r--r--server/tests/api/check-params/search.ts122
1 files changed, 122 insertions, 0 deletions
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
3import 'mocha'
4
5import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils'
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
7
8describe('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})