import * as chai from 'chai'
import {
AbusesCommand,
- addAccountToServerBlocklist,
- addServerToServerBlocklist,
addVideoCommentThread,
cleanupTests,
createUser,
getVideoCommentThreads,
getVideoIdFromUUID,
getVideosList,
- removeAccountFromServerBlocklist,
- removeServerFromServerBlocklist,
removeUser,
removeVideo,
ServerInfo,
userLogin,
waitJobs
} from '@shared/extra-utils'
-import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
+import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
const expect = chai.expect
const accountToBlock = 'root@' + servers[1].host
{
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
+ await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock })
const body = await commands[0].getAdminList()
expect(body.total).to.equal(2)
}
{
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock })
const body = await commands[0].getAdminList()
expect(body.total).to.equal(3)
const serverToBlock = servers[1].host
{
- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
+ await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock })
const body = await commands[0].getAdminList()
expect(body.total).to.equal(2)
}
{
- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
+ await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock })
const body = await commands[0].getAdminList()
expect(body.total).to.equal(3)
import 'mocha'
import * as chai from 'chai'
-import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications'
-import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
-import { UserNotification, UserNotificationType } from '@shared/models'
import {
+ addUserSubscription,
+ addVideoCommentThread,
cleanupTests,
createUser,
doubleFollow,
flushAndRunMultipleServers,
+ getUserNotifications,
+ markAsReadAllNotifications,
+ removeUserSubscription,
ServerInfo,
+ setAccessTokensToServers,
uploadVideo,
- userLogin
-} from '../../../../shared/extra-utils/index'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import {
- addAccountToAccountBlocklist,
- addAccountToServerBlocklist,
- addServerToAccountBlocklist,
- addServerToServerBlocklist,
- removeAccountFromAccountBlocklist,
- removeAccountFromServerBlocklist,
- removeServerFromAccountBlocklist
-} from '../../../../shared/extra-utils/users/blocklist'
-import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
-import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
+ userLogin,
+ waitJobs
+} from '@shared/extra-utils'
+import { UserNotification, UserNotificationType } from '@shared/models'
const expect = chai.expect
it('Should block an account', async function () {
this.timeout(10000)
- await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
await waitJobs(servers)
})
await checkNotifications(servers[0].url, userToken2, notifs)
- await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host)
+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
})
})
it('Should block an account', async function () {
this.timeout(10000)
- await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host)
+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host })
await waitJobs(servers)
})
await checkNotifications(servers[0].url, userToken2, notifs)
- await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host)
+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
})
})
it('Should block an account', async function () {
this.timeout(10000)
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
+ await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host })
await waitJobs(servers)
})
await checkNotifications(servers[0].url, userToken1, [])
await checkNotifications(servers[0].url, userToken2, [])
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host)
+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
})
})
it('Should block an account', async function () {
this.timeout(10000)
- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
+ await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host })
await waitJobs(servers)
})
import 'mocha'
import * as chai from 'chai'
import {
- addAccountToAccountBlocklist,
- addAccountToServerBlocklist,
- addServerToAccountBlocklist,
- addServerToServerBlocklist,
addVideoCommentReply,
addVideoCommentThread,
+ BlocklistCommand,
cleanupTests,
createUser,
deleteVideoComment,
doubleFollow,
findCommentId,
flushAndRunMultipleServers,
- getAccountBlocklistByAccount,
- getAccountBlocklistByServer,
- getServerBlocklistByAccount,
- getServerBlocklistByServer,
getUserNotifications,
getVideoCommentThreads,
getVideosList,
getVideosListWithToken,
getVideoThreadComments,
- removeAccountFromAccountBlocklist,
- removeAccountFromServerBlocklist,
- removeServerFromAccountBlocklist,
- removeServerFromServerBlocklist,
ServerInfo,
setAccessTokensToServers,
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 () {
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 () {
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 () {
})
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 () {
import 'mocha'
import * as chai from 'chai'
import {
- addAccountToAccountBlocklist,
addVideoCommentReply,
addVideoCommentThread,
checkCommentMention,
getVideoThreadComments,
MockSmtpServer,
prepareNotificationsTest,
- removeAccountFromAccountBlocklist,
ServerInfo,
updateMyUser,
uploadVideo,
it('Should not send a new comment notification if the account is muted', async function () {
this.timeout(20000)
- await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
- await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
})
it('Should send a new comment notification after a local comment on my video', async function () {
it('Should not send a new mention notification if the account is muted', async function () {
this.timeout(10000)
- await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
+ await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
- await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
+ await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
})
it('Should not send a new mention notification if the remote account mention a local account', async function () {
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
- addAccountToAccountBlocklist,
- addAccountToServerBlocklist,
- addServerToAccountBlocklist,
- addServerToServerBlocklist,
addVideoChannel,
addVideoInPlaylist,
addVideoToBlacklist,
getVideoPlaylistPrivacies,
getVideoPlaylistsList,
getVideoPlaylistWithToken,
- removeAccountFromAccountBlocklist,
- removeAccountFromServerBlocklist,
- removeServerFromAccountBlocklist,
- removeServerFromServerBlocklist,
removeUser,
removeVideoFromBlacklist,
removeVideoFromPlaylist,
it('Should update the element type if the account or server of the video is blocked', async function () {
this.timeout(90000)
+ const command = servers[0].blocklistCommand
+
const name = 'video 90'
const position = 2
{
- await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
+ await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
- await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
+ await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
{
- await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
+ await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
- await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
+ await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
{
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
+ await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
+ await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
}
{
- await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
- await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
await waitJobs(servers)
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
import 'mocha'
import * as chai from 'chai'
import {
- addAccountToAccountBlocklist,
cleanupTests,
flushAndRunServer,
generateUserAccessToken,
it('Should hide muted accounts', async function () {
const token = await generateUserAccessToken(server, 'choco')
- await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
+ await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })
{
const body = await server.overviewsCommand.getVideos({ page: 1 })
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
- addAccountToServerBlocklist,
- addServerToAccountBlocklist,
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
killallServers,
makeGetRequest,
MockBlocklist,
- removeAccountFromServerBlocklist,
reRunServer,
ServerInfo,
setAccessTokensToServers,
expect(res.body.total).to.equal(1)
}
- await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
+ await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
{
const res = await getVideosList(servers[0].url)
}
})
- await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
- await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
+ await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
+ await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
const res = await makeGetRequest({
url: servers[0].url,
import 'mocha'
import * as chai from 'chai'
import * as xmlParser from 'fast-xml-parser'
+import { HttpStatusCode } from '@shared/core-utils'
import {
- addAccountToAccountBlocklist,
- addAccountToServerBlocklist,
- removeAccountFromServerBlocklist
-} from '@shared/extra-utils/users/blocklist'
-import { addUserSubscription, listUserSubscriptionVideos } from '@shared/extra-utils/users/user-subscriptions'
-import { VideoPrivacy } from '@shared/models'
-import { ScopedToken } from '@shared/models/users/user-scoped-token'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
-import {
+ addUserSubscription,
+ addVideoCommentThread,
cleanupTests,
createUser,
doubleFollow,
flushAndRunServer,
getMyUserInformation,
getUserScopedTokens,
+ listUserSubscriptionVideos,
renewUserScopedTokens,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
- userLogin
-} from '../../../shared/extra-utils'
-import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
-import { User } from '../../../shared/models/users'
+ userLogin,
+ waitJobs
+} from '@shared/extra-utils'
+import { User, VideoPrivacy } from '@shared/models'
+import { ScopedToken } from '@shared/models/users/user-scoped-token'
chai.use(require('chai-xml'))
chai.use(require('chai-json-schema'))
const remoteHandle = 'root@localhost:' + servers[0].port
- await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+ await servers[1].blocklistCommand.addToServerBlocklist({ account: remoteHandle })
{
const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 2 } })
expect(jsonObj.items.length).to.be.equal(0)
}
- await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+ await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle })
{
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
expect(jsonObj.items.length).to.be.equal(3)
}
- await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
+ await servers[1].blocklistCommand.addToMyBlocklist({ account: remoteHandle })
{
const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 4 } })
import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket'
-import { AccountsCommand } from '../users'
+import { AccountsCommand, BlocklistCommand } from '../users'
import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command'
configCommand?: ConfigCommand
socketIOCommand?: SocketIOCommand
accountsCommand?: AccountsCommand
+ blocklistCommand?: BlocklistCommand
}
function parallelTests () {
server.configCommand = new ConfigCommand(server)
server.socketIOCommand = new SocketIOCommand(server)
server.accountsCommand = new AccountsCommand(server)
+ server.blocklistCommand = new BlocklistCommand(server)
res(server)
})
getUserNotificationSocket (options: OverrideCommandOptions = {}) {
return io(this.server.url + '/user-notifications', {
- query: { accessToken: this.server.accessToken }
+ query: { accessToken: options.token ?? this.server.accessToken }
})
}
--- /dev/null
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import { HttpStatusCode } from '@shared/core-utils'
+import { AccountBlock, ResultList, ServerBlock } from '@shared/models'
+import { AbstractCommand, OverrideCommandOptions } from '../shared'
+
+type ListBlocklistOptions = OverrideCommandOptions & {
+ start: number
+ count: number
+ sort: string // default -createdAt
+}
+
+export class BlocklistCommand extends AbstractCommand {
+
+ listMyAccountBlocklist (options: ListBlocklistOptions) {
+ const path = '/api/v1/users/me/blocklist/accounts'
+
+ return this.listBlocklist<AccountBlock>(options, path)
+ }
+
+ listMyServerBlocklist (options: ListBlocklistOptions) {
+ const path = '/api/v1/users/me/blocklist/servers'
+
+ return this.listBlocklist<ServerBlock>(options, path)
+ }
+
+ listServerAccountBlocklist (options: ListBlocklistOptions) {
+ const path = '/api/v1/server/blocklist/accounts'
+
+ return this.listBlocklist<AccountBlock>(options, path)
+ }
+
+ listServerServerBlocklist (options: ListBlocklistOptions) {
+ const path = '/api/v1/server/blocklist/servers'
+
+ return this.listBlocklist<ServerBlock>(options, path)
+ }
+
+ // ---------------------------------------------------------------------------
+
+ addToMyBlocklist (options: OverrideCommandOptions & {
+ account?: string
+ server?: string
+ }) {
+ const { account, server } = options
+
+ const path = account
+ ? '/api/v1/users/me/blocklist/accounts'
+ : '/api/v1/users/me/blocklist/servers'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: {
+ accountName: account,
+ host: server
+ },
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ addToServerBlocklist (options: OverrideCommandOptions & {
+ account?: string
+ server?: string
+ }) {
+ const { account, server } = options
+
+ const path = account
+ ? '/api/v1/server/blocklist/accounts'
+ : '/api/v1/server/blocklist/servers'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: {
+ accountName: account,
+ host: server
+ },
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ removeFromMyBlocklist (options: OverrideCommandOptions & {
+ account?: string
+ server?: string
+ }) {
+ const { account, server } = options
+
+ const path = account
+ ? '/api/v1/users/me/blocklist/accounts/' + account
+ : '/api/v1/users/me/blocklist/servers/' + server
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ removeFromServerBlocklist (options: OverrideCommandOptions & {
+ account?: string
+ server?: string
+ }) {
+ const { account, server } = options
+
+ const path = account
+ ? '/api/v1/server/blocklist/accounts/' + account
+ : '/api/v1/server/blocklist/servers/' + server
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ private listBlocklist <T> (options: ListBlocklistOptions, path: string) {
+ const { start, count, sort = '-createdAt' } = options
+
+ return this.getRequestBody<ResultList<T>>({
+ ...options,
+
+ path,
+ query: { start, count, sort },
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+}
+++ /dev/null
-/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-
-import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
-
-function getAccountBlocklistByAccount (
- url: string,
- token: string,
- start: number,
- count: number,
- sort = '-createdAt',
- statusCodeExpected = HttpStatusCode.OK_200
-) {
- const path = '/api/v1/users/me/blocklist/accounts'
-
- return makeGetRequest({
- url,
- token,
- query: { start, count, sort },
- path,
- statusCodeExpected
- })
-}
-
-function addAccountToAccountBlocklist (
- url: string,
- token: string,
- accountToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/me/blocklist/accounts'
-
- return makePostBodyRequest({
- url,
- path,
- token,
- fields: {
- accountName: accountToBlock
- },
- statusCodeExpected
- })
-}
-
-function removeAccountFromAccountBlocklist (
- url: string,
- token: string,
- accountToUnblock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock
-
- return makeDeleteRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-function getServerBlocklistByAccount (
- url: string,
- token: string,
- start: number,
- count: number,
- sort = '-createdAt',
- statusCodeExpected = HttpStatusCode.OK_200
-) {
- const path = '/api/v1/users/me/blocklist/servers'
-
- return makeGetRequest({
- url,
- token,
- query: { start, count, sort },
- path,
- statusCodeExpected
- })
-}
-
-function addServerToAccountBlocklist (
- url: string,
- token: string,
- serverToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/me/blocklist/servers'
-
- return makePostBodyRequest({
- url,
- path,
- token,
- fields: {
- host: serverToBlock
- },
- statusCodeExpected
- })
-}
-
-function removeServerFromAccountBlocklist (
- url: string,
- token: string,
- serverToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock
-
- return makeDeleteRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-function getAccountBlocklistByServer (
- url: string,
- token: string,
- start: number,
- count: number,
- sort = '-createdAt',
- statusCodeExpected = HttpStatusCode.OK_200
-) {
- const path = '/api/v1/server/blocklist/accounts'
-
- return makeGetRequest({
- url,
- token,
- query: { start, count, sort },
- path,
- statusCodeExpected
- })
-}
-
-function addAccountToServerBlocklist (
- url: string,
- token: string,
- accountToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/server/blocklist/accounts'
-
- return makePostBodyRequest({
- url,
- path,
- token,
- fields: {
- accountName: accountToBlock
- },
- statusCodeExpected
- })
-}
-
-function removeAccountFromServerBlocklist (
- url: string,
- token: string,
- accountToUnblock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock
-
- return makeDeleteRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-function getServerBlocklistByServer (
- url: string,
- token: string,
- start: number,
- count: number,
- sort = '-createdAt',
- statusCodeExpected = HttpStatusCode.OK_200
-) {
- const path = '/api/v1/server/blocklist/servers'
-
- return makeGetRequest({
- url,
- token,
- query: { start, count, sort },
- path,
- statusCodeExpected
- })
-}
-
-function addServerToServerBlocklist (
- url: string,
- token: string,
- serverToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/server/blocklist/servers'
-
- return makePostBodyRequest({
- url,
- path,
- token,
- fields: {
- host: serverToBlock
- },
- statusCodeExpected
- })
-}
-
-function removeServerFromServerBlocklist (
- url: string,
- token: string,
- serverToBlock: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/server/blocklist/servers/' + serverToBlock
-
- return makeDeleteRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-// ---------------------------------------------------------------------------
-
-export {
- getAccountBlocklistByAccount,
- addAccountToAccountBlocklist,
- removeAccountFromAccountBlocklist,
- getServerBlocklistByAccount,
- addServerToAccountBlocklist,
- removeServerFromAccountBlocklist,
-
- getAccountBlocklistByServer,
- addAccountToServerBlocklist,
- removeAccountFromServerBlocklist,
- getServerBlocklistByServer,
- addServerToServerBlocklist,
- removeServerFromServerBlocklist
-}
-export * from './accounts'
export * from './accounts-command'
+export * from './accounts'
+export * from './blocklist-command'
-export * from './blocklist'
export * from './login'
export * from './user-notifications'
export * from './user-subscriptions'