1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
14 setAccessTokensToServers
15 } from '@shared/extra-utils'
17 function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
18 return server.configCommand.updateCustomSubConfig({
30 describe('Test videos API validator', function () {
31 let server: ServerInfo
33 // ---------------------------------------------------------------
35 before(async function () {
38 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
42 describe('When searching videos', function () {
43 const path = '/api/v1/search/videos/'
49 it('Should fail with a bad start pagination', async function () {
50 await checkBadStartPagination(server.url, path, null, query)
53 it('Should fail with a bad count pagination', async function () {
54 await checkBadCountPagination(server.url, path, null, query)
57 it('Should fail with an incorrect sort', async function () {
58 await checkBadSortPagination(server.url, path, null, query)
61 it('Should success with the correct parameters', async function () {
62 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
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 })
69 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
70 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
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 })
77 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
78 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
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 })
85 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
86 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
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 })
93 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
94 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
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 })
101 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
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 })
109 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
112 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
113 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
115 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
116 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
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 })
123 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
124 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
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 })
131 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
132 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
134 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
135 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
137 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
138 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
142 describe('When searching video playlists', function () {
143 const path = '/api/v1/search/video-playlists/'
149 it('Should fail with a bad start pagination', async function () {
150 await checkBadStartPagination(server.url, path, null, query)
153 it('Should fail with a bad count pagination', async function () {
154 await checkBadCountPagination(server.url, path, null, query)
157 it('Should fail with an incorrect sort', async function () {
158 await checkBadSortPagination(server.url, path, null, query)
161 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
166 describe('When searching video channels', function () {
167 const path = '/api/v1/search/video-channels/'
173 it('Should fail with a bad start pagination', async function () {
174 await checkBadStartPagination(server.url, path, null, query)
177 it('Should fail with a bad count pagination', async function () {
178 await checkBadCountPagination(server.url, path, null, query)
181 it('Should fail with an incorrect sort', async function () {
182 await checkBadSortPagination(server.url, path, null, query)
185 it('Should success with the correct parameters', async function () {
186 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
190 describe('Search target', function () {
192 it('Should fail/succeed depending on the search target', async function () {
195 const query = { search: 'coucou' }
197 '/api/v1/search/video-playlists/',
198 '/api/v1/search/video-channels/',
199 '/api/v1/search/videos/'
202 for (const path of paths) {
204 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
205 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
209 const customQuery = immutableAssign(query, { searchTarget: undefined })
210 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
214 const customQuery = immutableAssign(query, { searchTarget: 'local' })
215 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
219 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
220 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
223 await updateSearchIndex(server, true, true)
226 const customQuery = immutableAssign(query, { searchTarget: 'local' })
227 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
231 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
232 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
235 await updateSearchIndex(server, true, false)
238 const customQuery = immutableAssign(query, { searchTarget: 'local' })
239 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
242 await updateSearchIndex(server, false, false)
247 after(async function () {
248 await cleanupTests([ server ])