]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/blocklist-notification.ts
Add mute status in account and channel pages
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist-notification.ts
index b676a4db46f29500c23ceee1826b20fc84ae2b27..75b15c298729d793184f3b6e665edc157f3d3c1e 100644 (file)
@@ -2,23 +2,13 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import {
-  cleanupTests,
-  createUser,
-  doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
-  setAccessTokensToServers,
-  uploadVideo,
-  userLogin,
-  waitJobs
-} from '@shared/extra-utils'
+import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
 import { UserNotificationType } from '@shared/models'
 
 const expect = chai.expect
 
-async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
-  const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
+async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) {
+  const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true })
   expect(data).to.have.lengthOf(expected.length)
 
   for (const type of expected) {
@@ -27,7 +17,7 @@ async function checkNotifications (server: ServerInfo, token: string, expected:
 }
 
 describe('Test blocklist', function () {
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let videoUUID: string
 
   let userToken1: string
@@ -36,24 +26,24 @@ describe('Test blocklist', function () {
 
   async function resetState () {
     try {
-      await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
-      await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
+      await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
+      await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
     } catch {}
 
     await waitJobs(servers)
 
-    await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
-    await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
+    await servers[0].notifications.markAsReadAll({ token: userToken1 })
+    await servers[0].notifications.markAsReadAll({ token: userToken2 })
 
     {
-      const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
-      videoUUID = res.body.video.uuid
+      const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } })
+      videoUUID = uuid
 
       await waitJobs(servers)
     }
 
     {
-      await servers[1].commentsCommand.createThread({
+      await servers[1].comments.createThread({
         token: remoteUserToken,
         videoId: videoUUID,
         text: '@user2@' + servers[0].host + ' hello'
@@ -62,8 +52,8 @@ describe('Test blocklist', function () {
 
     {
 
-      await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
-      await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
+      await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
+      await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
     }
 
     await waitJobs(servers)
@@ -72,36 +62,34 @@ describe('Test blocklist', function () {
   before(async function () {
     this.timeout(60000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
     await setAccessTokensToServers(servers)
 
     {
       const user = { username: 'user1', password: 'password' }
-      await createUser({
-        url: servers[0].url,
-        accessToken: servers[0].accessToken,
+      await servers[0].users.create({
         username: user.username,
         password: user.password,
         videoQuota: -1,
         videoQuotaDaily: -1
       })
 
-      userToken1 = await userLogin(servers[0], user)
-      await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
+      userToken1 = await servers[0].login.getAccessToken(user)
+      await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
     }
 
     {
       const user = { username: 'user2', password: 'password' }
-      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+      await servers[0].users.create({ username: user.username, password: user.password })
 
-      userToken2 = await userLogin(servers[0], user)
+      userToken2 = await servers[0].login.getAccessToken(user)
     }
 
     {
       const user = { username: 'user3', password: 'password' }
-      await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+      await servers[1].users.create({ username: user.username, password: user.password })
 
-      remoteUserToken = await userLogin(servers[1], user)
+      remoteUserToken = await servers[1].login.getAccessToken(user)
     }
 
     await doubleFollow(servers[0], servers[1])
@@ -123,7 +111,7 @@ describe('Test blocklist', function () {
     it('Should block an account', async function () {
       this.timeout(10000)
 
-      await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
+      await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
       await waitJobs(servers)
     })
 
@@ -136,7 +124,7 @@ describe('Test blocklist', function () {
 
       await checkNotifications(servers[0], userToken2, notifs)
 
-      await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
+      await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
     })
   })
 
@@ -156,7 +144,7 @@ describe('Test blocklist', function () {
     it('Should block an account', async function () {
       this.timeout(10000)
 
-      await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
+      await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
       await waitJobs(servers)
     })
 
@@ -169,7 +157,7 @@ describe('Test blocklist', function () {
 
       await checkNotifications(servers[0], userToken2, notifs)
 
-      await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
+      await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
     })
   })
 
@@ -196,7 +184,7 @@ describe('Test blocklist', function () {
     it('Should block an account', async function () {
       this.timeout(10000)
 
-      await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
+      await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
       await waitJobs(servers)
     })
 
@@ -204,7 +192,7 @@ describe('Test blocklist', function () {
       await checkNotifications(servers[0], userToken1, [])
       await checkNotifications(servers[0], userToken2, [])
 
-      await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
+      await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
     })
   })
 
@@ -231,7 +219,7 @@ describe('Test blocklist', function () {
     it('Should block an account', async function () {
       this.timeout(10000)
 
-      await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
+      await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
       await waitJobs(servers)
     })