aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts47
-rw-r--r--server/tests/api/moderation/blocklist.ts28
2 files changed, 32 insertions, 43 deletions
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index a077d8739..b676a4db4 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -7,27 +7,22 @@ import {
7 createUser, 7 createUser,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getUserNotifications,
11 markAsReadAllNotifications,
12 ServerInfo, 10 ServerInfo,
13 setAccessTokensToServers, 11 setAccessTokensToServers,
14 uploadVideo, 12 uploadVideo,
15 userLogin, 13 userLogin,
16 waitJobs 14 waitJobs
17} from '@shared/extra-utils' 15} from '@shared/extra-utils'
18import { UserNotification, UserNotificationType } from '@shared/models' 16import { UserNotificationType } from '@shared/models'
19 17
20const expect = chai.expect 18const expect = chai.expect
21 19
22async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { 20async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
23 const res = await getUserNotifications(url, token, 0, 10, true) 21 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
24 22 expect(data).to.have.lengthOf(expected.length)
25 const notifications: UserNotification[] = res.body.data
26
27 expect(notifications).to.have.lengthOf(expected.length)
28 23
29 for (const type of expected) { 24 for (const type of expected) {
30 expect(notifications.find(n => n.type === type)).to.exist 25 expect(data.find(n => n.type === type)).to.exist
31 } 26 }
32} 27}
33 28
@@ -47,8 +42,8 @@ describe('Test blocklist', function () {
47 42
48 await waitJobs(servers) 43 await waitJobs(servers)
49 44
50 await markAsReadAllNotifications(servers[0].url, userToken1) 45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
51 await markAsReadAllNotifications(servers[0].url, userToken2) 46 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
52 47
53 { 48 {
54 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) 49 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
@@ -122,7 +117,7 @@ describe('Test blocklist', function () {
122 117
123 it('Should have appropriate notifications', async function () { 118 it('Should have appropriate notifications', async function () {
124 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 119 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
125 await checkNotifications(servers[0].url, userToken1, notifs) 120 await checkNotifications(servers[0], userToken1, notifs)
126 }) 121 })
127 122
128 it('Should block an account', async function () { 123 it('Should block an account', async function () {
@@ -133,13 +128,13 @@ describe('Test blocklist', function () {
133 }) 128 })
134 129
135 it('Should not have notifications from this account', async function () { 130 it('Should not have notifications from this account', async function () {
136 await checkNotifications(servers[0].url, userToken1, []) 131 await checkNotifications(servers[0], userToken1, [])
137 }) 132 })
138 133
139 it('Should have notifications of this account on user 2', async function () { 134 it('Should have notifications of this account on user 2', async function () {
140 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 135 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
141 136
142 await checkNotifications(servers[0].url, userToken2, notifs) 137 await checkNotifications(servers[0], userToken2, notifs)
143 138
144 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) 139 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
145 }) 140 })
@@ -155,7 +150,7 @@ describe('Test blocklist', function () {
155 150
156 it('Should have appropriate notifications', async function () { 151 it('Should have appropriate notifications', async function () {
157 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 152 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
158 await checkNotifications(servers[0].url, userToken1, notifs) 153 await checkNotifications(servers[0], userToken1, notifs)
159 }) 154 })
160 155
161 it('Should block an account', async function () { 156 it('Should block an account', async function () {
@@ -166,13 +161,13 @@ describe('Test blocklist', function () {
166 }) 161 })
167 162
168 it('Should not have notifications from this account', async function () { 163 it('Should not have notifications from this account', async function () {
169 await checkNotifications(servers[0].url, userToken1, []) 164 await checkNotifications(servers[0], userToken1, [])
170 }) 165 })
171 166
172 it('Should have notifications of this account on user 2', async function () { 167 it('Should have notifications of this account on user 2', async function () {
173 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 168 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
174 169
175 await checkNotifications(servers[0].url, userToken2, notifs) 170 await checkNotifications(servers[0], userToken2, notifs)
176 171
177 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) 172 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
178 }) 173 })
@@ -189,12 +184,12 @@ describe('Test blocklist', function () {
189 it('Should have appropriate notifications', async function () { 184 it('Should have appropriate notifications', async function () {
190 { 185 {
191 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 186 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
192 await checkNotifications(servers[0].url, userToken1, notifs) 187 await checkNotifications(servers[0], userToken1, notifs)
193 } 188 }
194 189
195 { 190 {
196 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 191 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
197 await checkNotifications(servers[0].url, userToken2, notifs) 192 await checkNotifications(servers[0], userToken2, notifs)
198 } 193 }
199 }) 194 })
200 195
@@ -206,8 +201,8 @@ describe('Test blocklist', function () {
206 }) 201 })
207 202
208 it('Should not have notifications from this account', async function () { 203 it('Should not have notifications from this account', async function () {
209 await checkNotifications(servers[0].url, userToken1, []) 204 await checkNotifications(servers[0], userToken1, [])
210 await checkNotifications(servers[0].url, userToken2, []) 205 await checkNotifications(servers[0], userToken2, [])
211 206
212 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) 207 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
213 }) 208 })
@@ -224,12 +219,12 @@ describe('Test blocklist', function () {
224 it('Should have appropriate notifications', async function () { 219 it('Should have appropriate notifications', async function () {
225 { 220 {
226 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 221 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
227 await checkNotifications(servers[0].url, userToken1, notifs) 222 await checkNotifications(servers[0], userToken1, notifs)
228 } 223 }
229 224
230 { 225 {
231 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 226 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
232 await checkNotifications(servers[0].url, userToken2, notifs) 227 await checkNotifications(servers[0], userToken2, notifs)
233 } 228 }
234 }) 229 })
235 230
@@ -241,8 +236,8 @@ describe('Test blocklist', function () {
241 }) 236 })
242 237
243 it('Should not have notifications from this account', async function () { 238 it('Should not have notifications from this account', async function () {
244 await checkNotifications(servers[0].url, userToken1, []) 239 await checkNotifications(servers[0], userToken1, [])
245 await checkNotifications(servers[0].url, userToken2, []) 240 await checkNotifications(servers[0], userToken2, [])
246 }) 241 })
247 }) 242 })
248 243
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 00cb6c65c..44e3de4e4 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -9,7 +9,6 @@ import {
9 createUser, 9 createUser,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 getUserNotifications,
13 getVideosList, 12 getVideosList,
14 getVideosListWithToken, 13 getVideosListWithToken,
15 ServerInfo, 14 ServerInfo,
@@ -18,7 +17,7 @@ import {
18 userLogin, 17 userLogin,
19 waitJobs 18 waitJobs
20} from '@shared/extra-utils' 19} from '@shared/extra-utils'
21import { UserNotification, UserNotificationType, Video } from '@shared/models' 20import { UserNotificationType, Video } from '@shared/models'
22 21
23const expect = chai.expect 22const expect = chai.expect
24 23
@@ -59,9 +58,8 @@ async function checkCommentNotification (
59 58
60 await waitJobs([ mainServer, comment.server ]) 59 await waitJobs([ mainServer, comment.server ])
61 60
62 const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) 61 const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 })
63 const commentNotifications = (res.body.data as UserNotification[]) 62 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
64 .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
65 63
66 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) 64 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
67 else expect(commentNotifications).to.have.lengthOf(0) 65 else expect(commentNotifications).to.have.lengthOf(0)
@@ -710,12 +708,10 @@ describe('Test blocklist', function () {
710 708
711 await waitJobs(servers) 709 await waitJobs(servers)
712 710
713 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 711 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
714 const commentNotifications = (res.body.data as UserNotification[]) 712 const commentNotifications = data.filter(n => {
715 .filter(n => { 713 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
716 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 714 })
717 n.createdAt >= now.toISOString()
718 })
719 715
720 expect(commentNotifications).to.have.lengthOf(0) 716 expect(commentNotifications).to.have.lengthOf(0)
721 } 717 }
@@ -773,12 +769,10 @@ describe('Test blocklist', function () {
773 769
774 await waitJobs(servers) 770 await waitJobs(servers)
775 771
776 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 772 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
777 const commentNotifications = (res.body.data as UserNotification[]) 773 const commentNotifications = data.filter(n => {
778 .filter(n => { 774 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
779 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 775 })
780 n.createdAt >= now.toISOString()
781 })
782 776
783 expect(commentNotifications).to.have.lengthOf(1) 777 expect(commentNotifications).to.have.lengthOf(1)
784 } 778 }