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