]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { HttpStatusCode } from '@shared/core-utils' | |
5 | import { | |
6 | checkBadCountPagination, | |
7 | checkBadSortPagination, | |
8 | checkBadStartPagination, | |
9 | cleanupTests, | |
10 | flushAndRunServer, | |
11 | immutableAssign, | |
12 | makeGetRequest, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers | |
15 | } from '@shared/extra-utils' | |
16 | ||
17 | function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { | |
18 | return server.configCommand.updateCustomSubConfig({ | |
19 | newConfig: { | |
20 | search: { | |
21 | searchIndex: { | |
22 | enabled, | |
23 | disableLocalSearch | |
24 | } | |
25 | } | |
26 | } | |
27 | }) | |
28 | } | |
29 | ||
30 | describe('Test videos API validator', function () { | |
31 | let server: ServerInfo | |
32 | ||
33 | // --------------------------------------------------------------- | |
34 | ||
35 | before(async function () { | |
36 | this.timeout(30000) | |
37 | ||
38 | server = await flushAndRunServer(1) | |
39 | await setAccessTokensToServers([ server ]) | |
40 | }) | |
41 | ||
42 | describe('When searching videos', function () { | |
43 | const path = '/api/v1/search/videos/' | |
44 | ||
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 () { | |
62 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) | |
63 | }) | |
64 | ||
65 | it('Should fail with an invalid category', async function () { | |
66 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) | |
67 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
68 | ||
69 | const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) | |
70 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
71 | }) | |
72 | ||
73 | it('Should succeed with a valid category', async function () { | |
74 | const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) | |
75 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | |
76 | ||
77 | const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) | |
78 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | |
79 | }) | |
80 | ||
81 | it('Should fail with an invalid licence', async function () { | |
82 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) | |
83 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
84 | ||
85 | const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) | |
86 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
87 | }) | |
88 | ||
89 | it('Should succeed with a valid licence', async function () { | |
90 | const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) | |
91 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | |
92 | ||
93 | const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) | |
94 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | |
95 | }) | |
96 | ||
97 | it('Should succeed with a valid language', async function () { | |
98 | const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) | |
99 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | |
100 | ||
101 | const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) | |
102 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | |
103 | }) | |
104 | ||
105 | it('Should succeed with valid tags', async function () { | |
106 | const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) | |
107 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) | |
108 | ||
109 | const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) | |
110 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) | |
111 | ||
112 | const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) | |
113 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) | |
114 | ||
115 | const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) | |
116 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) | |
117 | }) | |
118 | ||
119 | it('Should fail with invalid durations', async function () { | |
120 | const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) | |
121 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
122 | ||
123 | const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) | |
124 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
125 | }) | |
126 | ||
127 | it('Should fail with invalid dates', async function () { | |
128 | const customQuery1 = immutableAssign(query, { startDate: 'hello' }) | |
129 | await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
130 | ||
131 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | |
132 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
133 | ||
134 | const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) | |
135 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
136 | ||
137 | const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) | |
138 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
139 | }) | |
140 | }) | |
141 | ||
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 | ||
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 () { | |
186 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) | |
187 | }) | |
188 | }) | |
189 | ||
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 = [ | |
197 | '/api/v1/search/video-playlists/', | |
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' }) | |
205 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
206 | } | |
207 | ||
208 | { | |
209 | const customQuery = immutableAssign(query, { searchTarget: undefined }) | |
210 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | |
211 | } | |
212 | ||
213 | { | |
214 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | |
215 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | |
216 | } | |
217 | ||
218 | { | |
219 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | |
220 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
221 | } | |
222 | ||
223 | await updateSearchIndex(server, true, true) | |
224 | ||
225 | { | |
226 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | |
227 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) | |
228 | } | |
229 | ||
230 | { | |
231 | const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) | |
232 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | |
233 | } | |
234 | ||
235 | await updateSearchIndex(server, true, false) | |
236 | ||
237 | { | |
238 | const customQuery = immutableAssign(query, { searchTarget: 'local' }) | |
239 | await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) | |
240 | } | |
241 | ||
242 | await updateSearchIndex(server, false, false) | |
243 | } | |
244 | }) | |
245 | }) | |
246 | ||
247 | after(async function () { | |
248 | await cleanupTests([ server ]) | |
249 | }) | |
250 | }) |