1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 updateCustomSubConfig,
11 setAccessTokensToServers
12 } from '../../../../shared/extra-utils'
14 checkBadCountPagination,
15 checkBadSortPagination,
16 checkBadStartPagination
17 } from '../../../../shared/extra-utils/requests/check-api-params'
18 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
20 function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
21 return updateCustomSubConfig(server.url, server.accessToken, {
31 describe('Test videos API validator', function () {
32 let server: ServerInfo
34 // ---------------------------------------------------------------
36 before(async function () {
39 server = await flushAndRunServer(1)
40 await setAccessTokensToServers([ server ])
43 describe('When searching videos', function () {
44 const path = '/api/v1/search/videos/'
50 it('Should fail with a bad start pagination', async function () {
51 await checkBadStartPagination(server.url, path, null, query)
54 it('Should fail with a bad count pagination', async function () {
55 await checkBadCountPagination(server.url, path, null, query)
58 it('Should fail with an incorrect sort', async function () {
59 await checkBadSortPagination(server.url, path, null, query)
62 it('Should success with the correct parameters', async function () {
63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
66 it('Should fail with an invalid category', async function () {
67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
74 it('Should succeed with a valid category', async function () {
75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
82 it('Should fail with an invalid licence', async function () {
83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
90 it('Should succeed with a valid licence', async function () {
91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
98 it('Should succeed with a valid language', async function () {
99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
106 it('Should succeed with valid tags', async function () {
107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
120 it('Should fail with invalid durations', async function () {
121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
128 it('Should fail with invalid dates', async function () {
129 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
132 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
143 describe('When searching video playlists', function () {
144 const path = '/api/v1/search/video-playlists/'
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, null, query)
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, null, query)
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, null, query)
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
167 describe('When searching video channels', function () {
168 const path = '/api/v1/search/video-channels/'
174 it('Should fail with a bad start pagination', async function () {
175 await checkBadStartPagination(server.url, path, null, query)
178 it('Should fail with a bad count pagination', async function () {
179 await checkBadCountPagination(server.url, path, null, query)
182 it('Should fail with an incorrect sort', async function () {
183 await checkBadSortPagination(server.url, path, null, query)
186 it('Should success with the correct parameters', async function () {
187 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
191 describe('Search target', function () {
193 it('Should fail/succeed depending on the search target', async function () {
196 const query = { search: 'coucou' }
198 '/api/v1/search/video-playlists/',
199 '/api/v1/search/video-channels/',
200 '/api/v1/search/videos/'
203 for (const path of paths) {
205 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
206 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
210 const customQuery = immutableAssign(query, { searchTarget: undefined })
211 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
215 const customQuery = immutableAssign(query, { searchTarget: 'local' })
216 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
220 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
221 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
224 await updateSearchIndex(server, true, true)
227 const customQuery = immutableAssign(query, { searchTarget: 'local' })
228 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
232 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
233 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
236 await updateSearchIndex(server, true, false)
239 const customQuery = immutableAssign(query, { searchTarget: 'local' })
240 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
243 await updateSearchIndex(server, false, false)
248 after(async function () {
249 await cleanupTests([ server ])