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