1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { UserNotificationType } from '@shared/models'
18 const expect = chai.expect
20 async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
21 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
22 expect(data).to.have.lengthOf(expected.length)
24 for (const type of expected) {
25 expect(data.find(n => n.type === type)).to.exist
29 describe('Test blocklist', function () {
30 let servers: ServerInfo[]
33 let userToken1: string
34 let userToken2: string
35 let remoteUserToken: string
37 async function resetState () {
39 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
40 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
43 await waitJobs(servers)
45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
46 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
49 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
50 videoUUID = res.body.video.uuid
52 await waitJobs(servers)
56 await servers[1].commentsCommand.createThread({
57 token: remoteUserToken,
59 text: '@user2@' + servers[0].host + ' hello'
65 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
66 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
69 await waitJobs(servers)
72 before(async function () {
75 servers = await flushAndRunMultipleServers(2)
76 await setAccessTokensToServers(servers)
79 const user = { username: 'user1', password: 'password' }
82 accessToken: servers[0].accessToken,
83 username: user.username,
84 password: user.password,
89 userToken1 = await userLogin(servers[0], user)
90 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
94 const user = { username: 'user2', password: 'password' }
95 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
97 userToken2 = await userLogin(servers[0], user)
101 const user = { username: 'user3', password: 'password' }
102 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
104 remoteUserToken = await userLogin(servers[1], user)
107 await doubleFollow(servers[0], servers[1])
110 describe('User blocks another user', function () {
112 before(async function () {
118 it('Should have appropriate notifications', async function () {
119 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
120 await checkNotifications(servers[0], userToken1, notifs)
123 it('Should block an account', async function () {
126 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
127 await waitJobs(servers)
130 it('Should not have notifications from this account', async function () {
131 await checkNotifications(servers[0], userToken1, [])
134 it('Should have notifications of this account on user 2', async function () {
135 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
137 await checkNotifications(servers[0], userToken2, notifs)
139 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
143 describe('User blocks another server', function () {
145 before(async function () {
151 it('Should have appropriate notifications', async function () {
152 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
153 await checkNotifications(servers[0], userToken1, notifs)
156 it('Should block an account', async function () {
159 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
160 await waitJobs(servers)
163 it('Should not have notifications from this account', async function () {
164 await checkNotifications(servers[0], userToken1, [])
167 it('Should have notifications of this account on user 2', async function () {
168 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
170 await checkNotifications(servers[0], userToken2, notifs)
172 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
176 describe('Server blocks a user', function () {
178 before(async function () {
184 it('Should have appropriate notifications', async function () {
186 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
187 await checkNotifications(servers[0], userToken1, notifs)
191 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
192 await checkNotifications(servers[0], userToken2, notifs)
196 it('Should block an account', async function () {
199 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
200 await waitJobs(servers)
203 it('Should not have notifications from this account', async function () {
204 await checkNotifications(servers[0], userToken1, [])
205 await checkNotifications(servers[0], userToken2, [])
207 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
211 describe('Server blocks a server', function () {
213 before(async function () {
219 it('Should have appropriate notifications', async function () {
221 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
222 await checkNotifications(servers[0], userToken1, notifs)
226 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
227 await checkNotifications(servers[0], userToken2, notifs)
231 it('Should block an account', async function () {
234 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
235 await waitJobs(servers)
238 it('Should not have notifications from this account', async function () {
239 await checkNotifications(servers[0], userToken1, [])
240 await checkNotifications(servers[0], userToken2, [])
244 after(async function () {
245 await cleanupTests(servers)