2020-11-18 11:13:01 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
2021-07-09 16:23:01 +02:00
|
|
|
import { UserNotificationType } from '@shared/models'
|
2021-12-17 11:58:15 +01:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/server-commands'
|
2020-11-18 11:13:01 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true })
|
2021-07-09 16:23:01 +02:00
|
|
|
expect(data).to.have.lengthOf(expected.length)
|
2020-11-18 11:13:01 +01:00
|
|
|
|
|
|
|
for (const type of expected) {
|
2021-07-09 16:23:01 +02:00
|
|
|
expect(data.find(n => n.type === type)).to.exist
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test blocklist', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let servers: PeerTubeServer[]
|
2020-11-18 11:13:01 +01:00
|
|
|
let videoUUID: string
|
|
|
|
|
|
|
|
let userToken1: string
|
|
|
|
let userToken2: string
|
|
|
|
let remoteUserToken: string
|
|
|
|
|
|
|
|
async function resetState () {
|
|
|
|
try {
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
|
|
|
|
await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
} catch {}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].notifications.markAsReadAll({ token: userToken1 })
|
|
|
|
await servers[0].notifications.markAsReadAll({ token: userToken2 })
|
2020-11-18 11:13:01 +01:00
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } })
|
2021-07-15 10:02:54 +02:00
|
|
|
videoUUID = uuid
|
2020-11-18 11:13:01 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].comments.createThread({
|
2021-07-09 14:15:11 +02:00
|
|
|
token: remoteUserToken,
|
|
|
|
videoId: videoUUID,
|
|
|
|
text: '@user2@' + servers[0].host + ' hello'
|
|
|
|
})
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
|
|
|
|
await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
}
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
servers = await createMultipleServers(2)
|
2020-11-18 11:13:01 +01:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({
|
2020-11-18 11:13:01 +01:00
|
|
|
username: user.username,
|
|
|
|
password: user.password,
|
|
|
|
videoQuota: -1,
|
|
|
|
videoQuotaDaily: -1
|
|
|
|
})
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
userToken1 = await servers[0].login.getAccessToken(user)
|
|
|
|
await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user2', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({ username: user.username, password: user.password })
|
2020-11-18 11:13:01 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
userToken2 = await servers[0].login.getAccessToken(user)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user3', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].users.create({ username: user.username, password: user.password })
|
2020-11-18 11:13:01 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
remoteUserToken = await servers[1].login.getAccessToken(user)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('User blocks another user', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await resetState()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have appropriate notifications', async function () {
|
|
|
|
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, [])
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have notifications of this account on user 2', async function () {
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken2, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('User blocks another server', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await resetState()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have appropriate notifications', async function () {
|
|
|
|
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, [])
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have notifications of this account on user 2', async function () {
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken2, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Server blocks a user', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await resetState()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have appropriate notifications', async function () {
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken2, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, [])
|
|
|
|
await checkNotifications(servers[0], userToken2, [])
|
2020-11-18 11:13:01 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Server blocks a server', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await resetState()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have appropriate notifications', async function () {
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken2, notifs)
|
2020-11-18 11:13:01 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
|
2020-11-18 11:13:01 +01:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
2021-07-09 16:23:01 +02:00
|
|
|
await checkNotifications(servers[0], userToken1, [])
|
|
|
|
await checkNotifications(servers[0], userToken2, [])
|
2020-11-18 11:13:01 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|