1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 setAccessTokensToServers,
14 } from '@shared/extra-utils'
15 import { UserNotificationType } from '@shared/models'
17 const expect = chai.expect
19 async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
20 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
21 expect(data).to.have.lengthOf(expected.length)
23 for (const type of expected) {
24 expect(data.find(n => n.type === type)).to.exist
28 describe('Test blocklist', function () {
29 let servers: ServerInfo[]
32 let userToken1: string
33 let userToken2: string
34 let remoteUserToken: string
36 async function resetState () {
38 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
39 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
42 await waitJobs(servers)
44 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
48 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
49 videoUUID = res.body.video.uuid
51 await waitJobs(servers)
55 await servers[1].commentsCommand.createThread({
56 token: remoteUserToken,
58 text: '@user2@' + servers[0].host + ' hello'
64 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
65 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
68 await waitJobs(servers)
71 before(async function () {
74 servers = await flushAndRunMultipleServers(2)
75 await setAccessTokensToServers(servers)
78 const user = { username: 'user1', password: 'password' }
81 accessToken: servers[0].accessToken,
82 username: user.username,
83 password: user.password,
88 userToken1 = await servers[0].loginCommand.getAccessToken(user)
89 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
93 const user = { username: 'user2', password: 'password' }
94 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
96 userToken2 = await servers[0].loginCommand.getAccessToken(user)
100 const user = { username: 'user3', password: 'password' }
101 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
103 remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
106 await doubleFollow(servers[0], servers[1])
109 describe('User blocks another user', function () {
111 before(async function () {
117 it('Should have appropriate notifications', async function () {
118 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
119 await checkNotifications(servers[0], userToken1, notifs)
122 it('Should block an account', async function () {
125 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
126 await waitJobs(servers)
129 it('Should not have notifications from this account', async function () {
130 await checkNotifications(servers[0], userToken1, [])
133 it('Should have notifications of this account on user 2', async function () {
134 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
136 await checkNotifications(servers[0], userToken2, notifs)
138 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
142 describe('User blocks another server', function () {
144 before(async function () {
150 it('Should have appropriate notifications', async function () {
151 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
152 await checkNotifications(servers[0], userToken1, notifs)
155 it('Should block an account', async function () {
158 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
159 await waitJobs(servers)
162 it('Should not have notifications from this account', async function () {
163 await checkNotifications(servers[0], userToken1, [])
166 it('Should have notifications of this account on user 2', async function () {
167 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
169 await checkNotifications(servers[0], userToken2, notifs)
171 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
175 describe('Server blocks a user', function () {
177 before(async function () {
183 it('Should have appropriate notifications', async function () {
185 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
186 await checkNotifications(servers[0], userToken1, notifs)
190 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
191 await checkNotifications(servers[0], userToken2, notifs)
195 it('Should block an account', async function () {
198 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
199 await waitJobs(servers)
202 it('Should not have notifications from this account', async function () {
203 await checkNotifications(servers[0], userToken1, [])
204 await checkNotifications(servers[0], userToken2, [])
206 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
210 describe('Server blocks a server', function () {
212 before(async function () {
218 it('Should have appropriate notifications', async function () {
220 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
221 await checkNotifications(servers[0], userToken1, notifs)
225 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
226 await checkNotifications(servers[0], userToken2, notifs)
230 it('Should block an account', async function () {
233 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
234 await waitJobs(servers)
237 it('Should not have notifications from this account', async function () {
238 await checkNotifications(servers[0], userToken1, [])
239 await checkNotifications(servers[0], userToken2, [])
243 after(async function () {
244 await cleanupTests(servers)