1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils'
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination
10 } from '../../../../shared/extra-utils/requests/check-api-params'
12 describe('Test videos API validator', function () {
13 let server: ServerInfo
15 // ---------------------------------------------------------------
17 before(async function () {
20 server = await flushAndRunServer(1)
23 describe('When searching videos', function () {
24 const path = '/api/v1/search/videos/'
30 it('Should fail with a bad start pagination', async function () {
31 await checkBadStartPagination(server.url, path, null, query)
34 it('Should fail with a bad count pagination', async function () {
35 await checkBadCountPagination(server.url, path, null, query)
38 it('Should fail with an incorrect sort', async function () {
39 await checkBadSortPagination(server.url, path, null, query)
42 it('Should success with the correct parameters', async function () {
43 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
46 it('Should fail with an invalid category', async function () {
47 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
48 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
50 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
51 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
54 it('Should succeed with a valid category', async function () {
55 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
56 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
58 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
59 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
62 it('Should fail with an invalid licence', async function () {
63 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
64 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
66 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
67 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
70 it('Should succeed with a valid licence', async function () {
71 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
72 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
74 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
75 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
78 it('Should succeed with a valid language', async function () {
79 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
80 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
82 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
83 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
86 it('Should succeed with valid tags', async function () {
87 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
88 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
90 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
91 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
93 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
94 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
96 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
97 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
100 it('Should fail with invalid durations', async function () {
101 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
102 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
104 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
105 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
108 it('Should fail with invalid dates', async function () {
109 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
110 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
112 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
113 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
115 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
116 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
118 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
119 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
123 describe('When searching video channels', function () {
124 const path = '/api/v1/search/video-channels/'
130 it('Should fail with a bad start pagination', async function () {
131 await checkBadStartPagination(server.url, path, null, query)
134 it('Should fail with a bad count pagination', async function () {
135 await checkBadCountPagination(server.url, path, null, query)
138 it('Should fail with an incorrect sort', async function () {
139 await checkBadSortPagination(server.url, path, null, query)
142 it('Should success with the correct parameters', async function () {
143 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
147 after(async function () {
148 await cleanupTests([ server ])