aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/blocklist-notification.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 16:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitdd0ebb715123dfa126a82d4e4fe3a04064ae77b8 (patch)
treee0741f35b31c66f09f7d9ad808b224ef86151bb1 /server/tests/api/moderation/blocklist-notification.ts
parent9293139fde7091e9badcafa9b570b83cea9a10ad (diff)
downloadPeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.gz
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.zst
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.zip
Introduce notifications command
Diffstat (limited to 'server/tests/api/moderation/blocklist-notification.ts')
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts47
1 files changed, 21 insertions, 26 deletions
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index a077d8739..b676a4db4 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -7,27 +7,22 @@ import {
7 createUser, 7 createUser,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getUserNotifications,
11 markAsReadAllNotifications,
12 ServerInfo, 10 ServerInfo,
13 setAccessTokensToServers, 11 setAccessTokensToServers,
14 uploadVideo, 12 uploadVideo,
15 userLogin, 13 userLogin,
16 waitJobs 14 waitJobs
17} from '@shared/extra-utils' 15} from '@shared/extra-utils'
18import { UserNotification, UserNotificationType } from '@shared/models' 16import { UserNotificationType } from '@shared/models'
19 17
20const expect = chai.expect 18const expect = chai.expect
21 19
22async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { 20async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
23 const res = await getUserNotifications(url, token, 0, 10, true) 21 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
24 22 expect(data).to.have.lengthOf(expected.length)
25 const notifications: UserNotification[] = res.body.data
26
27 expect(notifications).to.have.lengthOf(expected.length)
28 23
29 for (const type of expected) { 24 for (const type of expected) {
30 expect(notifications.find(n => n.type === type)).to.exist 25 expect(data.find(n => n.type === type)).to.exist
31 } 26 }
32} 27}
33 28
@@ -47,8 +42,8 @@ describe('Test blocklist', function () {
47 42
48 await waitJobs(servers) 43 await waitJobs(servers)
49 44
50 await markAsReadAllNotifications(servers[0].url, userToken1) 45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
51 await markAsReadAllNotifications(servers[0].url, userToken2) 46 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
52 47
53 { 48 {
54 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) 49 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
@@ -122,7 +117,7 @@ describe('Test blocklist', function () {
122 117
123 it('Should have appropriate notifications', async function () { 118 it('Should have appropriate notifications', async function () {
124 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 119 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
125 await checkNotifications(servers[0].url, userToken1, notifs) 120 await checkNotifications(servers[0], userToken1, notifs)
126 }) 121 })
127 122
128 it('Should block an account', async function () { 123 it('Should block an account', async function () {
@@ -133,13 +128,13 @@ describe('Test blocklist', function () {
133 }) 128 })
134 129
135 it('Should not have notifications from this account', async function () { 130 it('Should not have notifications from this account', async function () {
136 await checkNotifications(servers[0].url, userToken1, []) 131 await checkNotifications(servers[0], userToken1, [])
137 }) 132 })
138 133
139 it('Should have notifications of this account on user 2', async function () { 134 it('Should have notifications of this account on user 2', async function () {
140 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 135 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
141 136
142 await checkNotifications(servers[0].url, userToken2, notifs) 137 await checkNotifications(servers[0], userToken2, notifs)
143 138
144 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) 139 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
145 }) 140 })
@@ -155,7 +150,7 @@ describe('Test blocklist', function () {
155 150
156 it('Should have appropriate notifications', async function () { 151 it('Should have appropriate notifications', async function () {
157 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 152 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
158 await checkNotifications(servers[0].url, userToken1, notifs) 153 await checkNotifications(servers[0], userToken1, notifs)
159 }) 154 })
160 155
161 it('Should block an account', async function () { 156 it('Should block an account', async function () {
@@ -166,13 +161,13 @@ describe('Test blocklist', function () {
166 }) 161 })
167 162
168 it('Should not have notifications from this account', async function () { 163 it('Should not have notifications from this account', async function () {
169 await checkNotifications(servers[0].url, userToken1, []) 164 await checkNotifications(servers[0], userToken1, [])
170 }) 165 })
171 166
172 it('Should have notifications of this account on user 2', async function () { 167 it('Should have notifications of this account on user 2', async function () {
173 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 168 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
174 169
175 await checkNotifications(servers[0].url, userToken2, notifs) 170 await checkNotifications(servers[0], userToken2, notifs)
176 171
177 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) 172 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
178 }) 173 })
@@ -189,12 +184,12 @@ describe('Test blocklist', function () {
189 it('Should have appropriate notifications', async function () { 184 it('Should have appropriate notifications', async function () {
190 { 185 {
191 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 186 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
192 await checkNotifications(servers[0].url, userToken1, notifs) 187 await checkNotifications(servers[0], userToken1, notifs)
193 } 188 }
194 189
195 { 190 {
196 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 191 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
197 await checkNotifications(servers[0].url, userToken2, notifs) 192 await checkNotifications(servers[0], userToken2, notifs)
198 } 193 }
199 }) 194 })
200 195
@@ -206,8 +201,8 @@ describe('Test blocklist', function () {
206 }) 201 })
207 202
208 it('Should not have notifications from this account', async function () { 203 it('Should not have notifications from this account', async function () {
209 await checkNotifications(servers[0].url, userToken1, []) 204 await checkNotifications(servers[0], userToken1, [])
210 await checkNotifications(servers[0].url, userToken2, []) 205 await checkNotifications(servers[0], userToken2, [])
211 206
212 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) 207 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
213 }) 208 })
@@ -224,12 +219,12 @@ describe('Test blocklist', function () {
224 it('Should have appropriate notifications', async function () { 219 it('Should have appropriate notifications', async function () {
225 { 220 {
226 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 221 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
227 await checkNotifications(servers[0].url, userToken1, notifs) 222 await checkNotifications(servers[0], userToken1, notifs)
228 } 223 }
229 224
230 { 225 {
231 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 226 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
232 await checkNotifications(servers[0].url, userToken2, notifs) 227 await checkNotifications(servers[0], userToken2, notifs)
233 } 228 }
234 }) 229 })
235 230
@@ -241,8 +236,8 @@ describe('Test blocklist', function () {
241 }) 236 })
242 237
243 it('Should not have notifications from this account', async function () { 238 it('Should not have notifications from this account', async function () {
244 await checkNotifications(servers[0].url, userToken1, []) 239 await checkNotifications(servers[0], userToken1, [])
245 await checkNotifications(servers[0].url, userToken2, []) 240 await checkNotifications(servers[0], userToken2, [])
246 }) 241 })
247 }) 242 })
248 243