1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
4 import { expect } from 'chai'
5 import { existsSync, readdir } from 'fs-extra'
6 import { join } from 'path'
7 import { Account } from '../../models/actors'
8 import { root } from '../miscs/miscs'
9 import { makeGetRequest } from '../requests/requests'
10 import { VideoRateType } from '../../models/videos'
12 function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
13 const path = '/api/v1/accounts'
15 return makeGetRequest({
23 function getAccount (url: string, accountName: string, statusCodeExpected = 200) {
24 const path = '/api/v1/accounts/' + accountName
26 return makeGetRequest({
33 async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
34 const res = await getAccountsList(url)
35 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
37 const message = `${nameWithDomain} on ${url}`
38 expect(account.followersCount).to.equal(followersCount, message)
39 expect(account.followingCount).to.equal(followingCount, message)
42 async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
43 const testDirectory = 'test' + serverNumber
45 for (const directory of [ 'avatars' ]) {
46 const directoryPath = join(root(), testDirectory, directory)
48 const directoryExists = existsSync(directoryPath)
49 expect(directoryExists).to.be.true
51 const files = await readdir(directoryPath)
52 for (const file of files) {
53 expect(file).to.not.contain(filename)
58 function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) {
59 const path = '/api/v1/accounts/' + accountName + '/ratings'
61 const query = rating ? { rating } : {}
66 .set('Accept', 'application/json')
67 .set('Authorization', 'Bearer ' + accessToken)
68 .expect(statusCodeExpected)
69 .expect('Content-Type', /json/)
72 // ---------------------------------------------------------------------------
78 checkActorFilesWereRemoved,