2018-01-18 10:53:54 +01:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
2018-01-12 11:47:45 +01:00
|
|
|
import { expect } from 'chai'
|
2018-08-27 16:23:34 +02:00
|
|
|
import { existsSync, readdir } from 'fs-extra'
|
2018-01-18 10:53:54 +01:00
|
|
|
import { join } from 'path'
|
2018-10-29 18:06:09 +01:00
|
|
|
import { Account } from '../../models/actors'
|
2018-11-19 17:08:18 +01:00
|
|
|
import { root } from '../miscs/miscs'
|
2018-01-03 16:38:50 +01: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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-25 09:57:16 +02:00
|
|
|
function getAccount (url: string, accountName: string, statusCodeExpected = 200) {
|
|
|
|
const path = '/api/v1/accounts/' + accountName
|
2018-01-03 16:38:50 +01:00
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-12 11:47:45 +01: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 10:53:54 +01: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
|
|
|
|
|
2018-08-27 16:23:34 +02:00
|
|
|
const files = await readdir(directoryPath)
|
2018-01-18 10:53:54 +01:00
|
|
|
for (const file of files) {
|
|
|
|
expect(file).to.not.contain(actorUUID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 16:38:50 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getAccount,
|
2018-01-12 11:47:45 +01:00
|
|
|
expectAccountFollows,
|
2018-01-18 10:53:54 +01:00
|
|
|
getAccountsList,
|
|
|
|
checkActorFilesWereRemoved
|
2018-01-03 16:38:50 +01:00
|
|
|
}
|