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.ts258
-rw-r--r--server/tests/api/moderation/index.ts1
2 files changed, 259 insertions, 0 deletions
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
new file mode 100644
index 000000000..4fb3c95f2
--- /dev/null
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -0,0 +1,258 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications'
6import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
7import { UserNotification, UserNotificationType } from '@shared/models'
8import {
9 cleanupTests,
10 createUser,
11 doubleFollow,
12 flushAndRunMultipleServers,
13 ServerInfo,
14 uploadVideo,
15 userLogin
16} from '../../../../shared/extra-utils/index'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import {
19 addAccountToAccountBlocklist,
20 addAccountToServerBlocklist,
21 addServerToAccountBlocklist,
22 addServerToServerBlocklist,
23 removeAccountFromAccountBlocklist,
24 removeAccountFromServerBlocklist,
25 removeServerFromAccountBlocklist
26} from '../../../../shared/extra-utils/users/blocklist'
27import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
28import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
29
30const expect = chai.expect
31
32async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
33 const res = await getUserNotifications(url, token, 0, 10, true)
34
35 const notifications: UserNotification[] = res.body.data
36
37 expect(notifications).to.have.lengthOf(expected.length)
38
39 for (const type of expected) {
40 expect(notifications.find(n => n.type === type)).to.exist
41 }
42}
43
44describe('Test blocklist', function () {
45 let servers: ServerInfo[]
46 let videoUUID: string
47
48 let userToken1: string
49 let userToken2: string
50 let remoteUserToken: string
51
52 async function resetState () {
53 try {
54 await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
55 await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
56 } catch {}
57
58 await waitJobs(servers)
59
60 await markAsReadAllNotifications(servers[0].url, userToken1)
61 await markAsReadAllNotifications(servers[0].url, userToken2)
62
63 {
64 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
65 videoUUID = res.body.video.uuid
66
67 await waitJobs(servers)
68 }
69
70 {
71 await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
72 }
73
74 {
75
76 await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
77 await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
78 }
79
80 await waitJobs(servers)
81 }
82
83 before(async function () {
84 this.timeout(60000)
85
86 servers = await flushAndRunMultipleServers(2)
87 await setAccessTokensToServers(servers)
88
89 {
90 const user = { username: 'user1', password: 'password' }
91 await createUser({
92 url: servers[0].url,
93 accessToken: servers[0].accessToken,
94 username: user.username,
95 password: user.password,
96 videoQuota: -1,
97 videoQuotaDaily: -1
98 })
99
100 userToken1 = await userLogin(servers[0], user)
101 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
102 }
103
104 {
105 const user = { username: 'user2', password: 'password' }
106 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
107
108 userToken2 = await userLogin(servers[0], user)
109 }
110
111 {
112 const user = { username: 'user3', password: 'password' }
113 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
114
115 remoteUserToken = await userLogin(servers[1], user)
116 }
117
118 await doubleFollow(servers[0], servers[1])
119 })
120
121 describe('User blocks another user', function () {
122
123 before(async function () {
124 this.timeout(30000)
125
126 await resetState()
127 })
128
129 it('Should have appropriate notifications', async function () {
130 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
131 await checkNotifications(servers[0].url, userToken1, notifs)
132 })
133
134 it('Should block an account', async function () {
135 this.timeout(10000)
136
137 await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
138 await waitJobs(servers)
139 })
140
141 it('Should not have notifications from this account', async function () {
142 await checkNotifications(servers[0].url, userToken1, [])
143 })
144
145 it('Should have notifications of this account on user 2', async function () {
146 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
147
148 await checkNotifications(servers[0].url, userToken2, notifs)
149
150 await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
151 })
152 })
153
154 describe('User blocks another server', function () {
155
156 before(async function () {
157 this.timeout(30000)
158
159 await resetState()
160 })
161
162 it('Should have appropriate notifications', async function () {
163 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
164 await checkNotifications(servers[0].url, userToken1, notifs)
165 })
166
167 it('Should block an account', async function () {
168 this.timeout(10000)
169
170 await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host)
171 await waitJobs(servers)
172 })
173
174 it('Should not have notifications from this account', async function () {
175 await checkNotifications(servers[0].url, userToken1, [])
176 })
177
178 it('Should have notifications of this account on user 2', async function () {
179 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
180
181 await checkNotifications(servers[0].url, userToken2, notifs)
182
183 await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host)
184 })
185 })
186
187 describe('Server blocks a user', function () {
188
189 before(async function () {
190 this.timeout(30000)
191
192 await resetState()
193 })
194
195 it('Should have appropriate notifications', async function () {
196 {
197 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
198 await checkNotifications(servers[0].url, userToken1, notifs)
199 }
200
201 {
202 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
203 await checkNotifications(servers[0].url, userToken2, notifs)
204 }
205 })
206
207 it('Should block an account', async function () {
208 this.timeout(10000)
209
210 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
211 await waitJobs(servers)
212 })
213
214 it('Should not have notifications from this account', async function () {
215 await checkNotifications(servers[0].url, userToken1, [])
216 await checkNotifications(servers[0].url, userToken2, [])
217
218 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
219 })
220 })
221
222 describe('Server blocks a server', function () {
223
224 before(async function () {
225 this.timeout(30000)
226
227 await resetState()
228 })
229
230 it('Should have appropriate notifications', async function () {
231 {
232 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
233 await checkNotifications(servers[0].url, userToken1, notifs)
234 }
235
236 {
237 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
238 await checkNotifications(servers[0].url, userToken2, notifs)
239 }
240 })
241
242 it('Should block an account', async function () {
243 this.timeout(10000)
244
245 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
246 await waitJobs(servers)
247 })
248
249 it('Should not have notifications from this account', async function () {
250 await checkNotifications(servers[0].url, userToken1, [])
251 await checkNotifications(servers[0].url, userToken2, [])
252 })
253 })
254
255 after(async function () {
256 await cleanupTests(servers)
257 })
258})
diff --git a/server/tests/api/moderation/index.ts b/server/tests/api/moderation/index.ts
index 6593c001f..874be03d5 100644
--- a/server/tests/api/moderation/index.ts
+++ b/server/tests/api/moderation/index.ts
@@ -1,3 +1,4 @@
1export * from './abuses' 1export * from './abuses'
2export * from './blocklist-notification'
2export * from './blocklist' 3export * from './blocklist'
3export * from './video-blacklist' 4export * from './video-blacklist'