1 /* tslint:disable:no-unused-expression */
3 import { expect } from 'chai'
4 import { existsSync, readdir } from 'fs-extra'
5 import { join } from 'path'
6 import { Account } from '../../../../shared/models/actors'
7 import { root } from '../index'
8 import { makeGetRequest } from '../requests/requests'
10 function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
11 const path = '/api/v1/accounts'
13 return makeGetRequest({
21 function getAccount (url: string, accountName: string, statusCodeExpected = 200) {
22 const path = '/api/v1/accounts/' + accountName
24 return makeGetRequest({
31 async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
32 const res = await getAccountsList(url)
33 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
35 const message = `${nameWithDomain} on ${url}`
36 expect(account.followersCount).to.equal(followersCount, message)
37 expect(account.followingCount).to.equal(followingCount, message)
40 async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) {
41 const testDirectory = 'test' + serverNumber
43 for (const directory of [ 'avatars' ]) {
44 const directoryPath = join(root(), testDirectory, directory)
46 const directoryExists = existsSync(directoryPath)
47 expect(directoryExists).to.be.true
49 const files = await readdir(directoryPath)
50 for (const file of files) {
51 expect(file).to.not.contain(actorUUID)
56 // ---------------------------------------------------------------------------
62 checkActorFilesWereRemoved