aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-05 14:57:03 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:16 +0200
commita6a79eae0d8564099b6957e76d7a18528d9ef124 (patch)
treeb29a6eedbe5c9246e4cd651e51d26145ff10e517
parentcf21b2cbef61929177b9c09b5e017c3b7eb8535d (diff)
downloadPeerTube-a6a79eae0d8564099b6957e76d7a18528d9ef124.tar.gz
PeerTube-a6a79eae0d8564099b6957e76d7a18528d9ef124.tar.zst
PeerTube-a6a79eae0d8564099b6957e76d7a18528d9ef124.zip
Introduce bulk command
-rw-r--r--server/tests/api/server/bulk.ts13
-rw-r--r--shared/extra-utils/bulk/bulk.ts35
-rw-r--r--shared/extra-utils/shared/abstract-command.ts47
-rw-r--r--shared/extra-utils/shared/index.ts1
4 files changed, 72 insertions, 24 deletions
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index 80fa7fce6..ca98a2eb2 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -6,7 +6,7 @@ import { Video, VideoComment } from '@shared/models'
6import { 6import {
7 addVideoCommentReply, 7 addVideoCommentReply,
8 addVideoCommentThread, 8 addVideoCommentThread,
9 bulkRemoveCommentsOf, 9 BulkCommand,
10 cleanupTests, 10 cleanupTests,
11 createUser, 11 createUser,
12 doubleFollow, 12 doubleFollow,
@@ -30,6 +30,8 @@ describe('Test bulk actions', function () {
30 let user2AccessToken: string 30 let user2AccessToken: string
31 let user3AccessToken: string 31 let user3AccessToken: string
32 32
33 let bulkCommand: BulkCommand
34
33 before(async function () { 35 before(async function () {
34 this.timeout(30000) 36 this.timeout(30000)
35 37
@@ -60,6 +62,8 @@ describe('Test bulk actions', function () {
60 } 62 }
61 63
62 await doubleFollow(servers[0], servers[1]) 64 await doubleFollow(servers[0], servers[1])
65
66 bulkCommand = new BulkCommand(servers[0])
63 }) 67 })
64 68
65 describe('Bulk remove comments', function () { 69 describe('Bulk remove comments', function () {
@@ -133,8 +137,7 @@ describe('Test bulk actions', function () {
133 it('Should delete comments of an account on my videos', async function () { 137 it('Should delete comments of an account on my videos', async function () {
134 this.timeout(60000) 138 this.timeout(60000)
135 139
136 await bulkRemoveCommentsOf({ 140 await bulkCommand.removeCommentsOf({
137 url: servers[0].url,
138 token: user1AccessToken, 141 token: user1AccessToken,
139 attributes: { 142 attributes: {
140 accountName: 'user2', 143 accountName: 'user2',
@@ -164,9 +167,7 @@ describe('Test bulk actions', function () {
164 it('Should delete comments of an account on the instance', async function () { 167 it('Should delete comments of an account on the instance', async function () {
165 this.timeout(60000) 168 this.timeout(60000)
166 169
167 await bulkRemoveCommentsOf({ 170 await bulkCommand.removeCommentsOf({
168 url: servers[0].url,
169 token: servers[0].accessToken,
170 attributes: { 171 attributes: {
171 accountName: 'user3@localhost:' + servers[1].port, 172 accountName: 'user3@localhost:' + servers[1].port,
172 scope: 'instance' 173 scope: 'instance'
diff --git a/shared/extra-utils/bulk/bulk.ts b/shared/extra-utils/bulk/bulk.ts
index b6f437b8b..c102383e3 100644
--- a/shared/extra-utils/bulk/bulk.ts
+++ b/shared/extra-utils/bulk/bulk.ts
@@ -1,25 +1,24 @@
1import { BulkRemoveCommentsOfBody } from "@shared/models/bulk/bulk-remove-comments-of-body.model" 1
2import { makePostBodyRequest } from "../requests/requests" 2import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4import { AbstractCommand, CommonCommandOptions } from '../shared'
5
6class BulkCommand extends AbstractCommand {
4 7
5function bulkRemoveCommentsOf (options: { 8 removeCommentsOf (options: CommonCommandOptions & {
6 url: string 9 attributes: BulkRemoveCommentsOfBody
7 token: string 10 }) {
8 attributes: BulkRemoveCommentsOfBody 11 const { attributes } = options
9 expectedStatus?: number
10}) {
11 const { url, token, attributes, expectedStatus } = options
12 const path = '/api/v1/bulk/remove-comments-of'
13 12
14 return makePostBodyRequest({ 13 return this.postBodyRequest({
15 url, 14 ...options,
16 path, 15 path: '/api/v1/bulk/remove-comments-of',
17 token, 16 fields: attributes,
18 fields: attributes, 17 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
19 statusCodeExpected: expectedStatus || HttpStatusCode.NO_CONTENT_204 18 })
20 }) 19 }
21} 20}
22 21
23export { 22export {
24 bulkRemoveCommentsOf 23 BulkCommand
25} 24}
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts
new file mode 100644
index 000000000..bb06b6bdb
--- /dev/null
+++ b/shared/extra-utils/shared/abstract-command.ts
@@ -0,0 +1,47 @@
1import { HttpStatusCode } from '@shared/core-utils'
2import { makePostBodyRequest } from '../requests/requests'
3import { ServerInfo } from '../server/servers'
4
5export interface CommonCommandOptions {
6 token?: string
7 expectedStatus?: number
8}
9
10abstract class AbstractCommand {
11
12 private expectedStatus = HttpStatusCode.OK_200
13
14 constructor (
15 protected server: ServerInfo
16 ) {
17
18 }
19
20 setServer (server: ServerInfo) {
21 this.server = server
22 }
23
24 setExpectedStatus (status: HttpStatusCode) {
25 this.expectedStatus = status
26 }
27
28 protected postBodyRequest (options: CommonCommandOptions & {
29 path: string
30 defaultExpectedStatus: number
31 fields?: { [ fieldName: string ]: any }
32 }) {
33 const { token, fields, expectedStatus, defaultExpectedStatus, path } = options
34
35 return makePostBodyRequest({
36 url: this.server.url,
37 path,
38 token: token ?? this.server.accessToken,
39 fields,
40 statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
41 })
42 }
43}
44
45export {
46 AbstractCommand
47}
diff --git a/shared/extra-utils/shared/index.ts b/shared/extra-utils/shared/index.ts
new file mode 100644
index 000000000..e807ab4f7
--- /dev/null
+++ b/shared/extra-utils/shared/index.ts
@@ -0,0 +1 @@
export * from './abstract-command'