]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/activitypub/cleaner.ts
Add signup approval API REST doc
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / cleaner.ts
index dc885023ab7af68b661dad055f1be8e08f4babce..1c1495022c5a5d0ce0cd9628ecd8db55295f7241 100644 (file)
@@ -1,7 +1,6 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
 import { wait } from '@shared/core-utils'
 import {
   cleanupTests,
@@ -12,8 +11,6 @@ import {
   waitJobs
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 describe('Test AP cleaner', function () {
   let servers: PeerTubeServer[] = []
   let videoUUID1: string
@@ -151,7 +148,7 @@ describe('Test AP cleaner', function () {
   it('Should destroy server 3 internal shares and correctly clean them', async function () {
     this.timeout(20000)
 
-    const preCount = await servers[0].sql.getCount('videoShare')
+    const preCount = await servers[0].sql.getVideoShareCount()
     expect(preCount).to.equal(6)
 
     await servers[2].sql.deleteAll('videoShare')
@@ -159,7 +156,7 @@ describe('Test AP cleaner', function () {
     await waitJobs(servers)
 
     // Still 6 because we don't have remote shares on local videos
-    const postCount = await servers[0].sql.getCount('videoShare')
+    const postCount = await servers[0].sql.getVideoShareCount()
     expect(postCount).to.equal(6)
   })
 
@@ -188,7 +185,7 @@ describe('Test AP cleaner', function () {
     async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') {
       const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` +
         `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'`
-      const res = await servers[0].sql.selectQuery(query)
+      const res = await servers[0].sql.selectQuery<{ url: string }>(query)
 
       for (const rate of res) {
         const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`)
@@ -234,7 +231,7 @@ describe('Test AP cleaner', function () {
       const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` +
         `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'`
 
-      const res = await servers[0].sql.selectQuery(query)
+      const res = await servers[0].sql.selectQuery<{ url: string, videoUUID: string }>(query)
 
       for (const comment of res) {
         const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`)
@@ -291,12 +288,12 @@ describe('Test AP cleaner', function () {
       {
         const video = await servers[0].videos.get({ id: uuid })
 
-        expect(video.likes).to.equal(3)
+        expect(video.likes).to.equal(2)
         expect(video.dislikes).to.equal(0)
       }
 
       {
-        const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 })
+        const { total } = await servers[0].comments.listThreads({ videoId: uuid })
         expect(total).to.equal(2)
       }
     }
@@ -319,8 +316,15 @@ describe('Test AP cleaner', function () {
     await wait(5000)
     await expectNotDeleted()
 
-    await wait(15000)
-    await expectDeleted()
+    let continueWhile = true
+
+    do {
+      try {
+        await expectDeleted()
+        continueWhile = false
+      } catch {
+      }
+    } while (continueWhile)
   })
 
   after(async function () {