From 97ecddae104f4013d261f0e9645e8b319ff0f1a6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Nov 2019 10:55:17 +0100 Subject: Filter on follows actor types in about page --- server/tests/api/check-params/follows.ts | 26 +++++- server/tests/api/redundancy/redundancy.ts | 4 +- server/tests/api/server/auto-follows.ts | 4 +- server/tests/api/server/follows-moderation.ts | 16 ++-- server/tests/api/server/follows.ts | 130 +++++++++++++++++++------- server/tests/api/server/handle-down.ts | 4 +- 6 files changed, 135 insertions(+), 49 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 488666a75..be2a603a3 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -142,13 +142,24 @@ describe('Test server follows API validators', function () { }) }) + it('Should fail with an incorrect actor type', async function () { + await makeGetRequest({ + url: server.url, + path, + query: { + actorType: 'blabla' + } + }) + }) + it('Should fail succeed with the correct params', async function () { await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { - state: 'accepted' + state: 'accepted', + actorType: 'Application' } }) }) @@ -169,12 +180,23 @@ describe('Test server follows API validators', function () { await checkBadSortPagination(server.url, path) }) + it('Should fail with an incorrect actor type', async function () { + await makeGetRequest({ + url: server.url, + path, + query: { + actorType: 'blabla' + } + }) + }) + it('Should fail with an incorrect state', async function () { await makeGetRequest({ url: server.url, path, query: { - state: 'blabla' + state: 'blabla', + actorType: 'Application' } }) }) diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 9e8733774..be24eb32f 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -247,7 +247,7 @@ async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) { async function enableRedundancyOnServer1 () { await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true) - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, '-createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: '-createdAt' }) const follows: ActorFollow[] = res.body.data const server2 = follows.find(f => f.following.host === `localhost:${servers[ 1 ].port}`) const server3 = follows.find(f => f.following.host === `localhost:${servers[ 2 ].port}`) @@ -262,7 +262,7 @@ async function enableRedundancyOnServer1 () { async function disableRedundancyOnServer1 () { await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, false) - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, '-createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: '-createdAt' }) const follows: ActorFollow[] = res.body.data const server2 = follows.find(f => f.following.host === `localhost:${servers[ 1 ].port}`) const server3 = follows.find(f => f.following.host === `localhost:${servers[ 2 ].port}`) diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index df468034c..a06f578fc 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -21,7 +21,7 @@ const expect = chai.expect async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) { { - const res = await getFollowersListPaginationAndSort(following.url, 0, 5, '-createdAt') + const res = await getFollowersListPaginationAndSort({ url: following.url, start: 0, count: 5, sort: '-createdAt' }) const follows = res.body.data as ActorFollow[] const follow = follows.find(f => { @@ -36,7 +36,7 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: } { - const res = await getFollowingListPaginationAndSort(follower.url, 0, 5, '-createdAt') + const res = await getFollowingListPaginationAndSort({ url: follower.url, start: 0, count: 5, sort: '-createdAt' }) const follows = res.body.data as ActorFollow[] const follow = follows.find(f => { diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index a82acdb34..1984c9eb1 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -24,7 +24,7 @@ const expect = chai.expect async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(1) const follow = res.body.data[0] as ActorFollow @@ -34,7 +34,7 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc } { - const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 1 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(1) const follow = res.body.data[0] as ActorFollow @@ -46,12 +46,12 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc async function checkNoFollowers (servers: ServerInfo[]) { { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(0) } { - const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 1 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(0) } } @@ -164,17 +164,17 @@ describe('Test follows moderation', function () { await waitJobs(servers) { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(2) } { - const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 1 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(1) } { - const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 2 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(1) } @@ -184,7 +184,7 @@ describe('Test follows moderation', function () { await checkServer1And2HasFollowers(servers) { - const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 2 ].url, start: 0, count: 5, sort: 'createdAt' }) expect(res.body.total).to.equal(0) } }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 36a061926..dd85722a0 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -49,7 +49,7 @@ describe('Test follows', function () { it('Should not have followers', async function () { for (const server of servers) { - const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -60,7 +60,7 @@ describe('Test follows', function () { it('Should not have following', async function () { for (const server of servers) { - const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -78,14 +78,14 @@ describe('Test follows', function () { }) it('Should have 2 followings on server 1', async function () { - let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') + let res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 1, sort: 'createdAt' }) let follows = res.body.data expect(res.body.total).to.equal(2) expect(follows).to.be.an('array') expect(follows.length).to.equal(1) - res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') + res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 1, count: 1, sort: 'createdAt' }) follows = follows.concat(res.body.data) const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) @@ -98,26 +98,58 @@ describe('Test follows', function () { }) it('Should search/filter followings on server 1', async function () { + const sort = 'createdAt' + const start = 0 + const count = 1 + const url = servers[ 0 ].url + { const search = ':' + servers[1].port - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', search) - const follows = res.body.data - expect(res.body.total).to.equal(1) - expect(follows.length).to.equal(1) - expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[1].port) + { + const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search }) + const follows = res.body.data - const res2 = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', search, 'accepted') - expect(res2.body.total).to.equal(1) - expect(res2.body.data).to.have.lengthOf(1) + expect(res.body.total).to.equal(1) + expect(follows.length).to.equal(1) + expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[ 1 ].port) + } + + { + const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) + expect(res.body.total).to.equal(1) + expect(res.body.data).to.have.lengthOf(1) + } - const res3 = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', search, 'pending') - expect(res3.body.total).to.equal(0) - expect(res3.body.data).to.have.lengthOf(0) + { + const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + } + + { + const res = await getFollowingListPaginationAndSort({ + url, + start, + count, + sort, + search, + state: 'accepted', + actorType: 'Application' + }) + expect(res.body.total).to.equal(1) + expect(res.body.data).to.have.lengthOf(1) + } + + { + const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + } } { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt', 'bla') + const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search: 'bla' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -127,7 +159,7 @@ describe('Test follows', function () { it('Should have 0 followings on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -138,7 +170,7 @@ describe('Test follows', function () { it('Should have 1 followers on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt') + let res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 1, sort: 'createdAt' }) let follows = res.body.data expect(res.body.total).to.equal(1) @@ -149,26 +181,58 @@ describe('Test follows', function () { }) it('Should search/filter followers on server 2', async function () { + const url = servers[ 2 ].url + const start = 0 + const count = 5 + const sort = 'createdAt' + { const search = servers[0].port + '' - const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', search) - const follows = res.body.data - expect(res.body.total).to.equal(1) - expect(follows.length).to.equal(1) - expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[2].port) + { + const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search }) + const follows = res.body.data - const res2 = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', search, 'accepted') - expect(res2.body.total).to.equal(1) - expect(res2.body.data).to.have.lengthOf(1) + expect(res.body.total).to.equal(1) + expect(follows.length).to.equal(1) + expect(follows[ 0 ].following.host).to.equal('localhost:' + servers[ 2 ].port) + } + + { + const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) + expect(res.body.total).to.equal(1) + expect(res.body.data).to.have.lengthOf(1) + } - const res3 = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', search, 'pending') - expect(res3.body.total).to.equal(0) - expect(res3.body.data).to.have.lengthOf(0) + { + const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + } + + { + const res = await getFollowersListPaginationAndSort({ + url, + start, + count, + sort, + search, + state: 'accepted', + actorType: 'Application' + }) + expect(res.body.total).to.equal(1) + expect(res.body.data).to.have.lengthOf(1) + } + + { + const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + } } { - const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt', 'bla') + const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search: 'bla' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -177,7 +241,7 @@ describe('Test follows', function () { }) it('Should have 0 followers on server 1', async function () { - const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 5, sort: 'createdAt' }) const follows = res.body.data expect(res.body.total).to.equal(0) @@ -207,7 +271,7 @@ describe('Test follows', function () { }) it('Should not follow server 3 on server 1 anymore', async function () { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') + const res = await getFollowingListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 2, sort: 'createdAt' }) let follows = res.body.data expect(res.body.total).to.equal(1) @@ -218,7 +282,7 @@ describe('Test follows', function () { }) it('Should not have server 1 as follower on server 3 anymore', async function () { - const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 2 ].url, start: 0, count: 1, sort: 'createdAt' }) let follows = res.body.data expect(res.body.total).to.equal(0) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 420289bf4..a0f505474 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -174,7 +174,7 @@ describe('Test handle downs', function () { await wait(11000) // Only server 3 is still a follower of server 1 - const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 2, sort: 'createdAt' }) expect(res.body.data).to.be.an('array') expect(res.body.data).to.have.lengthOf(1) expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port) @@ -202,7 +202,7 @@ describe('Test handle downs', function () { await waitJobs(servers) - const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') + const res = await getFollowersListPaginationAndSort({ url: servers[ 0 ].url, start: 0, count: 2, sort: 'createdAt' }) expect(res.body.data).to.be.an('array') expect(res.body.data).to.have.lengthOf(2) }) -- cgit v1.2.3