1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 flushAndRunMultipleServers,
13 markAsReadAllNotifications,
14 removeUserSubscription,
16 setAccessTokensToServers,
20 } from '@shared/extra-utils'
21 import { UserNotification, UserNotificationType } from '@shared/models'
23 const expect = chai.expect
25 async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
26 const res = await getUserNotifications(url, token, 0, 10, true)
28 const notifications: UserNotification[] = res.body.data
30 expect(notifications).to.have.lengthOf(expected.length)
32 for (const type of expected) {
33 expect(notifications.find(n => n.type === type)).to.exist
37 describe('Test blocklist', function () {
38 let servers: ServerInfo[]
41 let userToken1: string
42 let userToken2: string
43 let remoteUserToken: string
45 async function resetState () {
47 await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
48 await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
51 await waitJobs(servers)
53 await markAsReadAllNotifications(servers[0].url, userToken1)
54 await markAsReadAllNotifications(servers[0].url, userToken2)
57 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
58 videoUUID = res.body.video.uuid
60 await waitJobs(servers)
64 await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
69 await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
70 await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
73 await waitJobs(servers)
76 before(async function () {
79 servers = await flushAndRunMultipleServers(2)
80 await setAccessTokensToServers(servers)
83 const user = { username: 'user1', password: 'password' }
86 accessToken: servers[0].accessToken,
87 username: user.username,
88 password: user.password,
93 userToken1 = await userLogin(servers[0], user)
94 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
98 const user = { username: 'user2', password: 'password' }
99 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
101 userToken2 = await userLogin(servers[0], user)
105 const user = { username: 'user3', password: 'password' }
106 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
108 remoteUserToken = await userLogin(servers[1], user)
111 await doubleFollow(servers[0], servers[1])
114 describe('User blocks another user', function () {
116 before(async function () {
122 it('Should have appropriate notifications', async function () {
123 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
124 await checkNotifications(servers[0].url, userToken1, notifs)
127 it('Should block an account', async function () {
130 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
131 await waitJobs(servers)
134 it('Should not have notifications from this account', async function () {
135 await checkNotifications(servers[0].url, userToken1, [])
138 it('Should have notifications of this account on user 2', async function () {
139 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
141 await checkNotifications(servers[0].url, userToken2, notifs)
143 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
147 describe('User blocks another server', function () {
149 before(async function () {
155 it('Should have appropriate notifications', async function () {
156 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
157 await checkNotifications(servers[0].url, userToken1, notifs)
160 it('Should block an account', async function () {
163 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
164 await waitJobs(servers)
167 it('Should not have notifications from this account', async function () {
168 await checkNotifications(servers[0].url, userToken1, [])
171 it('Should have notifications of this account on user 2', async function () {
172 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
174 await checkNotifications(servers[0].url, userToken2, notifs)
176 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
180 describe('Server blocks a user', function () {
182 before(async function () {
188 it('Should have appropriate notifications', async function () {
190 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
191 await checkNotifications(servers[0].url, userToken1, notifs)
195 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
196 await checkNotifications(servers[0].url, userToken2, notifs)
200 it('Should block an account', async function () {
203 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
204 await waitJobs(servers)
207 it('Should not have notifications from this account', async function () {
208 await checkNotifications(servers[0].url, userToken1, [])
209 await checkNotifications(servers[0].url, userToken2, [])
211 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
215 describe('Server blocks a server', function () {
217 before(async function () {
223 it('Should have appropriate notifications', async function () {
225 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
226 await checkNotifications(servers[0].url, userToken1, notifs)
230 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
231 await checkNotifications(servers[0].url, userToken2, notifs)
235 it('Should block an account', async function () {
238 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
239 await waitJobs(servers)
242 it('Should not have notifications from this account', async function () {
243 await checkNotifications(servers[0].url, userToken1, [])
244 await checkNotifications(servers[0].url, userToken2, [])
248 after(async function () {
249 await cleanupTests(servers)