]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/blocklist-notification.ts
Remove low timeouts
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist-notification.ts
index 4fb3c95f2ef18eca8326f609b0ef81862ab2f2c2..9c2863a58b5de17963bd61aa0421e973ab34e78c 100644 (file)
@@ -1,48 +1,27 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
-import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications'
-import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
-import { UserNotification, UserNotificationType } from '@shared/models'
+import { expect } from 'chai'
+import { UserNotificationType } from '@shared/models'
 import {
   cleanupTests,
-  createUser,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
-  uploadVideo,
-  userLogin
-} from '../../../../shared/extra-utils/index'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import {
-  addAccountToAccountBlocklist,
-  addAccountToServerBlocklist,
-  addServerToAccountBlocklist,
-  addServerToServerBlocklist,
-  removeAccountFromAccountBlocklist,
-  removeAccountFromServerBlocklist,
-  removeServerFromAccountBlocklist
-} from '../../../../shared/extra-utils/users/blocklist'
-import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
-import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
-
-const expect = chai.expect
-
-async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
-  const res = await getUserNotifications(url, token, 0, 10, true)
+  PeerTubeServer,
+  setAccessTokensToServers,
+  waitJobs
+} from '@shared/server-commands'
 
-  const notifications: UserNotification[] = res.body.data
-
-  expect(notifications).to.have.lengthOf(expected.length)
+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) {
-    expect(notifications.find(n => n.type === type)).to.exist
+    expect(data.find(n => n.type === type)).to.exist
   }
 }
 
-describe('Test blocklist', function () {
-  let servers: ServerInfo[]
+describe('Test blocklist notifications', function () {
+  let servers: PeerTubeServer[]
   let videoUUID: string
 
   let userToken1: string
@@ -51,30 +30,34 @@ describe('Test blocklist', function () {
 
   async function resetState () {
     try {
-      await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
-      await removeUserSubscription(servers[1].url, remoteUserToken, '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 markAsReadAllNotifications(servers[0].url, userToken1)
-    await markAsReadAllNotifications(servers[0].url, 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 addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
+      await servers[1].comments.createThread({
+        token: remoteUserToken,
+        videoId: videoUUID,
+        text: '@user2@' + servers[0].host + ' hello'
+      })
     }
 
     {
 
-      await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
-      await addUserSubscription(servers[1].url, remoteUserToken, '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)
@@ -83,36 +66,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])
@@ -128,26 +109,24 @@ describe('Test blocklist', function () {
 
     it('Should have appropriate notifications', async function () {
       const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
-      await checkNotifications(servers[0].url, userToken1, notifs)
+      await checkNotifications(servers[0], userToken1, notifs)
     })
 
     it('Should block an account', async function () {
-      this.timeout(10000)
-
-      await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
+      await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
       await waitJobs(servers)
     })
 
     it('Should not have notifications from this account', async function () {
-      await checkNotifications(servers[0].url, userToken1, [])
+      await checkNotifications(servers[0], userToken1, [])
     })
 
     it('Should have notifications of this account on user 2', async function () {
       const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
 
-      await checkNotifications(servers[0].url, userToken2, notifs)
+      await checkNotifications(servers[0], userToken2, notifs)
 
-      await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
+      await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
     })
   })
 
@@ -161,26 +140,24 @@ describe('Test blocklist', function () {
 
     it('Should have appropriate notifications', async function () {
       const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
-      await checkNotifications(servers[0].url, userToken1, notifs)
+      await checkNotifications(servers[0], userToken1, notifs)
     })
 
     it('Should block an account', async function () {
-      this.timeout(10000)
-
-      await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host)
+      await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
       await waitJobs(servers)
     })
 
     it('Should not have notifications from this account', async function () {
-      await checkNotifications(servers[0].url, userToken1, [])
+      await checkNotifications(servers[0], userToken1, [])
     })
 
     it('Should have notifications of this account on user 2', async function () {
       const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
 
-      await checkNotifications(servers[0].url, userToken2, notifs)
+      await checkNotifications(servers[0], userToken2, notifs)
 
-      await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host)
+      await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
     })
   })
 
@@ -195,27 +172,25 @@ describe('Test blocklist', function () {
     it('Should have appropriate notifications', async function () {
       {
         const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
-        await checkNotifications(servers[0].url, userToken1, notifs)
+        await checkNotifications(servers[0], userToken1, notifs)
       }
 
       {
         const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
-        await checkNotifications(servers[0].url, userToken2, notifs)
+        await checkNotifications(servers[0], userToken2, notifs)
       }
     })
 
     it('Should block an account', async function () {
-      this.timeout(10000)
-
-      await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
+      await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
       await waitJobs(servers)
     })
 
     it('Should not have notifications from this account', async function () {
-      await checkNotifications(servers[0].url, userToken1, [])
-      await checkNotifications(servers[0].url, userToken2, [])
+      await checkNotifications(servers[0], userToken1, [])
+      await checkNotifications(servers[0], userToken2, [])
 
-      await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
+      await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
     })
   })
 
@@ -230,25 +205,23 @@ describe('Test blocklist', function () {
     it('Should have appropriate notifications', async function () {
       {
         const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
-        await checkNotifications(servers[0].url, userToken1, notifs)
+        await checkNotifications(servers[0], userToken1, notifs)
       }
 
       {
         const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
-        await checkNotifications(servers[0].url, userToken2, notifs)
+        await checkNotifications(servers[0], userToken2, notifs)
       }
     })
 
     it('Should block an account', async function () {
-      this.timeout(10000)
-
-      await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
+      await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
       await waitJobs(servers)
     })
 
     it('Should not have notifications from this account', async function () {
-      await checkNotifications(servers[0].url, userToken1, [])
-      await checkNotifications(servers[0].url, userToken2, [])
+      await checkNotifications(servers[0], userToken1, [])
+      await checkNotifications(servers[0], userToken2, [])
     })
   })