From 32b2b43c06621e384c0bd1610ef0bb9f23399be7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Jan 2018 11:47:45 +0100 Subject: Update follower/following counts --- server/tests/api/server/follows.ts | 37 ++++++++++++++++++++++++++++++++++++ server/tests/utils/users/accounts.ts | 12 ++++++++++++ 2 files changed, 49 insertions(+) (limited to 'server/tests') diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index e6dfd5f62..27cf94985 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -12,6 +12,7 @@ import { } from '../../utils/index' import { dateIsValid } from '../../utils/miscs/miscs' import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' +import { expectAccountFollows } from '../../utils/users/accounts' import { userLogin } from '../../utils/users/login' import { createUser } from '../../utils/users/users' import { @@ -116,6 +117,19 @@ describe('Test follows', function () { expect(follows.length).to.equal(0) }) + it('Should have the correct following counts', async function () { + await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 2) + await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:9003', 1, 0) + + // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) + await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + + await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0) + }) + it('Should unfollow server 3 on server 1', async function () { this.timeout(5000) @@ -144,6 +158,17 @@ describe('Test follows', function () { expect(follows.length).to.equal(0) }) + it('Should have the correct following counts 2', async function () { + await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) + + await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + + await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 0) + await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 0, 0) + }) + it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () { this.timeout(10000) @@ -223,6 +248,18 @@ describe('Test follows', function () { await wait(7000) }) + it('Should have the correct following counts 2', async function () { + await expectAccountFollows(servers[0].url, 'peertube@localhost:9001', 0, 2) + await expectAccountFollows(servers[0].url, 'peertube@localhost:9002', 1, 0) + await expectAccountFollows(servers[0].url, 'peertube@localhost:9003', 1, 0) + + await expectAccountFollows(servers[1].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[1].url, 'peertube@localhost:9002', 1, 0) + + await expectAccountFollows(servers[2].url, 'peertube@localhost:9001', 0, 1) + await expectAccountFollows(servers[2].url, 'peertube@localhost:9003', 1, 0) + }) + it('Should propagate videos', async function () { const res = await getVideosList(servers[ 0 ].url) expect(res.body.total).to.equal(7) diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts index 71712100e..0ec7992b3 100644 --- a/server/tests/utils/users/accounts.ts +++ b/server/tests/utils/users/accounts.ts @@ -1,3 +1,5 @@ +import { expect } from 'chai' +import { Account } from '../../../../shared/models/actors' import { makeGetRequest } from '../requests/requests' function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { @@ -21,9 +23,19 @@ function getAccount (url: string, accountId: number | string, statusCodeExpected }) } +async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) { + const res = await getAccountsList(url) + const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain) + + const message = `${nameWithDomain} on ${url}` + expect(account.followersCount).to.equal(followersCount, message) + expect(account.followingCount).to.equal(followingCount, message) +} + // --------------------------------------------------------------------------- export { getAccount, + expectAccountFollows, getAccountsList } -- cgit v1.2.3