From 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Oct 2021 09:44:43 +0200 Subject: Add ability to view my followers --- server/tests/api/check-params/users.ts | 28 +++++ server/tests/api/check-params/video-channels.ts | 28 +++++ server/tests/api/users/user-subscriptions.ts | 156 ++++++++++++++++++++++++ 3 files changed, 212 insertions(+) (limited to 'server/tests') 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 () { }) }) + describe('When getting my global followers', function () { + const path = '/api/v1/accounts/user1/followers' + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, userToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, userToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, userToken) + }) + + it('Should fail with a unauthenticated user', async function () { + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + }) + + it('Should fail with a another user', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + }) + + it('Should succeed with the correct params', async function () { + await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.OK_200 }) + }) + }) + describe('When blocking/unblocking/removing user', function () { 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 () { }) }) + describe('When getting channel followers', function () { + const path = '/api/v1/video-channels/super_channel/followers' + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, server.accessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a unauthenticated user', async function () { + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + }) + + it('Should fail with a another user', async function () { + await makeGetRequest({ url: server.url, path, token: accessTokenUser, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + }) + + it('Should succeed with the correct params', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) + }) + }) + describe('When deleting a video channel', function () { it('Should fail with a non authenticated user', async function () { 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 () { } }) + it('Should follow user channels of server 3 by root of server 3', async function () { + this.timeout(60000) + + await servers[2].channels.create({ token: users[2].accessToken, attributes: { name: 'user3_channel2' } }) + + await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) + await servers[2].subscriptions.add({ token: servers[2].accessToken, targetUri: 'user3_channel2@localhost:' + servers[2].port }) + + await waitJobs(servers) + }) + + it('Should list user 3 followers', async function () { + { + const { total, data } = await servers[2].accounts.listFollowers({ + token: users[2].accessToken, + accountName: 'user3', + start: 0, + count: 5, + sort: 'createdAt' + }) + + expect(total).to.equal(3) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[0].host) + expect(data[0].follower.name).to.equal('user1') + + expect(data[1].following.host).to.equal(servers[2].host) + expect(data[1].following.name).to.equal('user3_channel') + expect(data[1].follower.host).to.equal(servers[2].host) + expect(data[1].follower.name).to.equal('root') + + expect(data[2].following.host).to.equal(servers[2].host) + expect(data[2].following.name).to.equal('user3_channel2') + expect(data[2].follower.host).to.equal(servers[2].host) + expect(data[2].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].accounts.listFollowers({ + token: users[2].accessToken, + accountName: 'user3', + start: 0, + count: 1, + sort: '-createdAt' + }) + + expect(total).to.equal(3) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel2') + expect(data[0].follower.host).to.equal(servers[2].host) + expect(data[0].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].accounts.listFollowers({ + token: users[2].accessToken, + accountName: 'user3', + start: 1, + count: 1, + sort: '-createdAt' + }) + + expect(total).to.equal(3) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[2].host) + expect(data[0].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].accounts.listFollowers({ + token: users[2].accessToken, + accountName: 'user3', + search: 'user1', + sort: '-createdAt' + }) + + expect(total).to.equal(1) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[0].host) + expect(data[0].follower.name).to.equal('user1') + } + }) + + it('Should list user3_channel followers', async function () { + { + const { total, data } = await servers[2].channels.listFollowers({ + token: users[2].accessToken, + channelName: 'user3_channel', + start: 0, + count: 5, + sort: 'createdAt' + }) + + expect(total).to.equal(2) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[0].host) + expect(data[0].follower.name).to.equal('user1') + + expect(data[1].following.host).to.equal(servers[2].host) + expect(data[1].following.name).to.equal('user3_channel') + expect(data[1].follower.host).to.equal(servers[2].host) + expect(data[1].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].channels.listFollowers({ + token: users[2].accessToken, + channelName: 'user3_channel', + start: 0, + count: 1, + sort: '-createdAt' + }) + + expect(total).to.equal(2) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[2].host) + expect(data[0].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].channels.listFollowers({ + token: users[2].accessToken, + channelName: 'user3_channel', + start: 1, + count: 1, + sort: '-createdAt' + }) + + expect(total).to.equal(2) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[0].host) + expect(data[0].follower.name).to.equal('root') + } + + { + const { total, data } = await servers[2].channels.listFollowers({ + token: users[2].accessToken, + channelName: 'user3_channel', + search: 'user1', + sort: '-createdAt' + }) + + expect(total).to.equal(1) + expect(data[0].following.host).to.equal(servers[2].host) + expect(data[0].following.name).to.equal('user3_channel') + expect(data[0].follower.host).to.equal(servers[0].host) + expect(data[0].follower.name).to.equal('user1') + } + }) + after(async function () { await cleanupTests(servers) }) -- cgit v1.2.3