2020-11-18 04:13:01 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import {
|
2021-07-07 09:02:46 -05:00
|
|
|
addUserSubscription,
|
|
|
|
addVideoCommentThread,
|
2020-11-18 04:13:01 -06:00
|
|
|
cleanupTests,
|
|
|
|
createUser,
|
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
2021-07-07 09:02:46 -05:00
|
|
|
getUserNotifications,
|
|
|
|
markAsReadAllNotifications,
|
|
|
|
removeUserSubscription,
|
2020-11-18 04:13:01 -06:00
|
|
|
ServerInfo,
|
2021-07-07 09:02:46 -05:00
|
|
|
setAccessTokensToServers,
|
2020-11-18 04:13:01 -06:00
|
|
|
uploadVideo,
|
2021-07-07 09:02:46 -05:00
|
|
|
userLogin,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
|
|
|
import { UserNotification, UserNotificationType } from '@shared/models'
|
2020-11-18 04:13:01 -06:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) {
|
|
|
|
const res = await getUserNotifications(url, token, 0, 10, true)
|
|
|
|
|
|
|
|
const notifications: UserNotification[] = res.body.data
|
|
|
|
|
|
|
|
expect(notifications).to.have.lengthOf(expected.length)
|
|
|
|
|
|
|
|
for (const type of expected) {
|
|
|
|
expect(notifications.find(n => n.type === type)).to.exist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test blocklist', function () {
|
|
|
|
let servers: ServerInfo[]
|
|
|
|
let videoUUID: string
|
|
|
|
|
|
|
|
let userToken1: string
|
|
|
|
let userToken2: string
|
|
|
|
let remoteUserToken: string
|
|
|
|
|
|
|
|
async function resetState () {
|
|
|
|
try {
|
|
|
|
await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
|
|
|
|
await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
await markAsReadAllNotifications(servers[0].url, userToken1)
|
|
|
|
await markAsReadAllNotifications(servers[0].url, userToken2)
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
|
|
|
|
videoUUID = res.body.video.uuid
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host)
|
|
|
|
await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host)
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
}
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
|
|
|
await createUser({
|
|
|
|
url: servers[0].url,
|
|
|
|
accessToken: servers[0].accessToken,
|
|
|
|
username: user.username,
|
|
|
|
password: user.password,
|
|
|
|
videoQuota: -1,
|
|
|
|
videoQuotaDaily: -1
|
|
|
|
})
|
|
|
|
|
|
|
|
userToken1 = await userLogin(servers[0], user)
|
|
|
|
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user2', password: 'password' }
|
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
|
|
|
|
|
|
|
userToken2 = await userLogin(servers[0], user)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user3', password: 'password' }
|
|
|
|
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
|
|
|
|
|
|
|
|
remoteUserToken = await userLogin(servers[1], user)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ]
|
|
|
|
await checkNotifications(servers[0].url, userToken1, notifs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
2020-11-18 04:13:01 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
|
|
|
await checkNotifications(servers[0].url, userToken1, [])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have notifications of this account on user 2', async function () {
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
|
|
|
|
await checkNotifications(servers[0].url, userToken2, notifs)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
2020-11-18 04:13:01 -06: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 ]
|
|
|
|
await checkNotifications(servers[0].url, userToken1, notifs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
|
2020-11-18 04:13:01 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
|
|
|
await checkNotifications(servers[0].url, userToken1, [])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have notifications of this account on user 2', async function () {
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
|
|
|
|
await checkNotifications(servers[0].url, userToken2, notifs)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
|
2020-11-18 04:13:01 -06: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 ]
|
|
|
|
await checkNotifications(servers[0].url, userToken1, notifs)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
await checkNotifications(servers[0].url, userToken2, notifs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
|
2020-11-18 04:13:01 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
|
|
|
await checkNotifications(servers[0].url, userToken1, [])
|
|
|
|
await checkNotifications(servers[0].url, userToken2, [])
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
|
2020-11-18 04:13:01 -06: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 ]
|
|
|
|
await checkNotifications(servers[0].url, userToken1, notifs)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
|
|
|
await checkNotifications(servers[0].url, userToken2, notifs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block an account', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-07 09:02:46 -05:00
|
|
|
await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
|
2020-11-18 04:13:01 -06:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from this account', async function () {
|
|
|
|
await checkNotifications(servers[0].url, userToken1, [])
|
|
|
|
await checkNotifications(servers[0].url, userToken2, [])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|