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