]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add tests for video-abuse persistence after video deletion
authorRigel Kent <sendmemail@rigelk.eu>
Mon, 20 Apr 2020 13:28:16 +0000 (15:28 +0200)
committerRigel Kent <par@rigelk.eu>
Fri, 1 May 2020 14:41:02 +0000 (16:41 +0200)
server/models/video/video-abuse.ts
server/tests/api/videos/video-abuse.ts

index 285fb1fbc609a23b52915189f1235626c747a491..628f1caa6f6db4e3d82c8de46bc212a53f25bfc7 100644 (file)
@@ -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'
index cd6df72672075e18ed5d1437c1cdbad801dd5dd2..8a8290e145d8ddd66abd71eb77647fc488abae80 100644 (file)
@@ -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)