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 () {
9 const path = '/api/v1/search/videos/'
10 let server: ServerInfo
12 // ---------------------------------------------------------------
14 before(async function () {
19 server = await runServer(1)
22 describe('When searching videos', function () {
27 it('Should fail with a bad start pagination', async function () {
28 await checkBadStartPagination(server.url, path, null, query)
31 it('Should fail with a bad count pagination', async function () {
32 await checkBadCountPagination(server.url, path, null, query)
35 it('Should fail with an incorrect sort', async function () {
36 await checkBadSortPagination(server.url, path, null, query)
39 it('Should success with the correct parameters', async function () {
40 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
43 it('Should fail with an invalid category', async function () {
44 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
45 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
47 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
48 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
51 it('Should succeed with a valid category', async function () {
52 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
53 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
55 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
56 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
59 it('Should fail with an invalid licence', async function () {
60 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
61 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
63 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
64 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
67 it('Should succeed with a valid licence', async function () {
68 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
69 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
71 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
72 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
75 it('Should succeed with a valid language', async function () {
76 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
77 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
79 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
80 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
83 it('Should succeed with valid tags', async function () {
84 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
85 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
87 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
88 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
90 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
91 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
93 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
94 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
97 it('Should fail with invalid durations', async function () {
98 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
101 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
105 it('Should fail with invalid dates', async function () {
106 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
109 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
114 after(async function () {
115 killallServers([ server ])
117 // Keep the logs if the test failed