import 'mocha'
import * as chai from 'chai'
import {
- addAccountToAccountBlocklist,
- addAccountToServerBlocklist,
- addServerToAccountBlocklist,
- addServerToServerBlocklist,
addVideoCommentReply,
addVideoCommentThread,
+ BlocklistCommand,
cleanupTests,
createUser,
deleteVideoComment,
doubleFollow,
findCommentId,
flushAndRunMultipleServers,
- follow,
- getAccountBlocklistByAccount,
- getAccountBlocklistByServer,
- getServerBlocklistByAccount,
- getServerBlocklistByServer,
getUserNotifications,
getVideoCommentThreads,
getVideosList,
getVideosListWithToken,
getVideoThreadComments,
- removeAccountFromAccountBlocklist,
- removeAccountFromServerBlocklist,
- removeServerFromAccountBlocklist,
- removeServerFromServerBlocklist,
ServerInfo,
setAccessTokensToServers,
- unfollow,
uploadVideo,
userLogin,
waitJobs
} from '@shared/extra-utils'
-import {
- AccountBlock,
- ServerBlock,
- UserNotification,
- UserNotificationType,
- Video,
- VideoComment,
- VideoCommentThreadTree
-} from '@shared/models'
+import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models'
const expect = chai.expect
let userModeratorToken: string
let userToken2: string
+ let command: BlocklistCommand
+
before(async function () {
this.timeout(120000)
}
await waitJobs(servers)
+
+ command = servers[0].blocklistCommand
})
describe('User blocklist', function () {
})
it('Should block a remote account', async function () {
- await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+ await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
})
it('Should hide its videos', async function () {
})
it('Should block a local account', async function () {
- await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+ await command.addToMyBlocklist({ account: 'user1' })
})
it('Should hide its videos', async function () {
const threads: VideoComment[] = resThreads.body.data
expect(threads).to.have.lengthOf(1)
- expect(threads[0].totalReplies).to.equal(0)
+ expect(threads[0].totalReplies).to.equal(1)
const t = threads.find(t => t.text === 'comment user 1')
expect(t).to.be.undefined
it('Should list blocked accounts', async function () {
{
- const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
- const blocks: AccountBlock[] = res.body.data
+ const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+ expect(body.total).to.equal(2)
- expect(res.body.total).to.equal(2)
-
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('root')
expect(block.byAccount.name).to.equal('root')
expect(block.blockedAccount.displayName).to.equal('user2')
}
{
- const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
- const blocks: AccountBlock[] = res.body.data
-
- expect(res.body.total).to.equal(2)
+ const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
+ expect(body.total).to.equal(2)
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('root')
expect(block.byAccount.name).to.equal('root')
expect(block.blockedAccount.displayName).to.equal('user1')
})
it('Should unblock the remote account', async function () {
- await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+ await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port })
})
it('Should display its videos', async function () {
})
it('Should unblock the local account', async function () {
- await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+ await command.removeFromMyBlocklist({ account: 'user1' })
})
it('Should display its comments', function () {
})
describe('When managing server blocklist', function () {
+
it('Should list all videos', function () {
return checkAllVideos(servers[0].url, servers[0].accessToken)
})
})
it('Should block a remote server', async function () {
- await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
})
it('Should hide its videos', async function () {
})
it('Should list blocked servers', async function () {
- const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
- const blocks: ServerBlock[] = res.body.data
-
- expect(res.body.total).to.equal(1)
+ const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+ expect(body.total).to.equal(1)
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('root')
expect(block.byAccount.name).to.equal('root')
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
})
it('Should unblock the remote server', async function () {
- await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
})
it('Should display its videos', function () {
})
it('Should block a remote account', async function () {
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+ await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
})
it('Should hide its videos', async function () {
})
it('Should block a local account', async function () {
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+ await command.addToServerBlocklist({ account: 'user1' })
})
it('Should hide its videos', async function () {
threads = threads.filter(t => t.isDeleted === false)
expect(threads).to.have.lengthOf(1)
- expect(threads[0].totalReplies).to.equal(0)
+ expect(threads[0].totalReplies).to.equal(1)
const t = threads.find(t => t.text === 'comment user 1')
expect(t).to.be.undefined
it('Should list blocked accounts', async function () {
{
- const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
- const blocks: AccountBlock[] = res.body.data
-
- expect(res.body.total).to.equal(2)
+ const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+ expect(body.total).to.equal(2)
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('peertube')
expect(block.byAccount.name).to.equal('peertube')
expect(block.blockedAccount.displayName).to.equal('user2')
}
{
- const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
- const blocks: AccountBlock[] = res.body.data
+ const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
+ expect(body.total).to.equal(2)
- expect(res.body.total).to.equal(2)
-
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('peertube')
expect(block.byAccount.name).to.equal('peertube')
expect(block.blockedAccount.displayName).to.equal('user1')
})
it('Should unblock the remote account', async function () {
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
+ await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
})
it('Should display its videos', async function () {
})
it('Should unblock the local account', async function () {
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
+ await command.removeFromServerBlocklist({ account: 'user1' })
})
it('Should display its comments', async function () {
})
it('Should block a remote server', async function () {
- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
})
it('Should hide its videos', async function () {
{
const now = new Date()
- await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+ await servers[1].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
- await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+ await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
await waitJobs(servers)
})
it('Should list blocked servers', async function () {
- const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
- const blocks: ServerBlock[] = res.body.data
-
- expect(res.body.total).to.equal(1)
+ const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
+ expect(body.total).to.equal(1)
- const block = blocks[0]
+ const block = body.data[0]
expect(block.byAccount.displayName).to.equal('peertube')
expect(block.byAccount.name).to.equal('peertube')
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
})
it('Should unblock the remote server', async function () {
- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
})
it('Should list all videos', async function () {
{
const now = new Date()
- await unfollow(servers[1].url, servers[1].accessToken, servers[0])
+ await servers[1].followsCommand.unfollow({ target: servers[0] })
await waitJobs(servers)
- await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken)
+ await servers[1].followsCommand.follow({ targets: [ servers[0].host ] })
await waitJobs(servers)