]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/moderation/blocklist-notification.ts
Introduce server commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist-notification.ts
CommitLineData
ea3674d0
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
ea3674d0
C
5import {
6 cleanupTests,
7 createUser,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 ServerInfo,
5f8bd4cb 11 setAccessTokensToServers,
ea3674d0 12 uploadVideo,
5f8bd4cb
C
13 userLogin,
14 waitJobs
15} from '@shared/extra-utils'
dd0ebb71 16import { UserNotificationType } from '@shared/models'
ea3674d0
C
17
18const expect = chai.expect
19
dd0ebb71
C
20async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
21 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
22 expect(data).to.have.lengthOf(expected.length)
ea3674d0
C
23
24 for (const type of expected) {
dd0ebb71 25 expect(data.find(n => n.type === type)).to.exist
ea3674d0
C
26 }
27}
28
29describe('Test blocklist', function () {
30 let servers: ServerInfo[]
31 let videoUUID: string
32
33 let userToken1: string
34 let userToken2: string
35 let remoteUserToken: string
36
37 async function resetState () {
38 try {
2c27e704
C
39 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
40 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
ea3674d0
C
41 } catch {}
42
43 await waitJobs(servers)
44
dd0ebb71
C
45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
46 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
ea3674d0
C
47
48 {
49 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
50 videoUUID = res.body.video.uuid
51
52 await waitJobs(servers)
53 }
54
55 {
12edc149
C
56 await servers[1].commentsCommand.createThread({
57 token: remoteUserToken,
58 videoId: videoUUID,
59 text: '@user2@' + servers[0].host + ' hello'
60 })
ea3674d0
C
61 }
62
63 {
64
2c27e704
C
65 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
66 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
ea3674d0
C
67 }
68
69 await waitJobs(servers)
70 }
71
72 before(async function () {
73 this.timeout(60000)
74
75 servers = await flushAndRunMultipleServers(2)
76 await setAccessTokensToServers(servers)
77
78 {
79 const user = { username: 'user1', password: 'password' }
80 await createUser({
81 url: servers[0].url,
82 accessToken: servers[0].accessToken,
83 username: user.username,
84 password: user.password,
85 videoQuota: -1,
86 videoQuotaDaily: -1
87 })
88
89 userToken1 = await userLogin(servers[0], user)
90 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
91 }
92
93 {
94 const user = { username: 'user2', password: 'password' }
95 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
96
97 userToken2 = await userLogin(servers[0], user)
98 }
99
100 {
101 const user = { username: 'user3', password: 'password' }
102 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
103
104 remoteUserToken = await userLogin(servers[1], user)
105 }
106
107 await doubleFollow(servers[0], servers[1])
108 })
109
110 describe('User blocks another user', function () {
111
112 before(async function () {
113 this.timeout(30000)
114
115 await resetState()
116 })
117
118 it('Should have appropriate notifications', async function () {
119 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 120 await checkNotifications(servers[0], userToken1, notifs)
ea3674d0
C
121 })
122
123 it('Should block an account', async function () {
124 this.timeout(10000)
125
5f8bd4cb 126 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
ea3674d0
C
127 await waitJobs(servers)
128 })
129
130 it('Should not have notifications from this account', async function () {
dd0ebb71 131 await checkNotifications(servers[0], userToken1, [])
ea3674d0
C
132 })
133
134 it('Should have notifications of this account on user 2', async function () {
135 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
136
dd0ebb71 137 await checkNotifications(servers[0], userToken2, notifs)
ea3674d0 138
5f8bd4cb 139 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
ea3674d0
C
140 })
141 })
142
143 describe('User blocks another server', function () {
144
145 before(async function () {
146 this.timeout(30000)
147
148 await resetState()
149 })
150
151 it('Should have appropriate notifications', async function () {
152 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 153 await checkNotifications(servers[0], userToken1, notifs)
ea3674d0
C
154 })
155
156 it('Should block an account', async function () {
157 this.timeout(10000)
158
5f8bd4cb 159 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
ea3674d0
C
160 await waitJobs(servers)
161 })
162
163 it('Should not have notifications from this account', async function () {
dd0ebb71 164 await checkNotifications(servers[0], userToken1, [])
ea3674d0
C
165 })
166
167 it('Should have notifications of this account on user 2', async function () {
168 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
169
dd0ebb71 170 await checkNotifications(servers[0], userToken2, notifs)
ea3674d0 171
5f8bd4cb 172 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
ea3674d0
C
173 })
174 })
175
176 describe('Server blocks a user', function () {
177
178 before(async function () {
179 this.timeout(30000)
180
181 await resetState()
182 })
183
184 it('Should have appropriate notifications', async function () {
185 {
186 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 187 await checkNotifications(servers[0], userToken1, notifs)
ea3674d0
C
188 }
189
190 {
191 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 192 await checkNotifications(servers[0], userToken2, notifs)
ea3674d0
C
193 }
194 })
195
196 it('Should block an account', async function () {
197 this.timeout(10000)
198
5f8bd4cb 199 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
ea3674d0
C
200 await waitJobs(servers)
201 })
202
203 it('Should not have notifications from this account', async function () {
dd0ebb71
C
204 await checkNotifications(servers[0], userToken1, [])
205 await checkNotifications(servers[0], userToken2, [])
ea3674d0 206
5f8bd4cb 207 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
ea3674d0
C
208 })
209 })
210
211 describe('Server blocks a server', function () {
212
213 before(async function () {
214 this.timeout(30000)
215
216 await resetState()
217 })
218
219 it('Should have appropriate notifications', async function () {
220 {
221 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 222 await checkNotifications(servers[0], userToken1, notifs)
ea3674d0
C
223 }
224
225 {
226 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
dd0ebb71 227 await checkNotifications(servers[0], userToken2, notifs)
ea3674d0
C
228 }
229 })
230
231 it('Should block an account', async function () {
232 this.timeout(10000)
233
5f8bd4cb 234 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
ea3674d0
C
235 await waitJobs(servers)
236 })
237
238 it('Should not have notifications from this account', async function () {
dd0ebb71
C
239 await checkNotifications(servers[0], userToken1, [])
240 await checkNotifications(servers[0], userToken2, [])
ea3674d0
C
241 })
242 })
243
244 after(async function () {
245 await cleanupTests(servers)
246 })
247})