1 /* tslint:disable:no-unused-expression */
5 import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils'
6 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
8 describe('Test videos API validator', function () {
11 // ---------------------------------------------------------------
13 before(async function () {
18 server = await runServer(1)
21 describe('When searching videos', function () {
22 const path = '/api/v1/search/videos/'
28 it('Should fail with a bad start pagination', async function () {
29 await checkBadStartPagination(server.url, path, null, query)
32 it('Should fail with a bad count pagination', async function () {
33 await checkBadCountPagination(server.url, path, null, query)
36 it('Should fail with an incorrect sort', async function () {
37 await checkBadSortPagination(server.url, path, null, query)
40 it('Should success with the correct parameters', async function () {
41 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
44 it('Should fail with an invalid category', async function () {
45 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
46 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
48 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
49 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
52 it('Should succeed with a valid category', async function () {
53 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
54 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
56 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
57 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
60 it('Should fail with an invalid licence', async function () {
61 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
62 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
64 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
65 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
68 it('Should succeed with a valid licence', async function () {
69 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
70 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
72 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
73 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
76 it('Should succeed with a valid language', async function () {
77 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
78 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
80 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
81 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
84 it('Should succeed with valid tags', async function () {
85 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
86 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
88 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
89 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
91 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
92 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
94 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
95 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
98 it('Should fail with invalid durations', async function () {
99 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
102 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
106 it('Should fail with invalid dates', async function () {
107 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
110 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
115 describe('When searching video channels', function () {
116 const path = '/api/v1/search/video-channels/'
122 it('Should fail with a bad start pagination', async function () {
123 await checkBadStartPagination(server.url, path, null, query)
126 it('Should fail with a bad count pagination', async function () {
127 await checkBadCountPagination(server.url, path, null, query)
130 it('Should fail with an incorrect sort', async function () {
131 await checkBadSortPagination(server.url, path, null, query)
134 it('Should success with the correct parameters', async function () {
135 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
139 after(async function () {
140 killallServers([ server ])
142 // Keep the logs if the test failed