aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/users.ts28
-rw-r--r--server/tests/api/check-params/video-channels.ts28
-rw-r--r--server/tests/api/users/user-subscriptions.ts156
3 files changed, 212 insertions, 0 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 58b360f92..517e2f423 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -840,6 +840,34 @@ describe('Test users API validators', function () {
840 }) 840 })
841 }) 841 })
842 842
843 describe('When getting my global followers', function () {
844 const path = '/api/v1/accounts/user1/followers'
845
846 it('Should fail with a bad start pagination', async function () {
847 await checkBadStartPagination(server.url, path, userToken)
848 })
849
850 it('Should fail with a bad count pagination', async function () {
851 await checkBadCountPagination(server.url, path, userToken)
852 })
853
854 it('Should fail with an incorrect sort', async function () {
855 await checkBadSortPagination(server.url, path, userToken)
856 })
857
858 it('Should fail with a unauthenticated user', async function () {
859 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
860 })
861
862 it('Should fail with a another user', async function () {
863 await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
864 })
865
866 it('Should succeed with the correct params', async function () {
867 await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.OK_200 })
868 })
869 })
870
843 describe('When blocking/unblocking/removing user', function () { 871 describe('When blocking/unblocking/removing user', function () {
844 872
845 it('Should fail with an incorrect id', async function () { 873 it('Should fail with an incorrect id', async function () {
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 2e63916d4..e86c315fa 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -321,6 +321,34 @@ describe('Test video channels API validator', function () {
321 }) 321 })
322 }) 322 })
323 323
324 describe('When getting channel followers', function () {
325 const path = '/api/v1/video-channels/super_channel/followers'
326
327 it('Should fail with a bad start pagination', async function () {
328 await checkBadStartPagination(server.url, path, server.accessToken)
329 })
330
331 it('Should fail with a bad count pagination', async function () {
332 await checkBadCountPagination(server.url, path, server.accessToken)
333 })
334
335 it('Should fail with an incorrect sort', async function () {
336 await checkBadSortPagination(server.url, path, server.accessToken)
337 })
338
339 it('Should fail with a unauthenticated user', async function () {
340 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
341 })
342
343 it('Should fail with a another user', async function () {
344 await makeGetRequest({ url: server.url, path, token: accessTokenUser, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
345 })
346
347 it('Should succeed with the correct params', async function () {
348 await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
349 })
350 })
351
324 describe('When deleting a video channel', function () { 352 describe('When deleting a video channel', function () {
325 it('Should fail with a non authenticated user', async function () { 353 it('Should fail with a non authenticated user', async function () {
326 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 354 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index 441f70d07..b49367be6 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -368,6 +368,162 @@ describe('Test users subscriptions', function () {
368 } 368 }
369 }) 369 })
370 370
371 it('Should follow user channels of server 3 by root of server 3', async function () {
372 this.timeout(60000)
373
374 await servers[2].channels.create({ token: users[2].accessToken, attributes: { name: 'user3_channel2' } })
375
376 await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port })
377 await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel2@localhost:' + servers[2].port })
378
379 await waitJobs(servers)
380 })
381
382 it('Should list user 3 followers', async function () {
383 {
384 const { total, data } = await servers[2].accounts.listFollowers({
385 token: users[2].accessToken,
386 accountName: 'user3',
387 start: 0,
388 count: 5,
389 sort: 'createdAt'
390 })
391
392 expect(total).to.equal(3)
393 expect(data[0].following.host).to.equal(servers[2].host)
394 expect(data[0].following.name).to.equal('user3_channel')
395 expect(data[0].follower.host).to.equal(servers[0].host)
396 expect(data[0].follower.name).to.equal('user1')
397
398 expect(data[1].following.host).to.equal(servers[2].host)
399 expect(data[1].following.name).to.equal('user3_channel')
400 expect(data[1].follower.host).to.equal(servers[2].host)
401 expect(data[1].follower.name).to.equal('root')
402
403 expect(data[2].following.host).to.equal(servers[2].host)
404 expect(data[2].following.name).to.equal('user3_channel2')
405 expect(data[2].follower.host).to.equal(servers[2].host)
406 expect(data[2].follower.name).to.equal('root')
407 }
408
409 {
410 const { total, data } = await servers[2].accounts.listFollowers({
411 token: users[2].accessToken,
412 accountName: 'user3',
413 start: 0,
414 count: 1,
415 sort: '-createdAt'
416 })
417
418 expect(total).to.equal(3)
419 expect(data[0].following.host).to.equal(servers[2].host)
420 expect(data[0].following.name).to.equal('user3_channel2')
421 expect(data[0].follower.host).to.equal(servers[2].host)
422 expect(data[0].follower.name).to.equal('root')
423 }
424
425 {
426 const { total, data } = await servers[2].accounts.listFollowers({
427 token: users[2].accessToken,
428 accountName: 'user3',
429 start: 1,
430 count: 1,
431 sort: '-createdAt'
432 })
433
434 expect(total).to.equal(3)
435 expect(data[0].following.host).to.equal(servers[2].host)
436 expect(data[0].following.name).to.equal('user3_channel')
437 expect(data[0].follower.host).to.equal(servers[2].host)
438 expect(data[0].follower.name).to.equal('root')
439 }
440
441 {
442 const { total, data } = await servers[2].accounts.listFollowers({
443 token: users[2].accessToken,
444 accountName: 'user3',
445 search: 'user1',
446 sort: '-createdAt'
447 })
448
449 expect(total).to.equal(1)
450 expect(data[0].following.host).to.equal(servers[2].host)
451 expect(data[0].following.name).to.equal('user3_channel')
452 expect(data[0].follower.host).to.equal(servers[0].host)
453 expect(data[0].follower.name).to.equal('user1')
454 }
455 })
456
457 it('Should list user3_channel followers', async function () {
458 {
459 const { total, data } = await servers[2].channels.listFollowers({
460 token: users[2].accessToken,
461 channelName: 'user3_channel',
462 start: 0,
463 count: 5,
464 sort: 'createdAt'
465 })
466
467 expect(total).to.equal(2)
468 expect(data[0].following.host).to.equal(servers[2].host)
469 expect(data[0].following.name).to.equal('user3_channel')
470 expect(data[0].follower.host).to.equal(servers[0].host)
471 expect(data[0].follower.name).to.equal('user1')
472
473 expect(data[1].following.host).to.equal(servers[2].host)
474 expect(data[1].following.name).to.equal('user3_channel')
475 expect(data[1].follower.host).to.equal(servers[2].host)
476 expect(data[1].follower.name).to.equal('root')
477 }
478
479 {
480 const { total, data } = await servers[2].channels.listFollowers({
481 token: users[2].accessToken,
482 channelName: 'user3_channel',
483 start: 0,
484 count: 1,
485 sort: '-createdAt'
486 })
487
488 expect(total).to.equal(2)
489 expect(data[0].following.host).to.equal(servers[2].host)
490 expect(data[0].following.name).to.equal('user3_channel')
491 expect(data[0].follower.host).to.equal(servers[2].host)
492 expect(data[0].follower.name).to.equal('root')
493 }
494
495 {
496 const { total, data } = await servers[2].channels.listFollowers({
497 token: users[2].accessToken,
498 channelName: 'user3_channel',
499 start: 1,
500 count: 1,
501 sort: '-createdAt'
502 })
503
504 expect(total).to.equal(2)
505 expect(data[0].following.host).to.equal(servers[2].host)
506 expect(data[0].following.name).to.equal('user3_channel')
507 expect(data[0].follower.host).to.equal(servers[0].host)
508 expect(data[0].follower.name).to.equal('root')
509 }
510
511 {
512 const { total, data } = await servers[2].channels.listFollowers({
513 token: users[2].accessToken,
514 channelName: 'user3_channel',
515 search: 'user1',
516 sort: '-createdAt'
517 })
518
519 expect(total).to.equal(1)
520 expect(data[0].following.host).to.equal(servers[2].host)
521 expect(data[0].following.name).to.equal('user3_channel')
522 expect(data[0].follower.host).to.equal(servers[0].host)
523 expect(data[0].follower.name).to.equal('user1')
524 }
525 })
526
371 after(async function () { 527 after(async function () {
372 await cleanupTests(servers) 528 await cleanupTests(servers)
373 }) 529 })