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