2018-01-18 04:53:54 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
2018-01-12 05:47:45 -05:00
|
|
|
import { expect } from 'chai'
|
2018-01-18 04:53:54 -05:00
|
|
|
import { existsSync } from 'fs'
|
|
|
|
import { join } from 'path'
|
2018-01-12 05:47:45 -05:00
|
|
|
import { Account } from '../../../../shared/models/actors'
|
2018-01-18 04:53:54 -05:00
|
|
|
import { readdirPromise } from '../../../helpers/core-utils'
|
|
|
|
import { root } from '../index'
|
2018-01-03 10:38:50 -05:00
|
|
|
import { makeGetRequest } from '../requests/requests'
|
|
|
|
|
|
|
|
function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
|
|
|
|
const path = '/api/v1/accounts'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
query: { sort },
|
|
|
|
path,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAccount (url: string, accountId: number | string, statusCodeExpected = 200) {
|
|
|
|
const path = '/api/v1/accounts/' + accountId
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-12 05:47:45 -05:00
|
|
|
async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
|
|
|
|
const res = await getAccountsList(url)
|
|
|
|
const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
|
|
|
|
|
|
|
|
const message = `${nameWithDomain} on ${url}`
|
|
|
|
expect(account.followersCount).to.equal(followersCount, message)
|
|
|
|
expect(account.followingCount).to.equal(followingCount, message)
|
|
|
|
}
|
|
|
|
|
2018-01-18 04:53:54 -05:00
|
|
|
async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) {
|
|
|
|
const testDirectory = 'test' + serverNumber
|
|
|
|
|
|
|
|
for (const directory of [ 'avatars' ]) {
|
|
|
|
const directoryPath = join(root(), testDirectory, directory)
|
|
|
|
|
|
|
|
const directoryExists = existsSync(directoryPath)
|
|
|
|
expect(directoryExists).to.be.true
|
|
|
|
|
|
|
|
const files = await readdirPromise(directoryPath)
|
|
|
|
for (const file of files) {
|
|
|
|
expect(file).to.not.contain(actorUUID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 10:38:50 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getAccount,
|
2018-01-12 05:47:45 -05:00
|
|
|
expectAccountFollows,
|
2018-01-18 04:53:54 -05:00
|
|
|
getAccountsList,
|
|
|
|
checkActorFilesWereRemoved
|
2018-01-03 10:38:50 -05:00
|
|
|
}
|