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