1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { UserNotificationType } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) {
15 const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true })
16 expect(data).to.have.lengthOf(expected.length)
18 for (const type of expected) {
19 expect(data.find(n => n.type === type)).to.exist
23 describe('Test blocklist notifications', function () {
24 let servers: PeerTubeServer[]
27 let userToken1: string
28 let userToken2: string
29 let remoteUserToken: string
31 async function resetState () {
33 await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
34 await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
37 await waitJobs(servers)
39 await servers[0].notifications.markAsReadAll({ token: userToken1 })
40 await servers[0].notifications.markAsReadAll({ token: userToken2 })
43 const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } })
46 await waitJobs(servers)
50 await servers[1].comments.createThread({
51 token: remoteUserToken,
53 text: '@user2@' + servers[0].host + ' hello'
59 await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
60 await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
63 await waitJobs(servers)
66 before(async function () {
69 servers = await createMultipleServers(2)
70 await setAccessTokensToServers(servers)
73 const user = { username: 'user1', password: 'password' }
74 await servers[0].users.create({
75 username: user.username,
76 password: user.password,
81 userToken1 = await servers[0].login.getAccessToken(user)
82 await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
86 const user = { username: 'user2', password: 'password' }
87 await servers[0].users.create({ username: user.username, password: user.password })
89 userToken2 = await servers[0].login.getAccessToken(user)
93 const user = { username: 'user3', password: 'password' }
94 await servers[1].users.create({ username: user.username, password: user.password })
96 remoteUserToken = await servers[1].login.getAccessToken(user)
99 await doubleFollow(servers[0], servers[1])
102 describe('User blocks another user', function () {
104 before(async function () {
110 it('Should have appropriate notifications', async function () {
111 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
112 await checkNotifications(servers[0], userToken1, notifs)
115 it('Should block an account', async function () {
118 await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
119 await waitJobs(servers)
122 it('Should not have notifications from this account', async function () {
123 await checkNotifications(servers[0], userToken1, [])
126 it('Should have notifications of this account on user 2', async function () {
127 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
129 await checkNotifications(servers[0], userToken2, notifs)
131 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
135 describe('User blocks another server', function () {
137 before(async function () {
143 it('Should have appropriate notifications', async function () {
144 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
145 await checkNotifications(servers[0], userToken1, notifs)
148 it('Should block an account', async function () {
151 await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
152 await waitJobs(servers)
155 it('Should not have notifications from this account', async function () {
156 await checkNotifications(servers[0], userToken1, [])
159 it('Should have notifications of this account on user 2', async function () {
160 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
162 await checkNotifications(servers[0], userToken2, notifs)
164 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
168 describe('Server blocks a user', function () {
170 before(async function () {
176 it('Should have appropriate notifications', async function () {
178 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
179 await checkNotifications(servers[0], userToken1, notifs)
183 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
184 await checkNotifications(servers[0], userToken2, notifs)
188 it('Should block an account', async function () {
191 await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
192 await waitJobs(servers)
195 it('Should not have notifications from this account', async function () {
196 await checkNotifications(servers[0], userToken1, [])
197 await checkNotifications(servers[0], userToken2, [])
199 await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
203 describe('Server blocks a server', function () {
205 before(async function () {
211 it('Should have appropriate notifications', async function () {
213 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
214 await checkNotifications(servers[0], userToken1, notifs)
218 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
219 await checkNotifications(servers[0], userToken2, notifs)
223 it('Should block an account', async function () {
226 await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
227 await waitJobs(servers)
230 it('Should not have notifications from this account', async function () {
231 await checkNotifications(servers[0], userToken1, [])
232 await checkNotifications(servers[0], userToken2, [])
236 after(async function () {
237 await cleanupTests(servers)