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