]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import { omit } from 'lodash' | |
5 | import 'mocha' | |
6 | import { | |
7 | createUser, | |
8 | deleteVideoChannel, | |
9 | flushTests, | |
10 | getAccountVideoChannelsList, | |
11 | getMyUserInformation, | |
12 | getVideoChannelsList, | |
13 | immutableAssign, | |
14 | killallServers, | |
15 | makeGetRequest, | |
16 | makePostBodyRequest, | |
17 | makePutBodyRequest, | |
18 | makeUploadRequest, | |
19 | runServer, | |
20 | ServerInfo, | |
21 | setAccessTokensToServers, | |
22 | userLogin | |
23 | } from '../../../../shared/utils' | |
24 | import { | |
25 | checkBadCountPagination, | |
26 | checkBadSortPagination, | |
27 | checkBadStartPagination | |
28 | } from '../../../../shared/utils/requests/check-api-params' | |
29 | import { User } from '../../../../shared/models/users' | |
30 | import { join } from 'path' | |
31 | ||
32 | const expect = chai.expect | |
33 | ||
34 | describe('Test video channels API validator', function () { | |
35 | const videoChannelPath = '/api/v1/video-channels' | |
36 | let server: ServerInfo | |
37 | let accessTokenUser: string | |
38 | ||
39 | // --------------------------------------------------------------- | |
40 | ||
41 | before(async function () { | |
42 | this.timeout(30000) | |
43 | ||
44 | await flushTests() | |
45 | ||
46 | server = await runServer(1) | |
47 | ||
48 | await setAccessTokensToServers([ server ]) | |
49 | ||
50 | const user = { | |
51 | username: 'fake', | |
52 | password: 'fake_password' | |
53 | } | |
54 | ||
55 | { | |
56 | await createUser(server.url, server.accessToken, user.username, user.password) | |
57 | accessTokenUser = await userLogin(server, user) | |
58 | } | |
59 | }) | |
60 | ||
61 | describe('When listing a video channels', function () { | |
62 | it('Should fail with a bad start pagination', async function () { | |
63 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) | |
64 | }) | |
65 | ||
66 | it('Should fail with a bad count pagination', async function () { | |
67 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) | |
68 | }) | |
69 | ||
70 | it('Should fail with an incorrect sort', async function () { | |
71 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) | |
72 | }) | |
73 | }) | |
74 | ||
75 | describe('When listing account video channels', function () { | |
76 | it('Should fail with a unknown account', async function () { | |
77 | await getAccountVideoChannelsList(server.url, 'unknown', 404) | |
78 | }) | |
79 | }) | |
80 | ||
81 | describe('When adding a video channel', function () { | |
82 | const baseCorrectParams = { | |
83 | name: 'super_channel', | |
84 | displayName: 'hello', | |
85 | description: 'super description', | |
86 | support: 'super support text' | |
87 | } | |
88 | ||
89 | it('Should fail with a non authenticated user', async function () { | |
90 | await makePostBodyRequest({ | |
91 | url: server.url, | |
92 | path: videoChannelPath, | |
93 | token: 'none', | |
94 | fields: baseCorrectParams, | |
95 | statusCodeExpected: 401 | |
96 | }) | |
97 | }) | |
98 | ||
99 | it('Should fail with nothing', async function () { | |
100 | const fields = {} | |
101 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
102 | }) | |
103 | ||
104 | it('Should fail without a name', async function () { | |
105 | const fields = omit(baseCorrectParams, 'name') | |
106 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
107 | }) | |
108 | ||
109 | it('Should fail with a bad name', async function () { | |
110 | const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) | |
111 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
112 | }) | |
113 | ||
114 | it('Should fail without a name', async function () { | |
115 | const fields = omit(baseCorrectParams, 'displayName') | |
116 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
117 | }) | |
118 | ||
119 | it('Should fail with a long name', async function () { | |
120 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) | |
121 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
122 | }) | |
123 | ||
124 | it('Should fail with a long description', async function () { | |
125 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) | |
126 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
127 | }) | |
128 | ||
129 | it('Should fail with a long support text', async function () { | |
130 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
131 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
132 | }) | |
133 | ||
134 | it('Should succeed with the correct parameters', async function () { | |
135 | await makePostBodyRequest({ | |
136 | url: server.url, | |
137 | path: videoChannelPath, | |
138 | token: server.accessToken, | |
139 | fields: baseCorrectParams, | |
140 | statusCodeExpected: 200 | |
141 | }) | |
142 | }) | |
143 | ||
144 | it('Should fail when adding a channel with the same username', async function () { | |
145 | await makePostBodyRequest({ | |
146 | url: server.url, | |
147 | path: videoChannelPath, | |
148 | token: server.accessToken, | |
149 | fields: baseCorrectParams, | |
150 | statusCodeExpected: 409 | |
151 | }) | |
152 | }) | |
153 | }) | |
154 | ||
155 | describe('When updating a video channel', function () { | |
156 | const baseCorrectParams = { | |
157 | displayName: 'hello', | |
158 | description: 'super description' | |
159 | } | |
160 | let path: string | |
161 | ||
162 | before(async function () { | |
163 | path = videoChannelPath + '/super_channel' | |
164 | }) | |
165 | ||
166 | it('Should fail with a non authenticated user', async function () { | |
167 | await makePutBodyRequest({ | |
168 | url: server.url, | |
169 | path, | |
170 | token: 'hi', | |
171 | fields: baseCorrectParams, | |
172 | statusCodeExpected: 401 | |
173 | }) | |
174 | }) | |
175 | ||
176 | it('Should fail with another authenticated user', async function () { | |
177 | await makePutBodyRequest({ | |
178 | url: server.url, | |
179 | path, | |
180 | token: accessTokenUser, | |
181 | fields: baseCorrectParams, | |
182 | statusCodeExpected: 403 | |
183 | }) | |
184 | }) | |
185 | ||
186 | it('Should fail with a long name', async function () { | |
187 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) | |
188 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
189 | }) | |
190 | ||
191 | it('Should fail with a long description', async function () { | |
192 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) | |
193 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
194 | }) | |
195 | ||
196 | it('Should fail with a long support text', async function () { | |
197 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
198 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
199 | }) | |
200 | ||
201 | it('Should succeed with the correct parameters', async function () { | |
202 | await makePutBodyRequest({ | |
203 | url: server.url, | |
204 | path, | |
205 | token: server.accessToken, | |
206 | fields: baseCorrectParams, | |
207 | statusCodeExpected: 204 | |
208 | }) | |
209 | }) | |
210 | }) | |
211 | ||
212 | describe('When updating video channel avatar', function () { | |
213 | let path: string | |
214 | ||
215 | before(async function () { | |
216 | path = videoChannelPath + '/super_channel' | |
217 | }) | |
218 | ||
219 | it('Should fail with an incorrect input file', async function () { | |
220 | const fields = {} | |
221 | const attaches = { | |
222 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') | |
223 | } | |
224 | await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) | |
225 | }) | |
226 | ||
227 | it('Should fail with a big file', async function () { | |
228 | const fields = {} | |
229 | const attaches = { | |
230 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
231 | } | |
232 | await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) | |
233 | }) | |
234 | ||
235 | it('Should fail with an unauthenticated user', async function () { | |
236 | const fields = {} | |
237 | const attaches = { | |
238 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
239 | } | |
240 | await makeUploadRequest({ | |
241 | url: server.url, | |
242 | path: path + '/avatar/pick', | |
243 | fields, | |
244 | attaches, | |
245 | statusCodeExpected: 401 | |
246 | }) | |
247 | }) | |
248 | ||
249 | it('Should succeed with the correct params', async function () { | |
250 | const fields = {} | |
251 | const attaches = { | |
252 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
253 | } | |
254 | await makeUploadRequest({ | |
255 | url: server.url, | |
256 | path: path + '/avatar/pick', | |
257 | token: server.accessToken, | |
258 | fields, | |
259 | attaches, | |
260 | statusCodeExpected: 200 | |
261 | }) | |
262 | }) | |
263 | }) | |
264 | ||
265 | describe('When getting a video channel', function () { | |
266 | it('Should return the list of the video channels with nothing', async function () { | |
267 | const res = await makeGetRequest({ | |
268 | url: server.url, | |
269 | path: videoChannelPath, | |
270 | statusCodeExpected: 200 | |
271 | }) | |
272 | ||
273 | expect(res.body.data).to.be.an('array') | |
274 | }) | |
275 | ||
276 | it('Should return 404 with an incorrect video channel', async function () { | |
277 | await makeGetRequest({ | |
278 | url: server.url, | |
279 | path: videoChannelPath + '/super_channel2', | |
280 | statusCodeExpected: 404 | |
281 | }) | |
282 | }) | |
283 | ||
284 | it('Should succeed with the correct parameters', async function () { | |
285 | await makeGetRequest({ | |
286 | url: server.url, | |
287 | path: videoChannelPath + '/super_channel', | |
288 | statusCodeExpected: 200 | |
289 | }) | |
290 | }) | |
291 | }) | |
292 | ||
293 | describe('When deleting a video channel', function () { | |
294 | it('Should fail with a non authenticated user', async function () { | |
295 | await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401) | |
296 | }) | |
297 | ||
298 | it('Should fail with another authenticated user', async function () { | |
299 | await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403) | |
300 | }) | |
301 | ||
302 | it('Should fail with an unknown video channel id', async function () { | |
303 | await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404) | |
304 | }) | |
305 | ||
306 | it('Should succeed with the correct parameters', async function () { | |
307 | await deleteVideoChannel(server.url, server.accessToken, 'super_channel') | |
308 | }) | |
309 | ||
310 | it('Should fail to delete the last user video channel', async function () { | |
311 | await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409) | |
312 | }) | |
313 | }) | |
314 | ||
315 | after(async function () { | |
316 | killallServers([ server ]) | |
317 | ||
318 | // Keep the logs if the test failed | |
319 | if (this['ok']) { | |
320 | await flushTests() | |
321 | } | |
322 | }) | |
323 | }) |