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