]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/users/notifications.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / notifications.ts
index 81f0729fa9a2d0415fe840946d01527a99334405..4c42fad3eea2f23fc139f02c0990e0df5998cd74 100644 (file)
@@ -5,10 +5,10 @@ import { inspect } from 'util'
 import { AbuseState, PluginType } from '@shared/models'
 import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users'
 import { MockSmtpServer } from '../mock-servers/mock-email'
+import { PeerTubeServer } from '../server'
 import { doubleFollow } from '../server/follows'
-import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
-import { setAccessTokensToServers, userLogin } from './login'
-import { createUser, getMyUserInformation } from './users'
+import { createMultipleServers } from '../server/servers'
+import { setAccessTokensToServers } from './login'
 
 function getAllNotificationsSettings (): UserNotificationSetting {
   return {
@@ -32,7 +32,7 @@ function getAllNotificationsSettings (): UserNotificationSetting {
 }
 
 type CheckerBaseParams = {
-  server: ServerInfo
+  server: PeerTubeServer
   emails: any[]
   socketNotifications: UserNotification[]
   token: string
@@ -50,7 +50,7 @@ async function checkNotification (
   const check = base.check || { web: true, mail: true }
 
   if (check.web) {
-    const notification = await base.server.notificationsCommand.getLastest({ token: base.token })
+    const notification = await base.server.notifications.getLastest({ token: base.token })
 
     if (notification || checkType !== 'absence') {
       notificationChecker(notification, checkType)
@@ -643,7 +643,7 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
       limit: 20
     }
   }
-  const servers = await flushAndRunMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
+  const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
 
   await setAccessTokensToServers(servers)
 
@@ -651,42 +651,33 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
     await doubleFollow(servers[0], servers[1])
   }
 
-  const user = {
-    username: 'user_1',
-    password: 'super password'
-  }
-  await createUser({
-    url: servers[0].url,
-    accessToken: servers[0].accessToken,
-    username: user.username,
-    password: user.password,
-    videoQuota: 10 * 1000 * 1000
-  })
-  const userAccessToken = await userLogin(servers[0], user)
+  const user = { username: 'user_1', password: 'super password' }
+  await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 })
+  const userAccessToken = await servers[0].login.getAccessToken(user)
 
-  await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
-  await servers[0].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
+  await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
+  await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
 
   if (serversCount > 1) {
-    await servers[1].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() })
+    await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
   }
 
   {
-    const socket = servers[0].socketIOCommand.getUserNotificationSocket({ token: userAccessToken })
+    const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken })
     socket.on('new-notification', n => userNotifications.push(n))
   }
   {
-    const socket = servers[0].socketIOCommand.getUserNotificationSocket()
+    const socket = servers[0].socketIO.getUserNotificationSocket()
     socket.on('new-notification', n => adminNotifications.push(n))
   }
 
   if (serversCount > 1) {
-    const socket = servers[1].socketIOCommand.getUserNotificationSocket()
+    const socket = servers[1].socketIO.getUserNotificationSocket()
     socket.on('new-notification', n => adminNotificationsServer2.push(n))
   }
 
-  const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
-  const channelId = resChannel.body.videoChannels[0].id
+  const { videoChannels } = await servers[0].users.getMyInfo()
+  const channelId = videoChannels[0].id
 
   return {
     userNotifications,