]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users/blocklist.ts
Add plugin hook on registration
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / blocklist.ts
index 99fe04b8c0de1376f61c2d05e5158622777390b3..c25e85ada6039edfbfc08eb684c5649dab3b443d 100644 (file)
@@ -4,6 +4,7 @@ import * as chai from 'chai'
 import 'mocha'
 import { AccountBlock, ServerBlock, Video } from '../../../../shared/index'
 import {
+  cleanupTests,
   createUser,
   doubleFollow,
   flushAndRunMultipleServers,
@@ -12,16 +13,16 @@ import {
   ServerInfo,
   uploadVideo,
   userLogin
-} from '../../utils/index'
-import { setAccessTokensToServers } from '../../utils/users/login'
-import { getVideosListWithToken } from '../../utils/videos/videos'
+} from '../../../../shared/extra-utils/index'
+import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
+import { getVideosListWithToken, getVideosList } from '../../../../shared/extra-utils/videos/videos'
 import {
   addVideoCommentReply,
   addVideoCommentThread,
   getVideoCommentThreads,
   getVideoThreadComments
-} from '../../utils/videos/video-comments'
-import { waitJobs } from '../../utils/server/jobs'
+} from '../../../../shared/extra-utils/videos/video-comments'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
 import {
   addAccountToAccountBlocklist,
@@ -36,14 +37,22 @@ import {
   removeAccountFromServerBlocklist,
   removeServerFromAccountBlocklist,
   removeServerFromServerBlocklist
-} from '../../utils/users/blocklist'
+} from '../../../../shared/extra-utils/users/blocklist'
 
 const expect = chai.expect
 
 async function checkAllVideos (url: string, token: string) {
-  const res = await getVideosListWithToken(url, token)
+  {
+    const res = await getVideosListWithToken(url, token)
 
-  expect(res.body.data).to.have.lengthOf(4)
+    expect(res.body.data).to.have.lengthOf(4)
+  }
+
+  {
+    const res = await getVideosList(url)
+
+    expect(res.body.data).to.have.lengthOf(4)
+  }
 }
 
 async function checkAllComments (url: string, token: string, videoUUID: string) {
@@ -71,14 +80,12 @@ describe('Test blocklist', function () {
   before(async function () {
     this.timeout(60000)
 
-    await flushTests()
-
     servers = await flushAndRunMultipleServers(2)
     await setAccessTokensToServers(servers)
 
     {
       const user = { username: 'user1', password: 'password' }
-      await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
+      await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
 
       userToken1 = await userLogin(servers[0], user)
       await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@@ -86,14 +93,14 @@ describe('Test blocklist', function () {
 
     {
       const user = { username: 'moderator', password: 'password' }
-      await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
+      await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
 
       userModeratorToken = await userLogin(servers[0], user)
     }
 
     {
       const user = { username: 'user2', password: 'password' }
-      await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
+      await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
 
       userToken2 = await userLogin(servers[1], user)
       await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
@@ -137,7 +144,7 @@ describe('Test blocklist', function () {
       })
 
       it('Should block a remote account', async function () {
-        await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
+        await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port)
       })
 
       it('Should hide its videos', async function () {
@@ -202,7 +209,7 @@ describe('Test blocklist', function () {
           expect(block.byAccount.name).to.equal('root')
           expect(block.blockedAccount.displayName).to.equal('user2')
           expect(block.blockedAccount.name).to.equal('user2')
-          expect(block.blockedAccount.host).to.equal('localhost:9002')
+          expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
         }
 
         {
@@ -216,12 +223,12 @@ describe('Test blocklist', function () {
           expect(block.byAccount.name).to.equal('root')
           expect(block.blockedAccount.displayName).to.equal('user1')
           expect(block.blockedAccount.name).to.equal('user1')
-          expect(block.blockedAccount.host).to.equal('localhost:9001')
+          expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
         }
       })
 
       it('Should unblock the remote account', async function () {
-        await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
+        await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port)
       })
 
       it('Should display its videos', async function () {
@@ -253,7 +260,7 @@ describe('Test blocklist', function () {
       })
 
       it('Should block a remote server', async function () {
-        await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
+        await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
       })
 
       it('Should hide its videos', async function () {
@@ -284,11 +291,11 @@ describe('Test blocklist', function () {
         const block = blocks[ 0 ]
         expect(block.byAccount.displayName).to.equal('root')
         expect(block.byAccount.name).to.equal('root')
-        expect(block.blockedServer.host).to.equal('localhost:9002')
+        expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
       it('Should unblock the remote server', async function () {
-        await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
+        await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
       })
 
       it('Should display its videos', function () {
@@ -317,7 +324,7 @@ describe('Test blocklist', function () {
       })
 
       it('Should block a remote account', async function () {
-        await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
+        await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port)
       })
 
       it('Should hide its videos', async function () {
@@ -380,7 +387,7 @@ describe('Test blocklist', function () {
           expect(block.byAccount.name).to.equal('peertube')
           expect(block.blockedAccount.displayName).to.equal('user2')
           expect(block.blockedAccount.name).to.equal('user2')
-          expect(block.blockedAccount.host).to.equal('localhost:9002')
+          expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
         }
 
         {
@@ -394,12 +401,12 @@ describe('Test blocklist', function () {
           expect(block.byAccount.name).to.equal('peertube')
           expect(block.blockedAccount.displayName).to.equal('user1')
           expect(block.blockedAccount.name).to.equal('user1')
-          expect(block.blockedAccount.host).to.equal('localhost:9001')
+          expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
         }
       })
 
       it('Should unblock the remote account', async function () {
-        await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002')
+        await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:' + servers[1].port)
       })
 
       it('Should display its videos', async function () {
@@ -439,21 +446,24 @@ describe('Test blocklist', function () {
       })
 
       it('Should block a remote server', async function () {
-        await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
+        await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
       })
 
       it('Should hide its videos', async function () {
         for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) {
-          const res = await getVideosListWithToken(servers[ 0 ].url, token)
+          const res1 = await getVideosList(servers[ 0 ].url)
+          const res2 = await getVideosListWithToken(servers[ 0 ].url, token)
 
-          const videos: Video[] = res.body.data
-          expect(videos).to.have.lengthOf(2)
+          for (const res of [ res1, res2 ]) {
+            const videos: Video[] = res.body.data
+            expect(videos).to.have.lengthOf(2)
 
-          const v1 = videos.find(v => v.name === 'video user 2')
-          const v2 = videos.find(v => v.name === 'video server 2')
+            const v1 = videos.find(v => v.name === 'video user 2')
+            const v2 = videos.find(v => v.name === 'video server 2')
 
-          expect(v1).to.be.undefined
-          expect(v2).to.be.undefined
+            expect(v1).to.be.undefined
+            expect(v2).to.be.undefined
+          }
         }
       })
 
@@ -468,11 +478,11 @@ describe('Test blocklist', function () {
         const block = blocks[ 0 ]
         expect(block.byAccount.displayName).to.equal('peertube')
         expect(block.byAccount.name).to.equal('peertube')
-        expect(block.blockedServer.host).to.equal('localhost:9002')
+        expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
       it('Should unblock the remote server', async function () {
-        await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002')
+        await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
       })
 
       it('Should list all videos', async function () {
@@ -490,11 +500,6 @@ describe('Test blocklist', function () {
   })
 
   after(async function () {
-    killallServers(servers)
-
-    // Keep the logs if the test failed
-    if (this[ 'ok' ]) {
-      await flushTests()
-    }
+    await cleanupTests(servers)
   })
 })