diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 13:38:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 9fff08cf83f34339df7ed4ac770e1dee536adf9d (patch) | |
tree | 36eac5147a12ae257a3e8aaeffae37c9aed23d0a /shared | |
parent | 87e2635a50ac2decb1c330e55c2ff7b6d07a85de (diff) | |
download | PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.gz PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.zst PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.zip |
Introduce accounts command
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 8 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/users/accounts-command.ts | 54 | ||||
-rw-r--r-- | shared/extra-utils/users/accounts.ts | 83 | ||||
-rw-r--r-- | shared/extra-utils/users/index.ts | 8 |
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' | |||
10 | export * from './search' | 10 | export * from './search' |
11 | export * from './server' | 11 | export * from './server' |
12 | export * from './socket' | 12 | export * from './socket' |
13 | export * from './users' | ||
13 | 14 | ||
14 | export * from './requests/check-api-params' | 15 | export * from './requests/check-api-params' |
15 | export * from './requests/requests' | 16 | export * from './requests/requests' |
16 | 17 | ||
17 | export * from './users/accounts' | ||
18 | export * from './users/blocklist' | ||
19 | export * from './users/login' | ||
20 | export * from './users/user-notifications' | ||
21 | export * from './users/user-subscriptions' | ||
22 | export * from './users/users' | ||
23 | |||
24 | export * from './videos/live' | 18 | export * from './videos/live' |
25 | export * from './videos/services' | 19 | export * from './videos/services' |
26 | export * from './videos/video-blacklist' | 20 | export * 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' | |||
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand } from '../users' | ||
20 | import { ConfigCommand } from './config-command' | 21 | import { ConfigCommand } from './config-command' |
21 | import { ContactFormCommand } from './contact-form-command' | 22 | import { ContactFormCommand } from './contact-form-command' |
22 | import { DebugCommand } from './debug-command' | 23 | import { 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 | ||
100 | function parallelTests () { | 102 | function 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 @@ | |||
1 | import { ResultList } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { Account } from '../../models/actors' | ||
4 | import { AccountVideoRate, VideoRateType } from '../../models/videos' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export 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 | ||
3 | import * as request from 'supertest' | ||
4 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
5 | import { existsSync, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
6 | import { join } from 'path' | 5 | import { join } from 'path' |
7 | import { Account } from '../../models/actors' | 6 | import { root } from '@server/helpers/core-utils' |
8 | import { root } from '../miscs/miscs' | 7 | import { ServerInfo } from '../server' |
9 | import { makeGetRequest } from '../requests/requests' | 8 | |
10 | import { VideoRateType } from '../../models/videos' | 9 | async function expectAccountFollows (options: { |
11 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 10 | server: ServerInfo |
12 | 11 | handle: string | |
13 | function 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) | |
24 | function 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 | |||
34 | async 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 | ||
43 | async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { | 25 | async 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 | ||
59 | function 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 | |||
81 | export { | 41 | export { |
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 @@ | |||
1 | export * from './accounts' | ||
2 | export * from './accounts-command' | ||
3 | |||
4 | export * from './blocklist' | ||
5 | export * from './login' | ||
6 | export * from './user-notifications' | ||
7 | export * from './user-subscriptions' | ||
8 | export * from './users' | ||