]>
Commit | Line | Data |
---|---|---|
d525fc39 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | ||
7c3b7976 | 5 | import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils' |
9639bd17 | 6 | import { |
7 | checkBadCountPagination, | |
8 | checkBadSortPagination, | |
9 | checkBadStartPagination | |
94565d52 | 10 | } from '../../../../shared/extra-utils/requests/check-api-params' |
d525fc39 C |
11 | |
12 | describe('Test videos API validator', function () { | |
d525fc39 C |
13 | let server: ServerInfo |
14 | ||
15 | // --------------------------------------------------------------- | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(30000) | |
19 | ||
210feb6c | 20 | server = await flushAndRunServer(1) |
d525fc39 C |
21 | }) |
22 | ||
23 | describe('When searching videos', function () { | |
f5b0af50 C |
24 | const path = '/api/v1/search/videos/' |
25 | ||
d525fc39 C |
26 | const query = { |
27 | search: 'coucou' | |
28 | } | |
29 | ||
30 | it('Should fail with a bad start pagination', async function () { | |
31 | await checkBadStartPagination(server.url, path, null, query) | |
32 | }) | |
33 | ||
34 | it('Should fail with a bad count pagination', async function () { | |
35 | await checkBadCountPagination(server.url, path, null, query) | |
36 | }) | |
37 | ||
38 | it('Should fail with an incorrect sort', async function () { | |
39 | await checkBadSortPagination(server.url, path, null, query) | |
40 | }) | |
41 | ||
42 | it('Should success with the correct parameters', async function () { | |
43 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) | |
44 | }) | |
45 | ||
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 }) | |
49 | ||
50 | const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) | |
51 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
52 | }) | |
53 | ||
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 }) | |
57 | ||
58 | const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) | |
59 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
60 | }) | |
61 | ||
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 }) | |
65 | ||
66 | const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) | |
67 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
68 | }) | |
69 | ||
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 }) | |
73 | ||
74 | const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) | |
75 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
76 | }) | |
77 | ||
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 }) | |
81 | ||
82 | const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) | |
83 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
84 | }) | |
85 | ||
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 }) | |
89 | ||
90 | const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) | |
91 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) | |
92 | ||
93 | const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) | |
94 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) | |
95 | ||
96 | const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) | |
97 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) | |
98 | }) | |
99 | ||
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 }) | |
103 | ||
104 | const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) | |
105 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
106 | }) | |
107 | ||
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 }) | |
111 | ||
112 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | |
113 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | |
31d065cc AM |
114 | |
115 | const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) | |
116 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) | |
117 | ||
118 | const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) | |
119 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) | |
d525fc39 C |
120 | }) |
121 | }) | |
122 | ||
f5b0af50 C |
123 | describe('When searching video channels', function () { |
124 | const path = '/api/v1/search/video-channels/' | |
125 | ||
126 | const query = { | |
127 | search: 'coucou' | |
128 | } | |
129 | ||
130 | it('Should fail with a bad start pagination', async function () { | |
131 | await checkBadStartPagination(server.url, path, null, query) | |
132 | }) | |
133 | ||
134 | it('Should fail with a bad count pagination', async function () { | |
135 | await checkBadCountPagination(server.url, path, null, query) | |
136 | }) | |
137 | ||
138 | it('Should fail with an incorrect sort', async function () { | |
139 | await checkBadSortPagination(server.url, path, null, query) | |
140 | }) | |
141 | ||
142 | it('Should success with the correct parameters', async function () { | |
143 | await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) | |
144 | }) | |
145 | }) | |
146 | ||
7c3b7976 C |
147 | after(async function () { |
148 | await cleanupTests([ server ]) | |
d525fc39 C |
149 | }) |
150 | }) |