2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-01-18 04:53:54 -05:00
|
|
|
|
2018-01-12 05:47:45 -05:00
|
|
|
import { expect } from 'chai'
|
2021-07-07 07:38:26 -04:00
|
|
|
import { pathExists, readdir } from 'fs-extra'
|
2018-01-18 04:53:54 -05:00
|
|
|
import { join } from 'path'
|
2021-11-02 14:11:20 -04:00
|
|
|
import { root } from '@shared/core-utils'
|
2021-07-20 08:15:15 -04:00
|
|
|
import { Account, VideoChannel } from '@shared/models'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { PeerTubeServer } from '@shared/server-commands'
|
2021-07-07 07:38:26 -04:00
|
|
|
|
2021-07-20 08:15:15 -04:00
|
|
|
async function expectChannelsFollows (options: {
|
2021-07-16 03:47:51 -04:00
|
|
|
server: PeerTubeServer
|
2021-07-07 07:38:26 -04:00
|
|
|
handle: string
|
|
|
|
followers: number
|
|
|
|
following: number
|
|
|
|
}) {
|
2021-07-20 08:15:15 -04:00
|
|
|
const { server } = options
|
|
|
|
const { data } = await server.channels.list()
|
2021-07-07 07:38:26 -04:00
|
|
|
|
2021-07-20 08:15:15 -04:00
|
|
|
return expectActorFollow({ ...options, data })
|
|
|
|
}
|
2021-07-07 07:38:26 -04:00
|
|
|
|
2021-07-20 08:15:15 -04:00
|
|
|
async function expectAccountFollows (options: {
|
|
|
|
server: PeerTubeServer
|
|
|
|
handle: string
|
|
|
|
followers: number
|
|
|
|
following: number
|
|
|
|
}) {
|
|
|
|
const { server } = options
|
|
|
|
const { data } = await server.accounts.list()
|
|
|
|
|
|
|
|
return expectActorFollow({ ...options, data })
|
2018-01-12 05:47:45 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 08:02:26 -04:00
|
|
|
async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
|
2018-01-18 04:53:54 -05:00
|
|
|
const testDirectory = 'test' + serverNumber
|
|
|
|
|
|
|
|
for (const directory of [ 'avatars' ]) {
|
|
|
|
const directoryPath = join(root(), testDirectory, directory)
|
|
|
|
|
2021-07-07 07:38:26 -04:00
|
|
|
const directoryExists = await pathExists(directoryPath)
|
2018-01-18 04:53:54 -05:00
|
|
|
expect(directoryExists).to.be.true
|
|
|
|
|
2018-08-27 10:23:34 -04:00
|
|
|
const files = await readdir(directoryPath)
|
2018-01-18 04:53:54 -05:00
|
|
|
for (const file of files) {
|
2019-05-31 08:02:26 -04:00
|
|
|
expect(file).to.not.contain(filename)
|
2018-01-18 04:53:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 10:38:50 -05:00
|
|
|
export {
|
2018-01-12 05:47:45 -05:00
|
|
|
expectAccountFollows,
|
2021-07-20 08:15:15 -04:00
|
|
|
expectChannelsFollows,
|
2021-07-07 07:38:26 -04:00
|
|
|
checkActorFilesWereRemoved
|
2018-01-03 10:38:50 -05:00
|
|
|
}
|
2021-07-20 08:15:15 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function expectActorFollow (options: {
|
|
|
|
server: PeerTubeServer
|
|
|
|
data: (Account | VideoChannel)[]
|
|
|
|
handle: string
|
|
|
|
followers: number
|
|
|
|
following: number
|
|
|
|
}) {
|
|
|
|
const { server, data, handle, followers, following } = options
|
|
|
|
|
|
|
|
const actor = data.find(a => a.name + '@' + a.host === handle)
|
|
|
|
const message = `${handle} on ${server.url}`
|
|
|
|
|
|
|
|
expect(actor, message).to.exist
|
|
|
|
expect(actor.followersCount).to.equal(followers, message)
|
|
|
|
expect(actor.followingCount).to.equal(following, message)
|
|
|
|
}
|