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