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