2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-01-18 03:53:54 -06:00
|
|
|
|
2019-04-09 04:02:02 -05:00
|
|
|
import * as request from 'supertest'
|
2018-01-12 04:47:45 -06:00
|
|
|
import { expect } from 'chai'
|
2018-08-27 09:23:34 -05:00
|
|
|
import { existsSync, readdir } from 'fs-extra'
|
2018-01-18 03:53:54 -06:00
|
|
|
import { join } from 'path'
|
2018-10-29 12:06:09 -05:00
|
|
|
import { Account } from '../../models/actors'
|
2018-11-19 10:08:18 -06:00
|
|
|
import { root } from '../miscs/miscs'
|
2018-01-03 09:38:50 -06:00
|
|
|
import { makeGetRequest } from '../requests/requests'
|
2019-04-09 04:21:36 -05:00
|
|
|
import { VideoRateType } from '../../models/videos'
|
2020-12-07 07:32:36 -06:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2018-01-03 09:38:50 -06:00
|
|
|
|
2020-12-07 07:32:36 -06:00
|
|
|
function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
|
2018-01-03 09:38:50 -06:00
|
|
|
const path = '/api/v1/accounts'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
query: { sort },
|
|
|
|
path,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-07 07:32:36 -06:00
|
|
|
function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) {
|
2018-05-25 02:57:16 -05:00
|
|
|
const path = '/api/v1/accounts/' + accountName
|
2018-01-03 09:38:50 -06:00
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-12 04:47:45 -06: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)
|
|
|
|
}
|
|
|
|
|
2019-05-31 07:02:26 -05:00
|
|
|
async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
|
2018-01-18 03:53:54 -06:00
|
|
|
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 09:23:34 -05:00
|
|
|
const files = await readdir(directoryPath)
|
2018-01-18 03:53:54 -06:00
|
|
|
for (const file of files) {
|
2019-05-31 07:02:26 -05:00
|
|
|
expect(file).to.not.contain(filename)
|
2018-01-18 03:53:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 07:32:36 -06:00
|
|
|
function getAccountRatings (
|
|
|
|
url: string,
|
|
|
|
accountName: string,
|
|
|
|
accessToken: string,
|
|
|
|
rating?: VideoRateType,
|
|
|
|
statusCodeExpected = HttpStatusCode.OK_200
|
|
|
|
) {
|
2019-04-09 04:02:02 -05:00
|
|
|
const path = '/api/v1/accounts/' + accountName + '/ratings'
|
|
|
|
|
2019-04-09 04:21:36 -05:00
|
|
|
const query = rating ? { rating } : {}
|
|
|
|
|
2019-04-09 04:02:02 -05:00
|
|
|
return request(url)
|
|
|
|
.get(path)
|
|
|
|
.query(query)
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
|
|
|
.expect(statusCodeExpected)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
2018-01-03 09:38:50 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getAccount,
|
2018-01-12 04:47:45 -06:00
|
|
|
expectAccountFollows,
|
2018-01-18 03:53:54 -06:00
|
|
|
getAccountsList,
|
2019-04-09 04:02:02 -05:00
|
|
|
checkActorFilesWereRemoved,
|
|
|
|
getAccountRatings
|
2018-01-03 09:38:50 -06:00
|
|
|
}
|