aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/accounts.ts
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/users/accounts.ts
parent87e2635a50ac2decb1c330e55c2ff7b6d07a85de (diff)
downloadPeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.gz
PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.zst
PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.zip
Introduce accounts command
Diffstat (limited to 'shared/extra-utils/users/accounts.ts')
-rw-r--r--shared/extra-utils/users/accounts.ts83
1 files changed, 20 insertions, 63 deletions
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}