1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 markAsReadAllNotifications,
13 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { UserNotification, UserNotificationType } from '@shared/models'
20 const expect = chai.expect
22 async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
23 const res = await getUserNotifications(url, token, 0, 10, true)
25 const notifications: UserNotification[] = res.body.data
27 expect(notifications).to.have.lengthOf(expected.length)
29 for (const type of expected) {
30 expect(notifications.find(n => n.type === type)).to.exist
34 describe('Test blocklist', function () {
35 let servers: ServerInfo[]
38 let userToken1: string
39 let userToken2: string
40 let remoteUserToken: string
42 async function resetState () {
44 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
45 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
48 await waitJobs(servers)
50 await markAsReadAllNotifications(servers[0].url, userToken1)
51 await markAsReadAllNotifications(servers[0].url, userToken2)
54 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
55 videoUUID = res.body.video.uuid
57 await waitJobs(servers)
61 await servers[1].commentsCommand.createThread({
62 token: remoteUserToken,
64 text: '@user2@' + servers[0].host + ' hello'
70 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
71 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
74 await waitJobs(servers)
77 before(async function () {
80 servers = await flushAndRunMultipleServers(2)
81 await setAccessTokensToServers(servers)
84 const user = { username: 'user1', password: 'password' }
87 accessToken: servers[0].accessToken,
88 username: user.username,
89 password: user.password,
94 userToken1 = await userLogin(servers[0], user)
95 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
99 const user = { username: 'user2', password: 'password' }
100 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
102 userToken2 = await userLogin(servers[0], user)
106 const user = { username: 'user3', password: 'password' }
107 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
109 remoteUserToken = await userLogin(servers[1], user)
112 await doubleFollow(servers[0], servers[1])
115 describe('User blocks another user', function () {
117 before(async function () {
123 it('Should have appropriate notifications', async function () {
124 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
125 await checkNotifications(servers[0].url, userToken1, notifs)
128 it('Should block an account', async function () {
131 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
132 await waitJobs(servers)
135 it('Should not have notifications from this account', async function () {
136 await checkNotifications(servers[0].url, userToken1, [])
139 it('Should have notifications of this account on user 2', async function () {
140 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
142 await checkNotifications(servers[0].url, userToken2, notifs)
144 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
148 describe('User blocks another server', function () {
150 before(async function () {
156 it('Should have appropriate notifications', async function () {
157 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
158 await checkNotifications(servers[0].url, userToken1, notifs)
161 it('Should block an account', async function () {
164 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
165 await waitJobs(servers)
168 it('Should not have notifications from this account', async function () {
169 await checkNotifications(servers[0].url, userToken1, [])
172 it('Should have notifications of this account on user 2', async function () {
173 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
175 await checkNotifications(servers[0].url, userToken2, notifs)
177 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
181 describe('Server blocks a user', function () {
183 before(async function () {
189 it('Should have appropriate notifications', async function () {
191 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
192 await checkNotifications(servers[0].url, userToken1, notifs)
196 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
197 await checkNotifications(servers[0].url, userToken2, notifs)
201 it('Should block an account', async function () {
204 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
205 await waitJobs(servers)
208 it('Should not have notifications from this account', async function () {
209 await checkNotifications(servers[0].url, userToken1, [])
210 await checkNotifications(servers[0].url, userToken2, [])
212 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
216 describe('Server blocks a server', function () {
218 before(async function () {
224 it('Should have appropriate notifications', async function () {
226 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
227 await checkNotifications(servers[0].url, userToken1, notifs)
231 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
232 await checkNotifications(servers[0].url, userToken2, notifs)
236 it('Should block an account', async function () {
239 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
240 await waitJobs(servers)
243 it('Should not have notifications from this account', async function () {
244 await checkNotifications(servers[0].url, userToken1, [])
245 await checkNotifications(servers[0].url, userToken2, [])
249 after(async function () {
250 await cleanupTests(servers)