1 /* tslint:disable:no-unused-expression */
5 import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils'
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination
10 } from '../../../../shared/utils/requests/check-api-params'
12 describe('Test videos API validator', function () {
13 let server: ServerInfo
15 // ---------------------------------------------------------------
17 before(async function () {
22 server = await runServer(1)
25 describe('When searching videos', function () {
26 const path = '/api/v1/search/videos/'
32 it('Should fail with a bad start pagination', async function () {
33 await checkBadStartPagination(server.url, path, null, query)
36 it('Should fail with a bad count pagination', async function () {
37 await checkBadCountPagination(server.url, path, null, query)
40 it('Should fail with an incorrect sort', async function () {
41 await checkBadSortPagination(server.url, path, null, query)
44 it('Should success with the correct parameters', async function () {
45 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
48 it('Should fail with an invalid category', async function () {
49 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
50 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
52 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
53 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
56 it('Should succeed with a valid category', async function () {
57 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
58 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
60 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
61 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
64 it('Should fail with an invalid licence', async function () {
65 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
66 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
68 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
69 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
72 it('Should succeed with a valid licence', async function () {
73 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
74 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
76 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
77 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
80 it('Should succeed with a valid language', async function () {
81 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
82 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
84 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
85 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
88 it('Should succeed with valid tags', async function () {
89 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
90 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
92 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
93 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
95 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
96 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
98 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
99 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
102 it('Should fail with invalid durations', async function () {
103 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
104 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
106 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
107 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
110 it('Should fail with invalid dates', async function () {
111 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
112 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
114 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
115 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
119 describe('When searching video channels', function () {
120 const path = '/api/v1/search/video-channels/'
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, null, query)
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, null, query)
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, null, query)
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
143 after(async function () {
144 killallServers([ server ])
146 // Keep the logs if the test failed