From 197876ea87494f9c8f5262fa371b0f70e3c56fb5 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 20 Apr 2020 15:28:16 +0200 Subject: [PATCH] Add tests for video-abuse persistence after video deletion --- server/models/video/video-abuse.ts | 3 ++- server/tests/api/videos/video-abuse.ts | 30 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 285fb1fbc..628f1caa6 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -143,7 +143,8 @@ export enum ScopeNames { 'SELECT count(DISTINCT "videoAbuse"."id") ' + 'FROM "videoAbuse" ' + `WHERE CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = "Video->VideoChannel"."accountId" ` + - `OR CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` + + `OR CAST("deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) = ` + + `CAST("VideoAbuseModel"."deletedVideo"->'channel'->'ownerAccount'->>'id' AS INTEGER) ` + ')' ), 'countReportsForReportee__deletedVideo' diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index cd6df7267..8a8290e14 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -13,7 +13,8 @@ import { ServerInfo, setAccessTokensToServers, updateVideoAbuse, - uploadVideo + uploadVideo, + removeVideo } from '../../../../shared/extra-utils/index' import { doubleFollow } from '../../../../shared/extra-utils/server/follows' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -97,6 +98,11 @@ describe('Test video abuses', function () { expect(abuse.reporterAccount.name).to.equal('root') expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.channel).to.exist + expect(abuse.count).to.equal(1) + expect(abuse.nth).to.equal(1) + expect(abuse.countReportsForReporter).to.equal(1) + expect(abuse.countReportsForReportee).to.equal(1) const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) expect(res2.body.total).to.equal(0) @@ -128,6 +134,8 @@ describe('Test video abuses', function () { expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING) expect(abuse1.state.label).to.equal('Pending') expect(abuse1.moderationComment).to.be.null + expect(abuse1.count).to.equal(1) + expect(abuse1.nth).to.equal(1) const abuse2: VideoAbuse = res1.body.data[1] expect(abuse2.reason).to.equal('my super bad reason 2') @@ -221,6 +229,26 @@ describe('Test video abuses', function () { } }) + it('Should keep the video abuse when deleting the video', async function () { + this.timeout(10000) + + await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) + + await waitJobs(servers) + + { + const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) + expect(res.body.total).to.equal(2) + expect(res.body.data.length).to.equal(2) + expect(res.body.data[0].id).to.equal(abuseServer2.id) + + const abuse: VideoAbuse = res.body.data[1] + expect(abuse.video.deleted).to.be.true + expect(abuse.video.id).to.equal(abuseServer2.video.id) + expect(abuse.video.channel).to.exist + } + }) + it('Should delete the video abuse', async function () { this.timeout(10000) -- 2.25.1