]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/users/accounts.ts
Translated using Weblate (Hungarian)
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / users / accounts.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
f05a1c30 2
c100a614 3import * as request from 'supertest'
32b2b43c 4import { expect } from 'chai'
62689b94 5import { existsSync, readdir } from 'fs-extra'
f05a1c30 6import { join } from 'path'
d4681c00 7import { Account } from '../../models/actors'
d175a6f7 8import { root } from '../miscs/miscs'
265ba139 9import { makeGetRequest } from '../requests/requests'
22834691 10import { VideoRateType } from '../../models/videos'
265ba139
C
11
12function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
13 const path = '/api/v1/accounts'
14
15 return makeGetRequest({
16 url,
17 query: { sort },
18 path,
19 statusCodeExpected
20 })
21}
22
ad9e39fb
C
23function getAccount (url: string, accountName: string, statusCodeExpected = 200) {
24 const path = '/api/v1/accounts/' + accountName
265ba139
C
25
26 return makeGetRequest({
27 url,
28 path,
29 statusCodeExpected
30 })
31}
32
32b2b43c
C
33async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
34 const res = await getAccountsList(url)
35 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
36
37 const message = `${nameWithDomain} on ${url}`
38 expect(account.followersCount).to.equal(followersCount, message)
39 expect(account.followingCount).to.equal(followingCount, message)
40}
41
57cfff78 42async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
f05a1c30
C
43 const testDirectory = 'test' + serverNumber
44
45 for (const directory of [ 'avatars' ]) {
46 const directoryPath = join(root(), testDirectory, directory)
47
48 const directoryExists = existsSync(directoryPath)
49 expect(directoryExists).to.be.true
50
62689b94 51 const files = await readdir(directoryPath)
f05a1c30 52 for (const file of files) {
57cfff78 53 expect(file).to.not.contain(filename)
f05a1c30
C
54 }
55 }
56}
57
22834691 58function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) {
c100a614
YB
59 const path = '/api/v1/accounts/' + accountName + '/ratings'
60
22834691
C
61 const query = rating ? { rating } : {}
62
c100a614
YB
63 return request(url)
64 .get(path)
65 .query(query)
66 .set('Accept', 'application/json')
67 .set('Authorization', 'Bearer ' + accessToken)
68 .expect(statusCodeExpected)
69 .expect('Content-Type', /json/)
70}
71
265ba139
C
72// ---------------------------------------------------------------------------
73
74export {
75 getAccount,
32b2b43c 76 expectAccountFollows,
f05a1c30 77 getAccountsList,
c100a614
YB
78 checkActorFilesWereRemoved,
79 getAccountRatings
265ba139 80}