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