PeerTube/server/tests/shared/actors.ts

74 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-01-12 11:47:45 +01:00
import { expect } from 'chai'
2021-07-07 13:38:26 +02:00
import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
import { root } from '@shared/core-utils'
import { Account, VideoChannel } from '@shared/models'
import { PeerTubeServer } from '@shared/server-commands'
2021-07-07 13:38:26 +02:00
async function expectChannelsFollows (options: {
2021-07-16 09:47:51 +02:00
server: PeerTubeServer
2021-07-07 13:38:26 +02:00
handle: string
followers: number
following: number
}) {
const { server } = options
const { data } = await server.channels.list()
2021-07-07 13:38:26 +02:00
return expectActorFollow({ ...options, data })
}
2021-07-07 13:38:26 +02: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 11:47:45 +01:00
}
2019-05-31 14:02:26 +02:00
async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
const testDirectory = 'test' + serverNumber
for (const directory of [ 'avatars' ]) {
const directoryPath = join(root(), testDirectory, directory)
2021-07-07 13:38:26 +02:00
const directoryExists = await pathExists(directoryPath)
expect(directoryExists).to.be.true
2018-08-27 16:23:34 +02:00
const files = await readdir(directoryPath)
for (const file of files) {
2019-05-31 14:02:26 +02:00
expect(file).to.not.contain(filename)
}
}
}
2018-01-03 16:38:50 +01:00
export {
2018-01-12 11:47:45 +01:00
expectAccountFollows,
expectChannelsFollows,
2021-07-07 13:38:26 +02:00
checkActorFilesWereRemoved
2018-01-03 16:38:50 +01: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)
}