]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils' | |
6 | import { | |
7 | checkBadCountPagination, | |
8 | checkBadSortPagination, | |
9 | checkBadStartPagination | |
10 | } from '../../../../shared/utils/requests/check-api-params' | |
11 | ||
12 | describe('Test videos API validator', function () { | |
13 | let server: ServerInfo | |
14 | ||
15 | // --------------------------------------------------------------- | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(30000) | |
19 | ||
20 | await flushTests() | |
21 | ||
22 | server = await runServer(1) | |
23 | }) | |
24 | ||
25 | describe('When searching videos', function () { | |
26 | const path = '/api/v1/search/videos/' | |
27 | ||
28 | const query = { | |
29 | search: 'coucou' | |
30 | } | |
31 | ||
32 | it('Should fail with a bad start pagination', async function () { | |
33 | await checkBadStartPagination(server.url, path, null, query) | |
34 | }) | |
35 | ||
36 | it('Should fail with a bad count pagination', async function () { | |
37 | await checkBadCountPagination(server.url, path, null, query) | |
38 | }) | |
39 | ||
40 | it('Should fail with an incorrect sort', async function () { | |
41 | await checkBadSortPagination(server.url, path, null, query) | |
42 | }) | |
43 | ||
44 | it('Should success with the correct parameters', async function () { | |
45 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) | |
46 | }) | |
47 | ||
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 }) | |
51 | ||
52 | const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) | |
53 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
54 | }) | |
55 | ||
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 }) | |
59 | ||
60 | const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) | |
61 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
62 | }) | |
63 | ||
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 }) | |
67 | ||
68 | const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) | |
69 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
70 | }) | |
71 | ||
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 }) | |
75 | ||
76 | const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) | |
77 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
78 | }) | |
79 | ||
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 }) | |
83 | ||
84 | const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) | |
85 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
86 | }) | |
87 | ||
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 }) | |
91 | ||
92 | const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) | |
93 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
94 | ||
95 | const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) | |
96 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) | |
97 | ||
98 | const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) | |
99 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) | |
100 | }) | |
101 | ||
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 }) | |
105 | ||
106 | const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) | |
107 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
108 | }) | |
109 | ||
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 }) | |
113 | ||
114 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | |
115 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
116 | ||
117 | const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) | |
118 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) | |
119 | ||
120 | const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) | |
121 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) | |
122 | }) | |
123 | }) | |
124 | ||
125 | describe('When searching video channels', function () { | |
126 | const path = '/api/v1/search/video-channels/' | |
127 | ||
128 | const query = { | |
129 | search: 'coucou' | |
130 | } | |
131 | ||
132 | it('Should fail with a bad start pagination', async function () { | |
133 | await checkBadStartPagination(server.url, path, null, query) | |
134 | }) | |
135 | ||
136 | it('Should fail with a bad count pagination', async function () { | |
137 | await checkBadCountPagination(server.url, path, null, query) | |
138 | }) | |
139 | ||
140 | it('Should fail with an incorrect sort', async function () { | |
141 | await checkBadSortPagination(server.url, path, null, query) | |
142 | }) | |
143 | ||
144 | it('Should success with the correct parameters', async function () { | |
145 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) | |
146 | }) | |
147 | }) | |
148 | ||
149 | after(async function () { | |
150 | killallServers([ server ]) | |
151 | ||
152 | // Keep the logs if the test failed | |
153 | if (this['ok']) { | |
154 | await flushTests() | |
155 | } | |
156 | }) | |
157 | }) |