]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/notifications/notifications-api.ts
Merge branch 'next' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / notifications-api.ts
index 447492c5f3676b348974db9df42d170b7a7871be..fa4b53db6c1f678e98ba085783479d71c4d0d5a1 100644 (file)
@@ -7,20 +7,17 @@ import {
   checkNewVideoFromSubscription,
   cleanupTests,
   getAllNotificationsSettings,
-  getMyUserInformation,
-  immutableAssign,
   MockSmtpServer,
+  PeerTubeServer,
   prepareNotificationsTest,
-  ServerInfo,
-  uploadRandomVideo,
   waitJobs
 } from '@shared/extra-utils'
-import { User, UserNotification, UserNotificationSettingValue } from '@shared/models'
+import { UserNotification, UserNotificationSettingValue } from '@shared/models'
 
 const expect = chai.expect
 
 describe('Test notifications API', function () {
-  let server: ServerInfo
+  let server: PeerTubeServer
   let userNotifications: UserNotification[] = []
   let userToken: string
   let emails: object[] = []
@@ -34,10 +31,10 @@ describe('Test notifications API', function () {
     userNotifications = res.userNotifications
     server = res.servers[0]
 
-    await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
+    await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
 
     for (let i = 0; i < 10; i++) {
-      await uploadRandomVideo(server, false)
+      await server.videos.randomUpload({ wait: false })
     }
 
     await waitJobs([ server ])
@@ -46,14 +43,14 @@ describe('Test notifications API', function () {
   describe('Mark as read', function () {
 
     it('Should mark as read some notifications', async function () {
-      const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 })
+      const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 })
       const ids = data.map(n => n.id)
 
-      await server.notificationsCommand.markAsRead({ token: userToken, ids })
+      await server.notifications.markAsRead({ token: userToken, ids })
     })
 
     it('Should have the notifications marked as read', async function () {
-      const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 })
+      const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 })
 
       expect(data[0].read).to.be.false
       expect(data[1].read).to.be.false
@@ -64,7 +61,7 @@ describe('Test notifications API', function () {
     })
 
     it('Should only list read notifications', async function () {
-      const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false })
+      const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false })
 
       for (const notification of data) {
         expect(notification.read).to.be.true
@@ -72,7 +69,7 @@ describe('Test notifications API', function () {
     })
 
     it('Should only list unread notifications', async function () {
-      const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
+      const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
 
       for (const notification of data) {
         expect(notification.read).to.be.false
@@ -80,9 +77,9 @@ describe('Test notifications API', function () {
     })
 
     it('Should mark as read all notifications', async function () {
-      await server.notificationsCommand.markAsReadAll({ token: userToken })
+      await server.notifications.markAsReadAll({ token: userToken })
 
-      const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
+      const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
 
       expect(body.total).to.equal(0)
       expect(body.data).to.have.lengthOf(0)
@@ -104,81 +101,78 @@ describe('Test notifications API', function () {
     it('Should not have notifications', async function () {
       this.timeout(20000)
 
-      await server.notificationsCommand.updateMySettings({
+      await server.notifications.updateMySettings({
         token: userToken,
         settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
       })
 
       {
-        const res = await getMyUserInformation(server.url, userToken)
-        const info = res.body as User
+        const info = await server.users.getMyInfo({ token: userToken })
         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
       }
 
-      const { name, uuid } = await uploadRandomVideo(server)
+      const { name, uuid } = await server.videos.randomUpload()
 
       const check = { web: true, mail: true }
-      await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
+      await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
     })
 
     it('Should only have web notifications', async function () {
       this.timeout(20000)
 
-      await server.notificationsCommand.updateMySettings({
+      await server.notifications.updateMySettings({
         token: userToken,
         settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
       })
 
       {
-        const res = await getMyUserInformation(server.url, userToken)
-        const info = res.body as User
+        const info = await server.users.getMyInfo({ token: userToken })
         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
       }
 
-      const { name, uuid } = await uploadRandomVideo(server)
+      const { name, uuid } = await server.videos.randomUpload()
 
       {
         const check = { mail: true, web: false }
-        await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
+        await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
       }
 
       {
         const check = { mail: false, web: true }
-        await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
+        await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
       }
     })
 
     it('Should only have mail notifications', async function () {
       this.timeout(20000)
 
-      await server.notificationsCommand.updateMySettings({
+      await server.notifications.updateMySettings({
         token: userToken,
         settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
       })
 
       {
-        const res = await getMyUserInformation(server.url, userToken)
-        const info = res.body as User
+        const info = await server.users.getMyInfo({ token: userToken })
         expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
       }
 
-      const { name, uuid } = await uploadRandomVideo(server)
+      const { name, uuid } = await server.videos.randomUpload()
 
       {
         const check = { mail: false, web: true }
-        await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence')
+        await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
       }
 
       {
         const check = { mail: true, web: false }
-        await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence')
+        await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
       }
     })
 
     it('Should have email and web notifications', async function () {
       this.timeout(20000)
 
-      await server.notificationsCommand.updateMySettings({
+      await server.notifications.updateMySettings({
         token: userToken,
         settings: {
           ...getAllNotificationsSettings(),
@@ -187,14 +181,13 @@ describe('Test notifications API', function () {
       })
 
       {
-        const res = await getMyUserInformation(server.url, userToken)
-        const info = res.body as User
+        const info = await server.users.getMyInfo({ token: userToken })
         expect(info.notificationSettings.newVideoFromSubscription).to.equal(
           UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
         )
       }
 
-      const { name, uuid } = await uploadRandomVideo(server)
+      const { name, uuid } = await server.videos.randomUpload()
 
       await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
     })