diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/users.js | 76 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.js | 42 |
2 files changed, 118 insertions, 0 deletions
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js index 6edb54660..11e2bada4 100644 --- a/server/tests/api/check-params/users.js +++ b/server/tests/api/check-params/users.js | |||
@@ -9,11 +9,13 @@ const loginUtils = require('../../utils/login') | |||
9 | const requestsUtils = require('../../utils/requests') | 9 | const requestsUtils = require('../../utils/requests') |
10 | const serversUtils = require('../../utils/servers') | 10 | const serversUtils = require('../../utils/servers') |
11 | const usersUtils = require('../../utils/users') | 11 | const usersUtils = require('../../utils/users') |
12 | const videosUtils = require('../../utils/videos') | ||
12 | 13 | ||
13 | describe('Test users API validators', function () { | 14 | describe('Test users API validators', function () { |
14 | const path = '/api/v1/users/' | 15 | const path = '/api/v1/users/' |
15 | let userId = null | 16 | let userId = null |
16 | let rootId = null | 17 | let rootId = null |
18 | let videoId = null | ||
17 | let server = null | 19 | let server = null |
18 | let userAccessToken = null | 20 | let userAccessToken = null |
19 | 21 | ||
@@ -48,6 +50,23 @@ describe('Test users API validators', function () { | |||
48 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | 50 | usersUtils.createUser(server.url, server.accessToken, username, password, next) |
49 | }, | 51 | }, |
50 | function (next) { | 52 | function (next) { |
53 | const name = 'my super name for pod' | ||
54 | const description = 'my super description for pod' | ||
55 | const tags = [ 'tag' ] | ||
56 | const file = 'video_short2.webm' | ||
57 | videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) | ||
58 | }, | ||
59 | function (next) { | ||
60 | videosUtils.getVideosList(server.url, function (err, res) { | ||
61 | if (err) throw err | ||
62 | |||
63 | const videos = res.body.data | ||
64 | videoId = videos[0].id | ||
65 | |||
66 | next() | ||
67 | }) | ||
68 | }, | ||
69 | function (next) { | ||
51 | const user = { | 70 | const user = { |
52 | username: 'user1', | 71 | username: 'user1', |
53 | password: 'my super password' | 72 | password: 'my super password' |
@@ -289,6 +308,63 @@ describe('Test users API validators', function () { | |||
289 | }) | 308 | }) |
290 | }) | 309 | }) |
291 | 310 | ||
311 | describe('When getting my video rating', function () { | ||
312 | it('Should fail with a non authenticated user', function (done) { | ||
313 | request(server.url) | ||
314 | .get(path + 'me/videos/' + videoId + '/rating') | ||
315 | .set('Authorization', 'Bearer faketoken') | ||
316 | .set('Accept', 'application/json') | ||
317 | .expect(401, done) | ||
318 | }) | ||
319 | |||
320 | it('Should fail with an incorrect video uuid', function (done) { | ||
321 | request(server.url) | ||
322 | .get(path + 'me/videos/blabla/rating') | ||
323 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
324 | .set('Accept', 'application/json') | ||
325 | .expect(400, done) | ||
326 | }) | ||
327 | |||
328 | it('Should fail with an unknown video', function (done) { | ||
329 | request(server.url) | ||
330 | .get(path + 'me/videos/4da6fde3-88f7-4d16-b119-108df5630b06/rating') | ||
331 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
332 | .set('Accept', 'application/json') | ||
333 | .expect(404, done) | ||
334 | }) | ||
335 | |||
336 | it('Should success with the correct parameters', function (done) { | ||
337 | request(server.url) | ||
338 | .get(path + 'me/videos/' + videoId + '/rating') | ||
339 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
340 | .set('Accept', 'application/json') | ||
341 | .expect(200, done) | ||
342 | }) | ||
343 | }) | ||
344 | |||
345 | describe('When removing an user', function () { | ||
346 | it('Should fail with an incorrect id', function (done) { | ||
347 | request(server.url) | ||
348 | .delete(path + 'bla-bla') | ||
349 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
350 | .expect(400, done) | ||
351 | }) | ||
352 | |||
353 | it('Should fail with the root user', function (done) { | ||
354 | request(server.url) | ||
355 | .delete(path + rootId) | ||
356 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
357 | .expect(400, done) | ||
358 | }) | ||
359 | |||
360 | it('Should return 404 with a non existing id', function (done) { | ||
361 | request(server.url) | ||
362 | .delete(path + '45') | ||
363 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
364 | .expect(404, done) | ||
365 | }) | ||
366 | }) | ||
367 | |||
292 | describe('When removing an user', function () { | 368 | describe('When removing an user', function () { |
293 | it('Should fail with an incorrect id', function (done) { | 369 | it('Should fail with an incorrect id', function (done) { |
294 | request(server.url) | 370 | request(server.url) |
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js index f8549a95b..0f5f40b8e 100644 --- a/server/tests/api/check-params/videos.js +++ b/server/tests/api/check-params/videos.js | |||
@@ -420,6 +420,48 @@ describe('Test videos API validator', function () { | |||
420 | it('Should succeed with the correct parameters') | 420 | it('Should succeed with the correct parameters') |
421 | }) | 421 | }) |
422 | 422 | ||
423 | describe('When rating a video', function () { | ||
424 | let videoId | ||
425 | |||
426 | before(function (done) { | ||
427 | videosUtils.getVideosList(server.url, function (err, res) { | ||
428 | if (err) throw err | ||
429 | |||
430 | videoId = res.body.data[0].id | ||
431 | |||
432 | return done() | ||
433 | }) | ||
434 | }) | ||
435 | |||
436 | it('Should fail without a valid uuid', function (done) { | ||
437 | const data = { | ||
438 | rating: 'like' | ||
439 | } | ||
440 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done) | ||
441 | }) | ||
442 | |||
443 | it('Should fail with an unknown id', function (done) { | ||
444 | const data = { | ||
445 | rating: 'like' | ||
446 | } | ||
447 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404) | ||
448 | }) | ||
449 | |||
450 | it('Should fail with a wrong rating', function (done) { | ||
451 | const data = { | ||
452 | rating: 'likes' | ||
453 | } | ||
454 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done) | ||
455 | }) | ||
456 | |||
457 | it('Should succeed with the correct parameters', function (done) { | ||
458 | const data = { | ||
459 | rating: 'like' | ||
460 | } | ||
461 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204) | ||
462 | }) | ||
463 | }) | ||
464 | |||
423 | describe('When removing a video', function () { | 465 | describe('When removing a video', function () { |
424 | it('Should have 404 with nothing', function (done) { | 466 | it('Should have 404 with nothing', function (done) { |
425 | request(server.url) | 467 | request(server.url) |