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