1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
12 markAsReadAllNotifications,
14 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { UserNotification, UserNotificationType } from '@shared/models'
21 const expect = chai.expect
23 async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
24 const res = await getUserNotifications(url, token, 0, 10, true)
26 const notifications: UserNotification[] = res.body.data
28 expect(notifications).to.have.lengthOf(expected.length)
30 for (const type of expected) {
31 expect(notifications.find(n => n.type === type)).to.exist
35 describe('Test blocklist', function () {
36 let servers: ServerInfo[]
39 let userToken1: string
40 let userToken2: string
41 let remoteUserToken: string
43 async function resetState () {
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 })
49 await waitJobs(servers)
51 await markAsReadAllNotifications(servers[0].url, userToken1)
52 await markAsReadAllNotifications(servers[0].url, userToken2)
55 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
56 videoUUID = res.body.video.uuid
58 await waitJobs(servers)
62 await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
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 })
71 await waitJobs(servers)
74 before(async function () {
77 servers = await flushAndRunMultipleServers(2)
78 await setAccessTokensToServers(servers)
81 const user = { username: 'user1', password: 'password' }
84 accessToken: servers[0].accessToken,
85 username: user.username,
86 password: user.password,
91 userToken1 = await userLogin(servers[0], user)
92 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
96 const user = { username: 'user2', password: 'password' }
97 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
99 userToken2 = await userLogin(servers[0], user)
103 const user = { username: 'user3', password: 'password' }
104 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
106 remoteUserToken = await userLogin(servers[1], user)
109 await doubleFollow(servers[0], servers[1])
112 describe('User blocks another user', function () {
114 before(async function () {
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)
125 it('Should block an account', async function () {
128 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
129 await waitJobs(servers)
132 it('Should not have notifications from this account', async function () {
133 await checkNotifications(servers[0].url, userToken1, [])
136 it('Should have notifications of this account on user 2', async function () {
137 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
139 await checkNotifications(servers[0].url, userToken2, notifs)
141 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
145 describe('User blocks another server', function () {
147 before(async function () {
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)
158 it('Should block an account', async function () {
161 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
162 await waitJobs(servers)
165 it('Should not have notifications from this account', async function () {
166 await checkNotifications(servers[0].url, userToken1, [])
169 it('Should have notifications of this account on user 2', async function () {
170 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
172 await checkNotifications(servers[0].url, userToken2, notifs)
174 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
178 describe('Server blocks a user', function () {
180 before(async function () {
186 it('Should have appropriate notifications', async function () {
188 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
189 await checkNotifications(servers[0].url, userToken1, notifs)
193 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
194 await checkNotifications(servers[0].url, userToken2, notifs)
198 it('Should block an account', async function () {
201 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
202 await waitJobs(servers)
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, [])
209 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
213 describe('Server blocks a server', function () {
215 before(async function () {
221 it('Should have appropriate notifications', async function () {
223 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
224 await checkNotifications(servers[0].url, userToken1, notifs)
228 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
229 await checkNotifications(servers[0].url, userToken2, notifs)
233 it('Should block an account', async function () {
236 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
237 await waitJobs(servers)
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, [])
246 after(async function () {
247 await cleanupTests(servers)