1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
10 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { UserNotificationType } from '@shared/models'
16 const expect = chai.expect
18 async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
19 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
20 expect(data).to.have.lengthOf(expected.length)
22 for (const type of expected) {
23 expect(data.find(n => n.type === type)).to.exist
27 describe('Test blocklist', function () {
28 let servers: ServerInfo[]
31 let userToken1: string
32 let userToken2: string
33 let remoteUserToken: string
35 async function resetState () {
37 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
38 await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
41 await waitJobs(servers)
43 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
44 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
47 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
48 videoUUID = res.body.video.uuid
50 await waitJobs(servers)
54 await servers[1].commentsCommand.createThread({
55 token: remoteUserToken,
57 text: '@user2@' + servers[0].host + ' hello'
63 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
64 await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
67 await waitJobs(servers)
70 before(async function () {
73 servers = await flushAndRunMultipleServers(2)
74 await setAccessTokensToServers(servers)
77 const user = { username: 'user1', password: 'password' }
78 await servers[0].usersCommand.create({
79 username: user.username,
80 password: user.password,
85 userToken1 = await servers[0].loginCommand.getAccessToken(user)
86 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
90 const user = { username: 'user2', password: 'password' }
91 await servers[0].usersCommand.create({ username: user.username, password: user.password })
93 userToken2 = await servers[0].loginCommand.getAccessToken(user)
97 const user = { username: 'user3', password: 'password' }
98 await servers[1].usersCommand.create({ username: user.username, password: user.password })
100 remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
103 await doubleFollow(servers[0], servers[1])
106 describe('User blocks another user', function () {
108 before(async function () {
114 it('Should have appropriate notifications', async function () {
115 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
116 await checkNotifications(servers[0], userToken1, notifs)
119 it('Should block an account', async function () {
122 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
123 await waitJobs(servers)
126 it('Should not have notifications from this account', async function () {
127 await checkNotifications(servers[0], userToken1, [])
130 it('Should have notifications of this account on user 2', async function () {
131 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
133 await checkNotifications(servers[0], userToken2, notifs)
135 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
139 describe('User blocks another server', function () {
141 before(async function () {
147 it('Should have appropriate notifications', async function () {
148 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
149 await checkNotifications(servers[0], userToken1, notifs)
152 it('Should block an account', async function () {
155 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
156 await waitJobs(servers)
159 it('Should not have notifications from this account', async function () {
160 await checkNotifications(servers[0], userToken1, [])
163 it('Should have notifications of this account on user 2', async function () {
164 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
166 await checkNotifications(servers[0], userToken2, notifs)
168 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
172 describe('Server blocks a user', function () {
174 before(async function () {
180 it('Should have appropriate notifications', async function () {
182 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
183 await checkNotifications(servers[0], userToken1, notifs)
187 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
188 await checkNotifications(servers[0], userToken2, notifs)
192 it('Should block an account', async function () {
195 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
196 await waitJobs(servers)
199 it('Should not have notifications from this account', async function () {
200 await checkNotifications(servers[0], userToken1, [])
201 await checkNotifications(servers[0], userToken2, [])
203 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
207 describe('Server blocks a server', function () {
209 before(async function () {
215 it('Should have appropriate notifications', async function () {
217 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
218 await checkNotifications(servers[0], userToken1, notifs)
222 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
223 await checkNotifications(servers[0], userToken2, notifs)
227 it('Should block an account', async function () {
230 await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
231 await waitJobs(servers)
234 it('Should not have notifications from this account', async function () {
235 await checkNotifications(servers[0], userToken1, [])
236 await checkNotifications(servers[0], userToken2, [])
240 after(async function () {
241 await cleanupTests(servers)