aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 16:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitdd0ebb715123dfa126a82d4e4fe3a04064ae77b8 (patch)
treee0741f35b31c66f09f7d9ad808b224ef86151bb1 /server/tests/api/notifications
parent9293139fde7091e9badcafa9b570b83cea9a10ad (diff)
downloadPeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.gz
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.zst
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.zip
Introduce notifications command
Diffstat (limited to 'server/tests/api/notifications')
-rw-r--r--server/tests/api/notifications/notifications-api.ts92
-rw-r--r--server/tests/api/notifications/user-notifications.ts5
2 files changed, 48 insertions, 49 deletions
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index 1ed98ae7a..447492c5f 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -8,14 +8,10 @@ import {
8 cleanupTests, 8 cleanupTests,
9 getAllNotificationsSettings, 9 getAllNotificationsSettings,
10 getMyUserInformation, 10 getMyUserInformation,
11 getUserNotifications,
12 immutableAssign, 11 immutableAssign,
13 markAsReadAllNotifications,
14 markAsReadNotifications,
15 MockSmtpServer, 12 MockSmtpServer,
16 prepareNotificationsTest, 13 prepareNotificationsTest,
17 ServerInfo, 14 ServerInfo,
18 updateMyNotificationSettings,
19 uploadRandomVideo, 15 uploadRandomVideo,
20 waitJobs 16 waitJobs
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
@@ -26,7 +22,7 @@ const expect = chai.expect
26describe('Test notifications API', function () { 22describe('Test notifications API', function () {
27 let server: ServerInfo 23 let server: ServerInfo
28 let userNotifications: UserNotification[] = [] 24 let userNotifications: UserNotification[] = []
29 let userAccessToken: string 25 let userToken: string
30 let emails: object[] = [] 26 let emails: object[] = []
31 27
32 before(async function () { 28 before(async function () {
@@ -34,11 +30,11 @@ describe('Test notifications API', function () {
34 30
35 const res = await prepareNotificationsTest(1) 31 const res = await prepareNotificationsTest(1)
36 emails = res.emails 32 emails = res.emails
37 userAccessToken = res.userAccessToken 33 userToken = res.userAccessToken
38 userNotifications = res.userNotifications 34 userNotifications = res.userNotifications
39 server = res.servers[0] 35 server = res.servers[0]
40 36
41 await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) 37 await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
42 38
43 for (let i = 0; i < 10; i++) { 39 for (let i = 0; i < 10; i++) {
44 await uploadRandomVideo(server, false) 40 await uploadRandomVideo(server, false)
@@ -50,49 +46,46 @@ describe('Test notifications API', function () {
50 describe('Mark as read', function () { 46 describe('Mark as read', function () {
51 47
52 it('Should mark as read some notifications', async function () { 48 it('Should mark as read some notifications', async function () {
53 const res = await getUserNotifications(server.url, userAccessToken, 2, 3) 49 const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 })
54 const ids = res.body.data.map(n => n.id) 50 const ids = data.map(n => n.id)
55 51
56 await markAsReadNotifications(server.url, userAccessToken, ids) 52 await server.notificationsCommand.markAsRead({ token: userToken, ids })
57 }) 53 })
58 54
59 it('Should have the notifications marked as read', async function () { 55 it('Should have the notifications marked as read', async function () {
60 const res = await getUserNotifications(server.url, userAccessToken, 0, 10) 56 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 })
61 57
62 const notifications = res.body.data as UserNotification[] 58 expect(data[0].read).to.be.false
63 expect(notifications[0].read).to.be.false 59 expect(data[1].read).to.be.false
64 expect(notifications[1].read).to.be.false 60 expect(data[2].read).to.be.true
65 expect(notifications[2].read).to.be.true 61 expect(data[3].read).to.be.true
66 expect(notifications[3].read).to.be.true 62 expect(data[4].read).to.be.true
67 expect(notifications[4].read).to.be.true 63 expect(data[5].read).to.be.false
68 expect(notifications[5].read).to.be.false
69 }) 64 })
70 65
71 it('Should only list read notifications', async function () { 66 it('Should only list read notifications', async function () {
72 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) 67 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false })
73 68
74 const notifications = res.body.data as UserNotification[] 69 for (const notification of data) {
75 for (const notification of notifications) {
76 expect(notification.read).to.be.true 70 expect(notification.read).to.be.true
77 } 71 }
78 }) 72 })
79 73
80 it('Should only list unread notifications', async function () { 74 it('Should only list unread notifications', async function () {
81 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 75 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
82 76
83 const notifications = res.body.data as UserNotification[] 77 for (const notification of data) {
84 for (const notification of notifications) {
85 expect(notification.read).to.be.false 78 expect(notification.read).to.be.false
86 } 79 }
87 }) 80 })
88 81
89 it('Should mark as read all notifications', async function () { 82 it('Should mark as read all notifications', async function () {
90 await markAsReadAllNotifications(server.url, userAccessToken) 83 await server.notificationsCommand.markAsReadAll({ token: userToken })
91 84
92 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 85 const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
93 86
94 expect(res.body.total).to.equal(0) 87 expect(body.total).to.equal(0)
95 expect(res.body.data).to.have.lengthOf(0) 88 expect(body.data).to.have.lengthOf(0)
96 }) 89 })
97 }) 90 })
98 91
@@ -104,19 +97,20 @@ describe('Test notifications API', function () {
104 server: server, 97 server: server,
105 emails, 98 emails,
106 socketNotifications: userNotifications, 99 socketNotifications: userNotifications,
107 token: userAccessToken 100 token: userToken
108 } 101 }
109 }) 102 })
110 103
111 it('Should not have notifications', async function () { 104 it('Should not have notifications', async function () {
112 this.timeout(20000) 105 this.timeout(20000)
113 106
114 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 107 await server.notificationsCommand.updateMySettings({
115 newVideoFromSubscription: UserNotificationSettingValue.NONE 108 token: userToken,
116 })) 109 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
110 })
117 111
118 { 112 {
119 const res = await getMyUserInformation(server.url, userAccessToken) 113 const res = await getMyUserInformation(server.url, userToken)
120 const info = res.body as User 114 const info = res.body as User
121 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 115 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
122 } 116 }
@@ -130,12 +124,13 @@ describe('Test notifications API', function () {
130 it('Should only have web notifications', async function () { 124 it('Should only have web notifications', async function () {
131 this.timeout(20000) 125 this.timeout(20000)
132 126
133 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 127 await server.notificationsCommand.updateMySettings({
134 newVideoFromSubscription: UserNotificationSettingValue.WEB 128 token: userToken,
135 })) 129 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
130 })
136 131
137 { 132 {
138 const res = await getMyUserInformation(server.url, userAccessToken) 133 const res = await getMyUserInformation(server.url, userToken)
139 const info = res.body as User 134 const info = res.body as User
140 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 135 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
141 } 136 }
@@ -156,12 +151,13 @@ describe('Test notifications API', function () {
156 it('Should only have mail notifications', async function () { 151 it('Should only have mail notifications', async function () {
157 this.timeout(20000) 152 this.timeout(20000)
158 153
159 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 154 await server.notificationsCommand.updateMySettings({
160 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 155 token: userToken,
161 })) 156 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
157 })
162 158
163 { 159 {
164 const res = await getMyUserInformation(server.url, userAccessToken) 160 const res = await getMyUserInformation(server.url, userToken)
165 const info = res.body as User 161 const info = res.body as User
166 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 162 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
167 } 163 }
@@ -182,12 +178,16 @@ describe('Test notifications API', function () {
182 it('Should have email and web notifications', async function () { 178 it('Should have email and web notifications', async function () {
183 this.timeout(20000) 179 this.timeout(20000)
184 180
185 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 181 await server.notificationsCommand.updateMySettings({
186 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 182 token: userToken,
187 })) 183 settings: {
184 ...getAllNotificationsSettings(),
185 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
186 }
187 })
188 188
189 { 189 {
190 const res = await getMyUserInformation(server.url, userAccessToken) 190 const res = await getMyUserInformation(server.url, userToken)
191 const info = res.body as User 191 const info = res.body as User
192 expect(info.notificationSettings.newVideoFromSubscription).to.equal( 192 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
193 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 193 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 1d159c48f..4b31edf25 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -10,7 +10,6 @@ import {
10 checkNewVideoFromSubscription, 10 checkNewVideoFromSubscription,
11 checkVideoIsPublished, 11 checkVideoIsPublished,
12 cleanupTests, 12 cleanupTests,
13 getLastNotification,
14 ImportsCommand, 13 ImportsCommand,
15 MockSmtpServer, 14 MockSmtpServer,
16 prepareNotificationsTest, 15 prepareNotificationsTest,
@@ -64,7 +63,7 @@ describe('Test user notifications', function () {
64 63
65 await uploadRandomVideoOnServers(servers, 1) 64 await uploadRandomVideoOnServers(servers, 1)
66 65
67 const notification = await getLastNotification(servers[0].url, userAccessToken) 66 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
68 expect(notification).to.be.undefined 67 expect(notification).to.be.undefined
69 68
70 expect(emails).to.have.lengthOf(0) 69 expect(emails).to.have.lengthOf(0)
@@ -245,7 +244,7 @@ describe('Test user notifications', function () {
245 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) 244 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
246 await waitJobs(servers) 245 await waitJobs(servers)
247 246
248 const notification = await getLastNotification(servers[0].url, userAccessToken) 247 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
249 if (notification) { 248 if (notification) {
250 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) 249 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
251 } 250 }