import {
addVideoCommentReply,
addVideoCommentThread,
- bulkRemoveCommentsOf,
+ BulkCommand,
cleanupTests,
createUser,
doubleFollow,
let user2AccessToken: string
let user3AccessToken: string
+ let bulkCommand: BulkCommand
+
before(async function () {
this.timeout(30000)
}
await doubleFollow(servers[0], servers[1])
+
+ bulkCommand = new BulkCommand(servers[0])
})
describe('Bulk remove comments', function () {
it('Should delete comments of an account on my videos', async function () {
this.timeout(60000)
- await bulkRemoveCommentsOf({
- url: servers[0].url,
+ await bulkCommand.removeCommentsOf({
token: user1AccessToken,
attributes: {
accountName: 'user2',
it('Should delete comments of an account on the instance', async function () {
this.timeout(60000)
- await bulkRemoveCommentsOf({
- url: servers[0].url,
- token: servers[0].accessToken,
+ await bulkCommand.removeCommentsOf({
attributes: {
accountName: 'user3@localhost:' + servers[1].port,
scope: 'instance'
-import { BulkRemoveCommentsOfBody } from "@shared/models/bulk/bulk-remove-comments-of-body.model"
-import { makePostBodyRequest } from "../requests/requests"
+
+import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
+import { AbstractCommand, CommonCommandOptions } from '../shared'
+
+class BulkCommand extends AbstractCommand {
-function bulkRemoveCommentsOf (options: {
- url: string
- token: string
- attributes: BulkRemoveCommentsOfBody
- expectedStatus?: number
-}) {
- const { url, token, attributes, expectedStatus } = options
- const path = '/api/v1/bulk/remove-comments-of'
+ removeCommentsOf (options: CommonCommandOptions & {
+ attributes: BulkRemoveCommentsOfBody
+ }) {
+ const { attributes } = options
- return makePostBodyRequest({
- url,
- path,
- token,
- fields: attributes,
- statusCodeExpected: expectedStatus || HttpStatusCode.NO_CONTENT_204
- })
+ return this.postBodyRequest({
+ ...options,
+ path: '/api/v1/bulk/remove-comments-of',
+ fields: attributes,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
}
export {
- bulkRemoveCommentsOf
+ BulkCommand
}
--- /dev/null
+import { HttpStatusCode } from '@shared/core-utils'
+import { makePostBodyRequest } from '../requests/requests'
+import { ServerInfo } from '../server/servers'
+
+export interface CommonCommandOptions {
+ token?: string
+ expectedStatus?: number
+}
+
+abstract class AbstractCommand {
+
+ private expectedStatus = HttpStatusCode.OK_200
+
+ constructor (
+ protected server: ServerInfo
+ ) {
+
+ }
+
+ setServer (server: ServerInfo) {
+ this.server = server
+ }
+
+ setExpectedStatus (status: HttpStatusCode) {
+ this.expectedStatus = status
+ }
+
+ protected postBodyRequest (options: CommonCommandOptions & {
+ path: string
+ defaultExpectedStatus: number
+ fields?: { [ fieldName: string ]: any }
+ }) {
+ const { token, fields, expectedStatus, defaultExpectedStatus, path } = options
+
+ return makePostBodyRequest({
+ url: this.server.url,
+ path,
+ token: token ?? this.server.accessToken,
+ fields,
+ statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
+ })
+ }
+}
+
+export {
+ AbstractCommand
+}
--- /dev/null
+export * from './abstract-command'