]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
34ca3b52 | 2 | |
f0f5567b C |
3 | const chai = require('chai') |
4 | const expect = chai.expect | |
5 | const pathUtils = require('path') | |
6 | const request = require('supertest') | |
1a42c9e2 | 7 | const series = require('async/series') |
34ca3b52 | 8 | |
8d309058 | 9 | const loginUtils = require('../utils/login') |
25ed57f3 | 10 | const requestsUtils = require('../utils/requests') |
8d309058 C |
11 | const serversUtils = require('../utils/servers') |
12 | const usersUtils = require('../utils/users') | |
7b1f49de | 13 | const videosUtils = require('../utils/videos') |
34ca3b52 | 14 | |
9f10b292 | 15 | describe('Test parameters validator', function () { |
0c1cbbfe | 16 | let server = null |
d3cd34be | 17 | let userAccessToken = null |
34ca3b52 | 18 | |
9f10b292 C |
19 | // --------------------------------------------------------------- |
20 | ||
21 | before(function (done) { | |
22 | this.timeout(20000) | |
23 | ||
1a42c9e2 | 24 | series([ |
9f10b292 | 25 | function (next) { |
8d309058 | 26 | serversUtils.flushTests(next) |
9f10b292 C |
27 | }, |
28 | function (next) { | |
8d309058 | 29 | serversUtils.runServer(1, function (server1) { |
0c1cbbfe C |
30 | server = server1 |
31 | ||
32 | next() | |
33 | }) | |
34 | }, | |
35 | function (next) { | |
8d309058 | 36 | loginUtils.loginAndGetAccessToken(server, function (err, token) { |
0c1cbbfe | 37 | if (err) throw err |
b6c6f935 | 38 | server.accessToken = token |
0c1cbbfe | 39 | |
9f10b292 | 40 | next() |
34ca3b52 | 41 | }) |
9f10b292 C |
42 | } |
43 | ], done) | |
44 | }) | |
45 | ||
46 | describe('Of the pods API', function () { | |
f0f5567b | 47 | const path = '/api/v1/pods/' |
9f10b292 | 48 | |
d57d6f26 | 49 | describe('When making friends', function () { |
9bd26629 C |
50 | let userAccessToken = null |
51 | ||
52 | before(function (done) { | |
8d309058 | 53 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { |
9bd26629 C |
54 | server.user = { |
55 | username: 'user1', | |
56 | password: 'password' | |
57 | } | |
58 | ||
8d309058 | 59 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
9bd26629 C |
60 | if (err) throw err |
61 | ||
62 | userAccessToken = accessToken | |
63 | ||
64 | done() | |
65 | }) | |
66 | }) | |
67 | }) | |
68 | ||
69 | describe('When making friends', function () { | |
1e2564d3 | 70 | const body = { |
a4254ea1 | 71 | hosts: [ 'localhost:9002' ] |
1e2564d3 C |
72 | } |
73 | ||
a4254ea1 | 74 | it('Should fail without hosts', function (done) { |
1e2564d3 C |
75 | request(server.url) |
76 | .post(path + '/makefriends') | |
d57d6f26 | 77 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 78 | .set('Accept', 'application/json') |
d57d6f26 | 79 | .expect(400, done) |
1e2564d3 C |
80 | }) |
81 | ||
a4254ea1 | 82 | it('Should fail if hosts is not an array', function (done) { |
1e2564d3 C |
83 | request(server.url) |
84 | .post(path + '/makefriends') | |
a4254ea1 | 85 | .send({ hosts: 'localhost:9002' }) |
d57d6f26 | 86 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 87 | .set('Accept', 'application/json') |
d57d6f26 | 88 | .expect(400, done) |
1e2564d3 C |
89 | }) |
90 | ||
a4254ea1 | 91 | it('Should fail if the array is not composed by hosts', function (done) { |
1e2564d3 C |
92 | request(server.url) |
93 | .post(path + '/makefriends') | |
a4254ea1 | 94 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) |
d57d6f26 | 95 | .set('Authorization', 'Bearer ' + server.accessToken) |
1e2564d3 | 96 | .set('Accept', 'application/json') |
d57d6f26 C |
97 | .expect(400, done) |
98 | }) | |
99 | ||
a4254ea1 | 100 | it('Should fail if the array is composed with http schemes', function (done) { |
d57d6f26 C |
101 | request(server.url) |
102 | .post(path + '/makefriends') | |
a4254ea1 C |
103 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) |
104 | .set('Authorization', 'Bearer ' + server.accessToken) | |
105 | .set('Accept', 'application/json') | |
106 | .expect(400, done) | |
107 | }) | |
108 | ||
109 | it('Should fail if hosts are not unique', function (done) { | |
110 | request(server.url) | |
111 | .post(path + '/makefriends') | |
112 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | |
d57d6f26 C |
113 | .set('Authorization', 'Bearer ' + server.accessToken) |
114 | .set('Accept', 'application/json') | |
115 | .expect(400, done) | |
1e2564d3 C |
116 | }) |
117 | ||
9bd26629 C |
118 | it('Should fail with a invalid token', function (done) { |
119 | request(server.url) | |
1e2564d3 C |
120 | .post(path + '/makefriends') |
121 | .send(body) | |
9bd26629 C |
122 | .set('Authorization', 'Bearer faketoken') |
123 | .set('Accept', 'application/json') | |
124 | .expect(401, done) | |
125 | }) | |
126 | ||
127 | it('Should fail if the user is not an administrator', function (done) { | |
128 | request(server.url) | |
1e2564d3 C |
129 | .post(path + '/makefriends') |
130 | .send(body) | |
9bd26629 C |
131 | .set('Authorization', 'Bearer ' + userAccessToken) |
132 | .set('Accept', 'application/json') | |
133 | .expect(403, done) | |
134 | }) | |
135 | }) | |
136 | ||
137 | describe('When quitting friends', function () { | |
138 | it('Should fail with a invalid token', function (done) { | |
139 | request(server.url) | |
140 | .get(path + '/quitfriends') | |
141 | .query({ start: 'hello' }) | |
142 | .set('Authorization', 'Bearer faketoken') | |
143 | .set('Accept', 'application/json') | |
144 | .expect(401, done) | |
145 | }) | |
146 | ||
147 | it('Should fail if the user is not an administrator', function (done) { | |
148 | request(server.url) | |
149 | .get(path + '/quitfriends') | |
150 | .query({ start: 'hello' }) | |
151 | .set('Authorization', 'Bearer ' + userAccessToken) | |
152 | .set('Accept', 'application/json') | |
153 | .expect(403, done) | |
154 | }) | |
34ca3b52 C |
155 | }) |
156 | }) | |
d57d6f26 C |
157 | |
158 | describe('When adding a pod', function () { | |
159 | it('Should fail with nothing', function (done) { | |
160 | const data = {} | |
161 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
162 | }) | |
163 | ||
164 | it('Should fail without public key', function (done) { | |
165 | const data = { | |
a4254ea1 | 166 | host: 'coucou.com' |
d57d6f26 C |
167 | } |
168 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
169 | }) | |
170 | ||
a4254ea1 | 171 | it('Should fail without an host', function (done) { |
d57d6f26 C |
172 | const data = { |
173 | publicKey: 'mysuperpublickey' | |
174 | } | |
175 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | |
176 | }) | |
177 | ||
a4254ea1 | 178 | it('Should fail with an incorrect host', function (done) { |
d57d6f26 | 179 | const data = { |
a4254ea1 | 180 | host: 'http://coucou.com', |
d57d6f26 C |
181 | publicKey: 'mysuperpublickey' |
182 | } | |
183 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | |
a4254ea1 | 184 | data.host = 'http://coucou' |
d57d6f26 | 185 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { |
a4254ea1 | 186 | data.host = 'coucou' |
d57d6f26 C |
187 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) |
188 | }) | |
189 | }) | |
190 | }) | |
191 | ||
192 | it('Should succeed with the correct parameters', function (done) { | |
193 | const data = { | |
a4254ea1 | 194 | host: 'coucou.com', |
d57d6f26 C |
195 | publicKey: 'mysuperpublickey' |
196 | } | |
197 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | |
198 | }) | |
199 | }) | |
9f10b292 | 200 | }) |
34ca3b52 | 201 | |
9f10b292 | 202 | describe('Of the videos API', function () { |
f0f5567b | 203 | const path = '/api/v1/videos/' |
34ca3b52 | 204 | |
a877d5ac C |
205 | describe('When listing a video', function () { |
206 | it('Should fail with a bad start pagination', function (done) { | |
207 | request(server.url) | |
208 | .get(path) | |
209 | .query({ start: 'hello' }) | |
210 | .set('Accept', 'application/json') | |
211 | .expect(400, done) | |
212 | }) | |
213 | ||
214 | it('Should fail with a bad count pagination', function (done) { | |
215 | request(server.url) | |
216 | .get(path) | |
217 | .query({ count: 'hello' }) | |
218 | .set('Accept', 'application/json') | |
219 | .expect(400, done) | |
220 | }) | |
221 | ||
222 | it('Should fail with an incorrect sort', function (done) { | |
223 | request(server.url) | |
224 | .get(path) | |
225 | .query({ sort: 'hello' }) | |
226 | .set('Accept', 'application/json') | |
227 | .expect(400, done) | |
228 | }) | |
229 | }) | |
230 | ||
9f10b292 C |
231 | describe('When searching a video', function () { |
232 | it('Should fail with nothing', function (done) { | |
0c1cbbfe | 233 | request(server.url) |
9f10b292 C |
234 | .get(pathUtils.join(path, 'search')) |
235 | .set('Accept', 'application/json') | |
236 | .expect(400, done) | |
34ca3b52 | 237 | }) |
a877d5ac C |
238 | |
239 | it('Should fail with a bad start pagination', function (done) { | |
240 | request(server.url) | |
241 | .get(pathUtils.join(path, 'search', 'test')) | |
242 | .query({ start: 'hello' }) | |
243 | .set('Accept', 'application/json') | |
244 | .expect(400, done) | |
245 | }) | |
246 | ||
247 | it('Should fail with a bad count pagination', function (done) { | |
248 | request(server.url) | |
249 | .get(pathUtils.join(path, 'search', 'test')) | |
250 | .query({ count: 'hello' }) | |
251 | .set('Accept', 'application/json') | |
252 | .expect(400, done) | |
253 | }) | |
254 | ||
255 | it('Should fail with an incorrect sort', function (done) { | |
256 | request(server.url) | |
257 | .get(pathUtils.join(path, 'search', 'test')) | |
258 | .query({ sort: 'hello' }) | |
259 | .set('Accept', 'application/json') | |
260 | .expect(400, done) | |
261 | }) | |
9f10b292 | 262 | }) |
34ca3b52 | 263 | |
9f10b292 C |
264 | describe('When adding a video', function () { |
265 | it('Should fail with nothing', function (done) { | |
f0f5567b C |
266 | const data = {} |
267 | const attach = {} | |
25ed57f3 | 268 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 269 | }) |
34ca3b52 | 270 | |
9f10b292 | 271 | it('Should fail without name', function (done) { |
f0f5567b | 272 | const data = { |
be587647 C |
273 | description: 'my super description', |
274 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 275 | } |
f0f5567b | 276 | const attach = { |
8c9c1942 | 277 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 278 | } |
25ed57f3 | 279 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 280 | }) |
34ca3b52 | 281 | |
9f10b292 | 282 | it('Should fail with a long name', function (done) { |
f0f5567b | 283 | const data = { |
9f10b292 | 284 | name: 'My very very very very very very very very very very very very very very very very long name', |
be587647 C |
285 | description: 'my super description', |
286 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 287 | } |
f0f5567b | 288 | const attach = { |
8c9c1942 | 289 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 290 | } |
25ed57f3 | 291 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 292 | }) |
34ca3b52 | 293 | |
9f10b292 | 294 | it('Should fail without description', function (done) { |
f0f5567b | 295 | const data = { |
be587647 C |
296 | name: 'my super name', |
297 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 298 | } |
f0f5567b | 299 | const attach = { |
8c9c1942 | 300 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 301 | } |
25ed57f3 | 302 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 303 | }) |
34ca3b52 | 304 | |
9f10b292 | 305 | it('Should fail with a long description', function (done) { |
f0f5567b | 306 | const data = { |
9f10b292 C |
307 | name: 'my super name', |
308 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
309 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
be587647 C |
310 | 'very very very very very very very very very very very very very very very long', |
311 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 312 | } |
f0f5567b | 313 | const attach = { |
8c9c1942 | 314 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 315 | } |
25ed57f3 | 316 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 317 | }) |
34ca3b52 | 318 | |
be587647 | 319 | it('Should fail without tags', function (done) { |
f0f5567b | 320 | const data = { |
9f10b292 C |
321 | name: 'my super name', |
322 | description: 'my super description' | |
323 | } | |
be587647 C |
324 | const attach = { |
325 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
326 | } | |
25ed57f3 | 327 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
328 | }) |
329 | ||
330 | it('Should fail with too many tags', function (done) { | |
331 | const data = { | |
332 | name: 'my super name', | |
333 | description: 'my super description', | |
334 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
335 | } | |
336 | const attach = { | |
337 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
338 | } | |
25ed57f3 | 339 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
340 | }) |
341 | ||
342 | it('Should fail with not enough tags', function (done) { | |
343 | const data = { | |
344 | name: 'my super name', | |
345 | description: 'my super description', | |
346 | tags: [ ] | |
347 | } | |
348 | const attach = { | |
349 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
350 | } | |
25ed57f3 | 351 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
352 | }) |
353 | ||
354 | it('Should fail with a tag length too low', function (done) { | |
355 | const data = { | |
356 | name: 'my super name', | |
357 | description: 'my super description', | |
358 | tags: [ 'tag1', 't' ] | |
359 | } | |
360 | const attach = { | |
361 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
362 | } | |
25ed57f3 | 363 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
364 | }) |
365 | ||
366 | it('Should fail with a tag length too big', function (done) { | |
367 | const data = { | |
368 | name: 'my super name', | |
369 | description: 'my super description', | |
370 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
371 | } | |
372 | const attach = { | |
373 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
374 | } | |
25ed57f3 | 375 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
376 | }) |
377 | ||
378 | it('Should fail with malformed tags', function (done) { | |
379 | const data = { | |
380 | name: 'my super name', | |
381 | description: 'my super description', | |
382 | tags: [ 'my tag' ] | |
383 | } | |
384 | const attach = { | |
385 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | |
386 | } | |
25ed57f3 | 387 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
be587647 C |
388 | }) |
389 | ||
390 | it('Should fail without an input file', function (done) { | |
391 | const data = { | |
392 | name: 'my super name', | |
393 | description: 'my super description', | |
394 | tags: [ 'tag1', 'tag2' ] | |
395 | } | |
f0f5567b | 396 | const attach = {} |
25ed57f3 | 397 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 398 | }) |
34ca3b52 | 399 | |
9f10b292 | 400 | it('Should fail without an incorrect input file', function (done) { |
f0f5567b | 401 | const data = { |
9f10b292 | 402 | name: 'my super name', |
be587647 C |
403 | description: 'my super description', |
404 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 405 | } |
f0f5567b | 406 | const attach = { |
67100f1f C |
407 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') |
408 | } | |
25ed57f3 | 409 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
67100f1f C |
410 | }) |
411 | ||
412 | it('Should fail with a too big duration', function (done) { | |
413 | const data = { | |
414 | name: 'my super name', | |
be587647 C |
415 | description: 'my super description', |
416 | tags: [ 'tag1', 'tag2' ] | |
67100f1f C |
417 | } |
418 | const attach = { | |
419 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') | |
9f10b292 | 420 | } |
25ed57f3 | 421 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) |
9f10b292 | 422 | }) |
34ca3b52 | 423 | |
9f10b292 | 424 | it('Should succeed with the correct parameters', function (done) { |
f0f5567b | 425 | const data = { |
9f10b292 | 426 | name: 'my super name', |
be587647 C |
427 | description: 'my super description', |
428 | tags: [ 'tag1', 'tag2' ] | |
9f10b292 | 429 | } |
f0f5567b | 430 | const attach = { |
8c9c1942 | 431 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') |
9f10b292 | 432 | } |
25ed57f3 | 433 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { |
8c9c1942 | 434 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') |
25ed57f3 | 435 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { |
8c9c1942 | 436 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') |
25ed57f3 | 437 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) |
67100f1f C |
438 | }, false) |
439 | }, false) | |
34ca3b52 | 440 | }) |
9f10b292 | 441 | }) |
34ca3b52 | 442 | |
7b1f49de C |
443 | describe('When updating a video', function () { |
444 | let videoId | |
445 | ||
446 | before(function (done) { | |
447 | videosUtils.getVideosList(server.url, function (err, res) { | |
448 | if (err) throw err | |
449 | ||
450 | videoId = res.body.data[0].id | |
451 | ||
452 | return done() | |
453 | }) | |
454 | }) | |
455 | ||
456 | it('Should fail with nothing', function (done) { | |
457 | const data = {} | |
458 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
459 | }) | |
460 | ||
461 | it('Should fail without a valid uuid', function (done) { | |
462 | const data = { | |
463 | description: 'my super description', | |
464 | tags: [ 'tag1', 'tag2' ] | |
465 | } | |
466 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | |
467 | }) | |
468 | ||
469 | it('Should fail with an unknown id', function (done) { | |
470 | const data = { | |
471 | description: 'my super description', | |
472 | tags: [ 'tag1', 'tag2' ] | |
473 | } | |
474 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done) | |
475 | }) | |
476 | ||
477 | it('Should fail with a long name', function (done) { | |
478 | const data = { | |
479 | name: 'My very very very very very very very very very very very very very very very very long name', | |
480 | description: 'my super description', | |
481 | tags: [ 'tag1', 'tag2' ] | |
482 | } | |
483 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
484 | }) | |
485 | ||
486 | it('Should fail with a long description', function (done) { | |
487 | const data = { | |
488 | name: 'my super name', | |
489 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
490 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
491 | 'very very very very very very very very very very very very very very very long', | |
492 | tags: [ 'tag1', 'tag2' ] | |
493 | } | |
494 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
495 | }) | |
496 | ||
497 | it('Should fail with too many tags', function (done) { | |
498 | const data = { | |
499 | name: 'my super name', | |
500 | description: 'my super description', | |
501 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
502 | } | |
503 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
504 | }) | |
505 | ||
506 | it('Should fail with not enough tags', function (done) { | |
507 | const data = { | |
508 | name: 'my super name', | |
509 | description: 'my super description', | |
510 | tags: [ ] | |
511 | } | |
512 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
513 | }) | |
514 | ||
515 | it('Should fail with a tag length too low', function (done) { | |
516 | const data = { | |
517 | name: 'my super name', | |
518 | description: 'my super description', | |
519 | tags: [ 'tag1', 't' ] | |
520 | } | |
521 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
522 | }) | |
523 | ||
524 | it('Should fail with a tag length too big', function (done) { | |
525 | const data = { | |
526 | name: 'my super name', | |
527 | description: 'my super description', | |
528 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
529 | } | |
530 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
531 | }) | |
532 | ||
533 | it('Should fail with malformed tags', function (done) { | |
534 | const data = { | |
535 | name: 'my super name', | |
536 | description: 'my super description', | |
537 | tags: [ 'my tag' ] | |
538 | } | |
539 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
540 | }) | |
541 | }) | |
542 | ||
9f10b292 C |
543 | describe('When getting a video', function () { |
544 | it('Should return the list of the videos with nothing', function (done) { | |
0c1cbbfe | 545 | request(server.url) |
9f10b292 C |
546 | .get(path) |
547 | .set('Accept', 'application/json') | |
548 | .expect(200) | |
549 | .expect('Content-Type', /json/) | |
550 | .end(function (err, res) { | |
551 | if (err) throw err | |
34ca3b52 | 552 | |
68ce3ae0 C |
553 | expect(res.body.data).to.be.an('array') |
554 | expect(res.body.data.length).to.equal(3) | |
34ca3b52 | 555 | |
9f10b292 C |
556 | done() |
557 | }) | |
558 | }) | |
34ca3b52 | 559 | |
7920c273 | 560 | it('Should fail without a correct uuid', function (done) { |
0c1cbbfe | 561 | request(server.url) |
9f10b292 C |
562 | .get(path + 'coucou') |
563 | .set('Accept', 'application/json') | |
564 | .expect(400, done) | |
34ca3b52 C |
565 | }) |
566 | ||
9f10b292 | 567 | it('Should return 404 with an incorrect video', function (done) { |
0c1cbbfe | 568 | request(server.url) |
feb4bdfd | 569 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') |
9f10b292 | 570 | .set('Accept', 'application/json') |
34ca3b52 | 571 | .expect(404, done) |
34ca3b52 | 572 | }) |
9f10b292 C |
573 | |
574 | it('Should succeed with the correct parameters') | |
34ca3b52 C |
575 | }) |
576 | ||
9f10b292 C |
577 | describe('When removing a video', function () { |
578 | it('Should have 404 with nothing', function (done) { | |
0c1cbbfe C |
579 | request(server.url) |
580 | .delete(path) | |
b6c6f935 | 581 | .set('Authorization', 'Bearer ' + server.accessToken) |
0c1cbbfe | 582 | .expect(400, done) |
34ca3b52 C |
583 | }) |
584 | ||
7920c273 | 585 | it('Should fail without a correct uuid', function (done) { |
0c1cbbfe | 586 | request(server.url) |
9f10b292 | 587 | .delete(path + 'hello') |
b6c6f935 | 588 | .set('Authorization', 'Bearer ' + server.accessToken) |
9f10b292 | 589 | .expect(400, done) |
34ca3b52 C |
590 | }) |
591 | ||
9f10b292 | 592 | it('Should fail with a video which does not exist', function (done) { |
0c1cbbfe | 593 | request(server.url) |
feb4bdfd | 594 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') |
b6c6f935 | 595 | .set('Authorization', 'Bearer ' + server.accessToken) |
9f10b292 | 596 | .expect(404, done) |
34ca3b52 | 597 | }) |
9f10b292 | 598 | |
58b2ba55 C |
599 | it('Should fail with a video of another user') |
600 | ||
9f10b292 C |
601 | it('Should fail with a video of another pod') |
602 | ||
603 | it('Should succeed with the correct parameters') | |
34ca3b52 | 604 | }) |
9f10b292 | 605 | }) |
34ca3b52 | 606 | |
9bd26629 C |
607 | describe('Of the users API', function () { |
608 | const path = '/api/v1/users/' | |
99a64bfe | 609 | let userId = null |
af1068ce | 610 | let rootId = null |
9bd26629 | 611 | |
5c39adb7 C |
612 | describe('When listing users', function () { |
613 | it('Should fail with a bad start pagination', function (done) { | |
614 | request(server.url) | |
615 | .get(path) | |
616 | .query({ start: 'hello' }) | |
617 | .set('Accept', 'application/json') | |
618 | .expect(400, done) | |
619 | }) | |
620 | ||
621 | it('Should fail with a bad count pagination', function (done) { | |
622 | request(server.url) | |
623 | .get(path) | |
624 | .query({ count: 'hello' }) | |
625 | .set('Accept', 'application/json') | |
626 | .expect(400, done) | |
627 | }) | |
628 | ||
629 | it('Should fail with an incorrect sort', function (done) { | |
630 | request(server.url) | |
631 | .get(path) | |
632 | .query({ sort: 'hello' }) | |
633 | .set('Accept', 'application/json') | |
634 | .expect(400, done) | |
635 | }) | |
636 | }) | |
637 | ||
9bd26629 C |
638 | describe('When adding a new user', function () { |
639 | it('Should fail with a too small username', function (done) { | |
640 | const data = { | |
641 | username: 'ji', | |
642 | password: 'mysuperpassword' | |
643 | } | |
644 | ||
25ed57f3 | 645 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
646 | }) |
647 | ||
648 | it('Should fail with a too long username', function (done) { | |
649 | const data = { | |
650 | username: 'mysuperusernamewhichisverylong', | |
651 | password: 'mysuperpassword' | |
652 | } | |
653 | ||
25ed57f3 | 654 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
655 | }) |
656 | ||
657 | it('Should fail with an incorrect username', function (done) { | |
658 | const data = { | |
659 | username: 'my username', | |
660 | password: 'mysuperpassword' | |
661 | } | |
662 | ||
25ed57f3 | 663 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
664 | }) |
665 | ||
666 | it('Should fail with a too small password', function (done) { | |
667 | const data = { | |
668 | username: 'myusername', | |
669 | password: 'bla' | |
670 | } | |
671 | ||
25ed57f3 | 672 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
673 | }) |
674 | ||
675 | it('Should fail with a too long password', function (done) { | |
676 | const data = { | |
677 | username: 'myusername', | |
678 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
679 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
680 | 'very very very very very very very very very very very very very very very very very very very very long' | |
681 | } | |
682 | ||
25ed57f3 | 683 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
684 | }) |
685 | ||
686 | it('Should fail with an non authenticated user', function (done) { | |
687 | const data = { | |
688 | username: 'myusername', | |
689 | password: 'my super password' | |
690 | } | |
691 | ||
25ed57f3 | 692 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) |
9bd26629 C |
693 | }) |
694 | ||
327680c9 | 695 | it('Should fail if we add a user with the same username', function (done) { |
9bd26629 C |
696 | const data = { |
697 | username: 'user1', | |
698 | password: 'my super password' | |
699 | } | |
700 | ||
327680c9 | 701 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) |
9bd26629 C |
702 | }) |
703 | ||
327680c9 C |
704 | it('Should succeed with the correct params', function (done) { |
705 | const data = { | |
706 | username: 'user2', | |
707 | password: 'my super password' | |
708 | } | |
bf68dd75 | 709 | |
327680c9 | 710 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) |
bf68dd75 C |
711 | }) |
712 | ||
9bd26629 C |
713 | it('Should fail with a non admin user', function (done) { |
714 | server.user = { | |
715 | username: 'user1', | |
327680c9 | 716 | password: 'password' |
9bd26629 C |
717 | } |
718 | ||
8d309058 | 719 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
9bd26629 C |
720 | if (err) throw err |
721 | ||
99a64bfe C |
722 | userAccessToken = accessToken |
723 | ||
9bd26629 | 724 | const data = { |
327680c9 | 725 | username: 'user3', |
9bd26629 C |
726 | password: 'my super password' |
727 | } | |
728 | ||
25ed57f3 | 729 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) |
9bd26629 C |
730 | }) |
731 | }) | |
732 | }) | |
733 | ||
734 | describe('When updating a user', function () { | |
9bd26629 | 735 | before(function (done) { |
8d309058 | 736 | usersUtils.getUsersList(server.url, function (err, res) { |
9bd26629 C |
737 | if (err) throw err |
738 | ||
739 | userId = res.body.data[1].id | |
af1068ce | 740 | rootId = res.body.data[2].id |
9bd26629 C |
741 | done() |
742 | }) | |
743 | }) | |
744 | ||
745 | it('Should fail with a too small password', function (done) { | |
746 | const data = { | |
747 | password: 'bla' | |
748 | } | |
749 | ||
25ed57f3 | 750 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
751 | }) |
752 | ||
753 | it('Should fail with a too long password', function (done) { | |
754 | const data = { | |
755 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
756 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
757 | 'very very very very very very very very very very very very very very very very very very very very long' | |
758 | } | |
759 | ||
25ed57f3 | 760 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
761 | }) |
762 | ||
763 | it('Should fail with an non authenticated user', function (done) { | |
764 | const data = { | |
765 | password: 'my super password' | |
766 | } | |
767 | ||
25ed57f3 | 768 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) |
9bd26629 C |
769 | }) |
770 | ||
771 | it('Should succeed with the correct params', function (done) { | |
772 | const data = { | |
773 | password: 'my super password' | |
774 | } | |
775 | ||
25ed57f3 | 776 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) |
99a64bfe C |
777 | }) |
778 | }) | |
779 | ||
780 | describe('When getting my information', function () { | |
781 | it('Should fail with a non authenticated user', function (done) { | |
782 | request(server.url) | |
783 | .get(path + 'me') | |
784 | .set('Authorization', 'Bearer faketoken') | |
785 | .set('Accept', 'application/json') | |
786 | .expect(401, done) | |
787 | }) | |
788 | ||
789 | it('Should success with the correct parameters', function (done) { | |
790 | request(server.url) | |
791 | .get(path + 'me') | |
792 | .set('Authorization', 'Bearer ' + userAccessToken) | |
793 | .set('Accept', 'application/json') | |
794 | .expect(200, done) | |
9bd26629 C |
795 | }) |
796 | }) | |
797 | ||
798 | describe('When removing an user', function () { | |
68a3b9f2 | 799 | it('Should fail with an incorrect id', function (done) { |
9bd26629 C |
800 | request(server.url) |
801 | .delete(path + 'bla-bla') | |
802 | .set('Authorization', 'Bearer ' + server.accessToken) | |
803 | .expect(400, done) | |
804 | }) | |
805 | ||
af1068ce C |
806 | it('Should fail with the root user', function (done) { |
807 | request(server.url) | |
808 | .delete(path + rootId) | |
809 | .set('Authorization', 'Bearer ' + server.accessToken) | |
810 | .expect(400, done) | |
811 | }) | |
812 | ||
68a3b9f2 | 813 | it('Should return 404 with a non existing id', function (done) { |
9bd26629 | 814 | request(server.url) |
feb4bdfd | 815 | .delete(path + '45') |
9bd26629 C |
816 | .set('Authorization', 'Bearer ' + server.accessToken) |
817 | .expect(404, done) | |
818 | }) | |
9bd26629 C |
819 | }) |
820 | }) | |
821 | ||
9f10b292 C |
822 | describe('Of the remote videos API', function () { |
823 | describe('When making a secure request', function () { | |
824 | it('Should check a secure request') | |
825 | }) | |
34ca3b52 | 826 | |
9f10b292 C |
827 | describe('When adding a video', function () { |
828 | it('Should check when adding a video') | |
34ca3b52 | 829 | }) |
9f10b292 C |
830 | |
831 | describe('When removing a video', function () { | |
832 | it('Should check when removing a video') | |
833 | }) | |
834 | }) | |
835 | ||
d3cd34be C |
836 | describe('Of the requests API', function () { |
837 | const path = '/api/v1/requests/stats' | |
838 | ||
839 | it('Should fail with an non authenticated user', function (done) { | |
840 | request(server.url) | |
841 | .get(path) | |
842 | .set('Accept', 'application/json') | |
843 | .expect(401, done) | |
844 | }) | |
845 | ||
846 | it('Should fail with a non admin user', function (done) { | |
847 | request(server.url) | |
848 | .get(path) | |
849 | .set('Authorization', 'Bearer ' + userAccessToken) | |
850 | .set('Accept', 'application/json') | |
851 | .expect(403, done) | |
852 | }) | |
853 | }) | |
854 | ||
9f10b292 | 855 | after(function (done) { |
0c1cbbfe | 856 | process.kill(-server.app.pid) |
9f10b292 C |
857 | |
858 | // Keep the logs if the test failed | |
859 | if (this.ok) { | |
8d309058 | 860 | serversUtils.flushTests(done) |
9f10b292 C |
861 | } else { |
862 | done() | |
863 | } | |
34ca3b52 | 864 | }) |
9f10b292 | 865 | }) |