]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/blocklist-notification.ts
Introduce user command
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist-notification.ts
index 5b9699816630610b7ebfb1f62f93bfbb3f727896..b44bcb012423d366e5e75260024d1bb1c7de71dc 100644 (file)
@@ -3,32 +3,24 @@
 import 'mocha'
 import * as chai from 'chai'
 import {
-  addVideoCommentThread,
   cleanupTests,
-  createUser,
   doubleFollow,
   flushAndRunMultipleServers,
-  getUserNotifications,
-  markAsReadAllNotifications,
   ServerInfo,
   setAccessTokensToServers,
   uploadVideo,
-  userLogin,
   waitJobs
 } from '@shared/extra-utils'
-import { UserNotification, UserNotificationType } from '@shared/models'
+import { UserNotificationType } from '@shared/models'
 
 const expect = chai.expect
 
-async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
-  const res = await getUserNotifications(url, token, 0, 10, true)
-
-  const notifications: UserNotification[] = res.body.data
-
-  expect(notifications).to.have.lengthOf(expected.length)
+async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
+  const { data } = await server.notificationsCommand.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
   }
 }
 
@@ -48,8 +40,8 @@ describe('Test blocklist', function () {
 
     await waitJobs(servers)
 
-    await markAsReadAllNotifications(servers[0].url, userToken1)
-    await markAsReadAllNotifications(servers[0].url, userToken2)
+    await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
+    await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
 
     {
       const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
@@ -59,7 +51,11 @@ describe('Test blocklist', function () {
     }
 
     {
-      await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
+      await servers[1].commentsCommand.createThread({
+        token: remoteUserToken,
+        videoId: videoUUID,
+        text: '@user2@' + servers[0].host + ' hello'
+      })
     }
 
     {
@@ -79,31 +75,29 @@ describe('Test blocklist', function () {
 
     {
       const user = { username: 'user1', password: 'password' }
-      await createUser({
-        url: servers[0].url,
-        accessToken: servers[0].accessToken,
+      await servers[0].usersCommand.create({
         username: user.username,
         password: user.password,
         videoQuota: -1,
         videoQuotaDaily: -1
       })
 
-      userToken1 = await userLogin(servers[0], user)
+      userToken1 = await servers[0].loginCommand.getAccessToken(user)
       await uploadVideo(servers[0].url, userToken1, { 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].usersCommand.create({ username: user.username, password: user.password })
 
-      userToken2 = await userLogin(servers[0], user)
+      userToken2 = await servers[0].loginCommand.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].usersCommand.create({ username: user.username, password: user.password })
 
-      remoteUserToken = await userLogin(servers[1], user)
+      remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
     }
 
     await doubleFollow(servers[0], servers[1])
@@ -119,7 +113,7 @@ 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 () {
@@ -130,13 +124,13 @@ describe('Test blocklist', function () {
     })
 
     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 servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
     })
@@ -152,7 +146,7 @@ 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 () {
@@ -163,13 +157,13 @@ describe('Test blocklist', function () {
     })
 
     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 servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
     })
@@ -186,12 +180,12 @@ 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)
       }
     })
 
@@ -203,8 +197,8 @@ describe('Test blocklist', function () {
     })
 
     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 servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
     })
@@ -221,12 +215,12 @@ 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)
       }
     })
 
@@ -238,8 +232,8 @@ describe('Test blocklist', function () {
     })
 
     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, [])
     })
   })