From feb34f6b6b991046aab6a10df747b48fa4da07a7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 May 2020 17:39:07 +0200 Subject: Use video abuse filters on client side --- server/tests/api/check-params/video-abuses.ts | 16 ++++++ server/tests/api/users/users.ts | 2 +- server/tests/api/videos/video-abuse.ts | 70 +++++++++++++++++++++------ 3 files changed, 71 insertions(+), 17 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index bea2177f3..e643cb95e 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts @@ -76,6 +76,22 @@ describe('Test video abuses API validators', function () { statusCodeExpected: 403 }) }) + + it('Should fail with a bad id filter', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } }) + }) + + it('Should fail with a bad state filter', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } }) + }) + + it('Should fail with a bad videoIs filter', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } }) + }) + + it('Should succeed with the correct params', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 13 }, statusCodeExpected: 200 }) + }) }) describe('When reporting a video abuse', function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 60fbd2a20..f3b732632 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -901,7 +901,7 @@ describe('Test users', function () { const reason = 'my super bad reason' await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) - const res1 = await getVideoAbusesList(server.url, server.accessToken) + const res1 = await getVideoAbusesList({ url: server.url, token: server.accessToken }) const abuseId = res1.body.data[0].id const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index 26bc3783b..a96be97f6 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -71,7 +71,7 @@ describe('Test video abuses', function () { }) it('Should not have video abuses', async function () { - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(0) expect(res.body.data).to.be.an('array') @@ -89,7 +89,7 @@ describe('Test video abuses', function () { }) it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { - const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res1.body.total).to.equal(1) expect(res1.body.data).to.be.an('array') @@ -106,7 +106,7 @@ describe('Test video abuses', function () { expect(abuse.countReportsForReporter).to.equal(1) expect(abuse.countReportsForReportee).to.equal(1) - const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res2.body.total).to.equal(0) expect(res2.body.data).to.be.an('array') expect(res2.body.data.length).to.equal(0) @@ -123,7 +123,7 @@ describe('Test video abuses', function () { }) it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { - const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res1.body.total).to.equal(2) expect(res1.body.data).to.be.an('array') expect(res1.body.data.length).to.equal(2) @@ -148,7 +148,7 @@ describe('Test video abuses', function () { expect(abuse2.state.label).to.equal('Pending') expect(abuse2.moderationComment).to.be.null - const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res2.body.total).to.equal(1) expect(res2.body.data).to.be.an('array') expect(res2.body.data.length).to.equal(1) @@ -166,7 +166,7 @@ describe('Test video abuses', function () { const body = { state: VideoAbuseState.REJECTED } await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) - const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED) }) @@ -174,7 +174,7 @@ describe('Test video abuses', function () { const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' } await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) - const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED) expect(res.body.data[0].moderationComment).to.equal('It is valid') }) @@ -186,7 +186,7 @@ describe('Test video abuses', function () { await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') await waitJobs(servers) - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(3) } @@ -195,7 +195,7 @@ describe('Test video abuses', function () { { await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(2) const abuse = res.body.data.find(a => a.reason === 'will mute this') @@ -205,7 +205,7 @@ describe('Test video abuses', function () { { await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(3) } }) @@ -216,7 +216,7 @@ describe('Test video abuses', function () { { await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(2) const abuse = res.body.data.find(a => a.reason === 'will mute this') @@ -226,7 +226,7 @@ describe('Test video abuses', function () { { await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(3) } }) @@ -238,7 +238,7 @@ describe('Test video abuses', function () { await waitJobs(servers) - const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res.body.total).to.equal(2, "wrong number of videos returned") expect(res.body.data.length).to.equal(2, "wrong number of videos returned") expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video") @@ -274,7 +274,7 @@ describe('Test video abuses', function () { const reason4 = 'my super bad reason 4' await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4) - const res2 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) { for (const abuse of res2.body.data as VideoAbuse[]) { @@ -299,18 +299,56 @@ describe('Test video abuses', function () { await waitJobs(servers) { - const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) expect(res.body.total).to.equal(1) expect(res.body.data.length).to.equal(1) expect(res.body.data[0].id).to.not.equal(abuseServer2.id) } { - const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(5) } }) + it('Should list and filter video abuses', async function () { + async function list (query: Omit[0], 'url' | 'token'>) { + const options = { + url: servers[0].url, + token: servers[0].accessToken + } + + Object.assign(options, query) + + const res = await getVideoAbusesList(options) + + return res.body.data as VideoAbuse[] + } + + expect(await list({ id: 56 })).to.have.lengthOf(0) + expect(await list({ id: 1 })).to.have.lengthOf(1) + + expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(3) + expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) + + expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) + + expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(3) + expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) + + expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) + expect(await list({ searchReporter: 'root' })).to.have.lengthOf(4) + + expect(await list({ searchReportee: 'root' })).to.have.lengthOf(3) + expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) + + expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) + expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) + + expect(await list({ state: VideoAbuseState.ACCEPTED })).to.have.lengthOf(0) + expect(await list({ state: VideoAbuseState.PENDING })).to.have.lengthOf(5) + }) + after(async function () { await cleanupTests(servers) }) -- cgit v1.2.3