]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/shared/notifications.ts
Use displayName as label in channelFilters
[github/Chocobozzz/PeerTube.git] / server / tests / shared / notifications.ts
index 58d79d3aa1c492ec8281055939c30c1c52b0be92..6c0688d5aaf82e372d5c9e40fa23e8b66a88a614 100644 (file)
@@ -11,12 +11,14 @@ import {
   UserNotificationType
 } from '@shared/models'
 import {
+  ConfigCommand,
   createMultipleServers,
   doubleFollow,
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultAccountAvatar,
-  setDefaultChannelAvatar
+  setDefaultChannelAvatar,
+  setDefaultVideoChannel
 } from '@shared/server-commands'
 import { MockSmtpServer } from './mock-servers'
 
@@ -172,6 +174,8 @@ async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
   await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
 }
 
+// ---------------------------------------------------------------------------
+
 async function checkUserRegistered (options: CheckerBaseParams & {
   username: string
   checkType: CheckerType
@@ -184,7 +188,7 @@ async function checkUserRegistered (options: CheckerBaseParams & {
       expect(notification).to.not.be.undefined
       expect(notification.type).to.equal(notificationType)
 
-      checkActor(notification.account)
+      checkActor(notification.account, { withAvatar: false })
       expect(notification.account.name).to.equal(username)
     } else {
       expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
@@ -200,6 +204,36 @@ async function checkUserRegistered (options: CheckerBaseParams & {
   await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
 }
 
+async function checkRegistrationRequest (options: CheckerBaseParams & {
+  username: string
+  registrationReason: string
+  checkType: CheckerType
+}) {
+  const { username, registrationReason } = options
+  const notificationType = UserNotificationType.NEW_USER_REGISTRATION_REQUEST
+
+  function notificationChecker (notification: UserNotification, checkType: CheckerType) {
+    if (checkType === 'presence') {
+      expect(notification).to.not.be.undefined
+      expect(notification.type).to.equal(notificationType)
+
+      expect(notification.registration.username).to.equal(username)
+    } else {
+      expect(notification).to.satisfy(n => n.type !== notificationType || n.registration.username !== username)
+    }
+  }
+
+  function emailNotificationFinder (email: object) {
+    const text: string = email['text']
+
+    return text.includes(' wants to register ') && text.includes(username) && text.includes(registrationReason)
+  }
+
+  await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
+}
+
+// ---------------------------------------------------------------------------
+
 async function checkNewActorFollow (options: CheckerBaseParams & {
   followType: 'channel' | 'account'
   followerName: string
@@ -252,7 +286,7 @@ async function checkNewInstanceFollower (options: CheckerBaseParams & {
       expect(notification).to.not.be.undefined
       expect(notification.type).to.equal(notificationType)
 
-      checkActor(notification.actorFollow.follower)
+      checkActor(notification.actorFollow.follower, { withAvatar: false })
       expect(notification.actorFollow.follower.name).to.equal('peertube')
       expect(notification.actorFollow.follower.host).to.equal(followerHost)
 
@@ -287,7 +321,8 @@ async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
       expect(notification.type).to.equal(notificationType)
 
       const following = notification.actorFollow.following
-      checkActor(following)
+
+      checkActor(following, { withAvatar: false })
       expect(following.name).to.equal('peertube')
       expect(following.host).to.equal(followingHost)
 
@@ -369,7 +404,7 @@ async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
     }
   }
 
-  const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
+  const commentUrl = `${server.url}/w/${shortUUID};threadId=${threadId}`
 
   function emailNotificationFinder (email: object) {
     return email['text'].indexOf(commentUrl) !== -1
@@ -671,10 +706,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
   const port = await MockSmtpServer.Instance.collectEmails(emails)
 
   const overrideConfig = {
-    smtp: {
-      hostname: 'localhost',
-      port
-    },
+    ...ConfigCommand.getEmailOverrideConfig(port),
+
     signup: {
       limit: 20
     }
@@ -682,10 +715,14 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
   const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
 
   await setAccessTokensToServers(servers)
+  await setDefaultVideoChannel(servers)
   await setDefaultChannelAvatar(servers)
   await setDefaultAccountAvatar(servers)
 
-  if (servers[1]) await servers[1].config.enableStudio()
+  if (servers[1]) {
+    await servers[1].config.enableStudio()
+    await servers[1].config.enableLive({ allowReplay: true, transcoding: false })
+  }
 
   if (serversCount > 1) {
     await doubleFollow(servers[0], servers[1])
@@ -696,6 +733,9 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
   const userAccessToken = await servers[0].login.getAccessToken(user)
 
   await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
+  await servers[0].users.updateMyAvatar({ token: userAccessToken, fixture: 'avatar.png' })
+  await servers[0].channels.updateImage({ channelName: 'user_1_channel', token: userAccessToken, fixture: 'avatar.png', type: 'avatar' })
+
   await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
 
   if (serversCount > 1) {
@@ -726,7 +766,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
     userAccessToken,
     emails,
     servers,
-    channelId
+    channelId,
+    baseOverrideConfig: overrideConfig
   }
 }
 
@@ -756,7 +797,8 @@ export {
   checkNewAccountAbuseForModerators,
   checkNewPeerTubeVersion,
   checkNewPluginVersion,
-  checkVideoStudioEditionIsFinished
+  checkVideoStudioEditionIsFinished,
+  checkRegistrationRequest
 }
 
 // ---------------------------------------------------------------------------
@@ -771,7 +813,7 @@ async function checkNotification (options: CheckerBaseParams & {
   const check = options.check || { web: true, mail: true }
 
   if (check.web) {
-    const notification = await server.notifications.getLatest({ token: token })
+    const notification = await server.notifications.getLatest({ token })
 
     if (notification || checkType !== 'absence') {
       notificationChecker(notification, checkType)
@@ -827,10 +869,18 @@ function checkVideo (video: any, videoName?: string, shortUUID?: string) {
   expect(video.id).to.be.a('number')
 }
 
-function checkActor (actor: any) {
+function checkActor (actor: any, options: { withAvatar?: boolean } = {}) {
+  const { withAvatar = true } = options
+
   expect(actor.displayName).to.be.a('string')
   expect(actor.displayName).to.not.be.empty
   expect(actor.host).to.not.be.undefined
+
+  if (withAvatar) {
+    expect(actor.avatars).to.be.an('array')
+    expect(actor.avatars).to.have.lengthOf(2)
+    expect(actor.avatars[0].path).to.exist.and.not.empty
+  }
 }
 
 function checkComment (comment: any, commentId: number, threadId: number) {