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