]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/search.ts
Add ability to search playlists
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / search.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d525fc39
C
2
3import 'mocha'
3b0bd70a
C
4import {
5 cleanupTests,
6 flushAndRunServer,
7 immutableAssign,
8 makeGetRequest,
9 ServerInfo,
10 updateCustomSubConfig,
11 setAccessTokensToServers
12} from '../../../../shared/extra-utils'
9639bd17 13import {
14 checkBadCountPagination,
15 checkBadSortPagination,
16 checkBadStartPagination
94565d52 17} from '../../../../shared/extra-utils/requests/check-api-params'
2d53be02 18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
d525fc39 19
3b0bd70a
C
20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
21 return updateCustomSubConfig(server.url, server.accessToken, {
22 search: {
23 searchIndex: {
24 enabled,
25 disableLocalSearch
26 }
27 }
28 })
29}
30
d525fc39 31describe('Test videos API validator', function () {
d525fc39
C
32 let server: ServerInfo
33
34 // ---------------------------------------------------------------
35
36 before(async function () {
37 this.timeout(30000)
38
210feb6c 39 server = await flushAndRunServer(1)
3b0bd70a 40 await setAccessTokensToServers([ server ])
d525fc39
C
41 })
42
43 describe('When searching videos', function () {
f5b0af50
C
44 const path = '/api/v1/search/videos/'
45
d525fc39
C
46 const query = {
47 search: 'coucou'
48 }
49
50 it('Should fail with a bad start pagination', async function () {
51 await checkBadStartPagination(server.url, path, null, query)
52 })
53
54 it('Should fail with a bad count pagination', async function () {
55 await checkBadCountPagination(server.url, path, null, query)
56 })
57
58 it('Should fail with an incorrect sort', async function () {
59 await checkBadSortPagination(server.url, path, null, query)
60 })
61
62 it('Should success with the correct parameters', async function () {
2d53be02 63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
64 })
65
66 it('Should fail with an invalid category', async function () {
67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
2d53be02 68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
69
70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
2d53be02 71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
72 })
73
74 it('Should succeed with a valid category', async function () {
75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
2d53be02 76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
77
78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
2d53be02 79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
80 })
81
82 it('Should fail with an invalid licence', async function () {
83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
2d53be02 84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
85
86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
2d53be02 87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
88 })
89
90 it('Should succeed with a valid licence', async function () {
91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
2d53be02 92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
93
94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
2d53be02 95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
96 })
97
98 it('Should succeed with a valid language', async function () {
99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
2d53be02 100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
101
102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
2d53be02 103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
104 })
105
106 it('Should succeed with valid tags', async function () {
107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
2d53be02 108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
109
110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
2d53be02 111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
112
113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
2d53be02 114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
115
116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
2d53be02 117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
d525fc39
C
118 })
119
120 it('Should fail with invalid durations', async function () {
121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
2d53be02 122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
123
124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
2d53be02 125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
126 })
127
128 it('Should fail with invalid dates', async function () {
129 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
2d53be02 130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
131
132 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
2d53be02 133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
31d065cc
AM
134
135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
2d53be02 136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
31d065cc
AM
137
138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
2d53be02 139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
d525fc39
C
140 })
141 })
142
37a44fc9
C
143 describe('When searching video playlists', function () {
144 const path = '/api/v1/search/video-playlists/'
145
146 const query = {
147 search: 'coucou'
148 }
149
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, null, query)
152 })
153
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, null, query)
156 })
157
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, null, query)
160 })
161
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
164 })
165 })
166
f5b0af50
C
167 describe('When searching video channels', function () {
168 const path = '/api/v1/search/video-channels/'
169
170 const query = {
171 search: 'coucou'
172 }
173
174 it('Should fail with a bad start pagination', async function () {
175 await checkBadStartPagination(server.url, path, null, query)
176 })
177
178 it('Should fail with a bad count pagination', async function () {
179 await checkBadCountPagination(server.url, path, null, query)
180 })
181
182 it('Should fail with an incorrect sort', async function () {
183 await checkBadSortPagination(server.url, path, null, query)
184 })
185
186 it('Should success with the correct parameters', async function () {
2d53be02 187 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
f5b0af50
C
188 })
189 })
190
3b0bd70a
C
191 describe('Search target', function () {
192
193 it('Should fail/succeed depending on the search target', async function () {
194 this.timeout(10000)
195
196 const query = { search: 'coucou' }
197 const paths = [
37a44fc9 198 '/api/v1/search/video-playlists/',
3b0bd70a
C
199 '/api/v1/search/video-channels/',
200 '/api/v1/search/videos/'
201 ]
202
203 for (const path of paths) {
204 {
205 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
2d53be02 206 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
3b0bd70a
C
207 }
208
209 {
210 const customQuery = immutableAssign(query, { searchTarget: undefined })
2d53be02 211 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
3b0bd70a
C
212 }
213
214 {
215 const customQuery = immutableAssign(query, { searchTarget: 'local' })
2d53be02 216 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
3b0bd70a
C
217 }
218
219 {
220 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
2d53be02 221 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
3b0bd70a
C
222 }
223
224 await updateSearchIndex(server, true, true)
225
226 {
227 const customQuery = immutableAssign(query, { searchTarget: 'local' })
2d53be02 228 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
3b0bd70a
C
229 }
230
231 {
232 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
2d53be02 233 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
3b0bd70a
C
234 }
235
236 await updateSearchIndex(server, true, false)
237
238 {
239 const customQuery = immutableAssign(query, { searchTarget: 'local' })
2d53be02 240 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
3b0bd70a
C
241 }
242
243 await updateSearchIndex(server, false, false)
244 }
245 })
246 })
247
7c3b7976
C
248 after(async function () {
249 await cleanupTests([ server ])
d525fc39
C
250 })
251})