aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 13:38:26 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commit9fff08cf83f34339df7ed4ac770e1dee536adf9d (patch)
tree36eac5147a12ae257a3e8aaeffae37c9aed23d0a /shared/extra-utils
parent87e2635a50ac2decb1c330e55c2ff7b6d07a85de (diff)
downloadPeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.gz
PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.zst
PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.zip
Introduce accounts command
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/index.ts8
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/users/accounts-command.ts54
-rw-r--r--shared/extra-utils/users/accounts.ts83
-rw-r--r--shared/extra-utils/users/index.ts8
5 files changed, 86 insertions, 70 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index ed7d7ab04..68900af26 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -10,17 +10,11 @@ export * from './overviews'
10export * from './search' 10export * from './search'
11export * from './server' 11export * from './server'
12export * from './socket' 12export * from './socket'
13export * from './users'
13 14
14export * from './requests/check-api-params' 15export * from './requests/check-api-params'
15export * from './requests/requests' 16export * from './requests/requests'
16 17
17export * from './users/accounts'
18export * from './users/blocklist'
19export * from './users/login'
20export * from './users/user-notifications'
21export * from './users/user-subscriptions'
22export * from './users/users'
23
24export * from './videos/live' 18export * from './videos/live'
25export * from './videos/services' 19export * from './videos/services'
26export * from './videos/video-blacklist' 20export * from './videos/video-blacklist'
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 8bd4446be..c2cab9818 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 19import { SocketIOCommand } from '../socket'
20import { AccountsCommand } from '../users'
20import { ConfigCommand } from './config-command' 21import { ConfigCommand } from './config-command'
21import { ContactFormCommand } from './contact-form-command' 22import { ContactFormCommand } from './contact-form-command'
22import { DebugCommand } from './debug-command' 23import { DebugCommand } from './debug-command'
@@ -95,6 +96,7 @@ interface ServerInfo {
95 statsCommand?: StatsCommand 96 statsCommand?: StatsCommand
96 configCommand?: ConfigCommand 97 configCommand?: ConfigCommand
97 socketIOCommand?: SocketIOCommand 98 socketIOCommand?: SocketIOCommand
99 accountsCommand?: AccountsCommand
98} 100}
99 101
100function parallelTests () { 102function parallelTests () {
@@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
317 server.statsCommand = new StatsCommand(server) 319 server.statsCommand = new StatsCommand(server)
318 server.configCommand = new ConfigCommand(server) 320 server.configCommand = new ConfigCommand(server)
319 server.socketIOCommand = new SocketIOCommand(server) 321 server.socketIOCommand = new SocketIOCommand(server)
322 server.accountsCommand = new AccountsCommand(server)
320 323
321 res(server) 324 res(server)
322 }) 325 })
diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.ts
new file mode 100644
index 000000000..89c080e93
--- /dev/null
+++ b/shared/extra-utils/users/accounts-command.ts
@@ -0,0 +1,54 @@
1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { Account } from '../../models/actors'
4import { AccountVideoRate, VideoRateType } from '../../models/videos'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class AccountsCommand extends AbstractCommand {
8
9 list (options: OverrideCommandOptions & {
10 sort?: string // default -createdAt
11 } = {}) {
12 const { sort = '-createdAt' } = options
13 const path = '/api/v1/accounts'
14
15 return this.getRequestBody<ResultList<Account>>({
16 ...options,
17
18 path,
19 query: { sort },
20 defaultExpectedStatus: HttpStatusCode.OK_200
21 })
22 }
23
24 get (options: OverrideCommandOptions & {
25 accountName: string
26 }) {
27 const path = '/api/v1/accounts/' + options.accountName
28
29 return this.getRequestBody<Account>({
30 ...options,
31
32 path,
33 defaultExpectedStatus: HttpStatusCode.OK_200
34 })
35 }
36
37 listRatings (options: OverrideCommandOptions & {
38 accountName: string
39 rating?: VideoRateType
40 }) {
41 const { rating, accountName } = options
42 const path = '/api/v1/accounts/' + accountName + '/ratings'
43
44 const query = { rating }
45
46 return this.getRequestBody<ResultList<AccountVideoRate>>({
47 ...options,
48
49 path,
50 query,
51 defaultExpectedStatus: HttpStatusCode.OK_200
52 })
53 }
54}
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts
index 4ea7f1402..ee94351e8 100644
--- a/shared/extra-utils/users/accounts.ts
+++ b/shared/extra-utils/users/accounts.ts
@@ -1,43 +1,25 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as request from 'supertest'
4import { expect } from 'chai' 3import { expect } from 'chai'
5import { existsSync, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
6import { join } from 'path' 5import { join } from 'path'
7import { Account } from '../../models/actors' 6import { root } from '@server/helpers/core-utils'
8import { root } from '../miscs/miscs' 7import { ServerInfo } from '../server'
9import { makeGetRequest } from '../requests/requests' 8
10import { VideoRateType } from '../../models/videos' 9async function expectAccountFollows (options: {
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 10 server: ServerInfo
12 11 handle: string
13function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { 12 followers: number
14 const path = '/api/v1/accounts' 13 following: number
15 14}) {
16 return makeGetRequest({ 15 const { server, handle, followers, following } = options
17 url, 16
18 query: { sort }, 17 const body = await server.accountsCommand.list()
19 path, 18 const account = body.data.find(a => a.name + '@' + a.host === handle)
20 statusCodeExpected 19
21 }) 20 const message = `${handle} on ${server.url}`
22} 21 expect(account.followersCount).to.equal(followers, message)
23 22 expect(account.followingCount).to.equal(following, message)
24function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) {
25 const path = '/api/v1/accounts/' + accountName
26
27 return makeGetRequest({
28 url,
29 path,
30 statusCodeExpected
31 })
32}
33
34async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
35 const res = await getAccountsList(url)
36 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
37
38 const message = `${nameWithDomain} on ${url}`
39 expect(account.followersCount).to.equal(followersCount, message)
40 expect(account.followingCount).to.equal(followingCount, message)
41} 23}
42 24
43async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { 25async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
@@ -46,7 +28,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
46 for (const directory of [ 'avatars' ]) { 28 for (const directory of [ 'avatars' ]) {
47 const directoryPath = join(root(), testDirectory, directory) 29 const directoryPath = join(root(), testDirectory, directory)
48 30
49 const directoryExists = existsSync(directoryPath) 31 const directoryExists = await pathExists(directoryPath)
50 expect(directoryExists).to.be.true 32 expect(directoryExists).to.be.true
51 33
52 const files = await readdir(directoryPath) 34 const files = await readdir(directoryPath)
@@ -56,32 +38,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
56 } 38 }
57} 39}
58 40
59function getAccountRatings (
60 url: string,
61 accountName: string,
62 accessToken: string,
63 rating?: VideoRateType,
64 statusCodeExpected = HttpStatusCode.OK_200
65) {
66 const path = '/api/v1/accounts/' + accountName + '/ratings'
67
68 const query = rating ? { rating } : {}
69
70 return request(url)
71 .get(path)
72 .query(query)
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + accessToken)
75 .expect(statusCodeExpected)
76 .expect('Content-Type', /json/)
77}
78
79// ---------------------------------------------------------------------------
80
81export { 41export {
82 getAccount,
83 expectAccountFollows, 42 expectAccountFollows,
84 getAccountsList, 43 checkActorFilesWereRemoved
85 checkActorFilesWereRemoved,
86 getAccountRatings
87} 44}
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
new file mode 100644
index 000000000..b3387ed8a
--- /dev/null
+++ b/shared/extra-utils/users/index.ts
@@ -0,0 +1,8 @@
1export * from './accounts'
2export * from './accounts-command'
3
4export * from './blocklist'
5export * from './login'
6export * from './user-notifications'
7export * from './user-subscriptions'
8export * from './users'