]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/utils/users/accounts.ts
Underline links in feed popover when hovering
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users / accounts.ts
... / ...
CommitLineData
1/* tslint:disable:no-unused-expression */
2
3import { expect } from 'chai'
4import { existsSync } from 'fs-extra'
5import { join } from 'path'
6import { Account } from '../../../../shared/models/actors'
7import { readdirPromise } from '../../../helpers/core-utils'
8import { root } from '../index'
9import { makeGetRequest } from '../requests/requests'
10
11function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
12 const path = '/api/v1/accounts'
13
14 return makeGetRequest({
15 url,
16 query: { sort },
17 path,
18 statusCodeExpected
19 })
20}
21
22function getAccount (url: string, accountName: string, statusCodeExpected = 200) {
23 const path = '/api/v1/accounts/' + accountName
24
25 return makeGetRequest({
26 url,
27 path,
28 statusCodeExpected
29 })
30}
31
32async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
33 const res = await getAccountsList(url)
34 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
35
36 const message = `${nameWithDomain} on ${url}`
37 expect(account.followersCount).to.equal(followersCount, message)
38 expect(account.followingCount).to.equal(followingCount, message)
39}
40
41async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) {
42 const testDirectory = 'test' + serverNumber
43
44 for (const directory of [ 'avatars' ]) {
45 const directoryPath = join(root(), testDirectory, directory)
46
47 const directoryExists = existsSync(directoryPath)
48 expect(directoryExists).to.be.true
49
50 const files = await readdirPromise(directoryPath)
51 for (const file of files) {
52 expect(file).to.not.contain(actorUUID)
53 }
54 }
55}
56
57// ---------------------------------------------------------------------------
58
59export {
60 getAccount,
61 expectAccountFollows,
62 getAccountsList,
63 checkActorFilesWereRemoved
64}