PeerTube/shared/extra-utils/users/accounts.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-01-12 04:47:45 -06:00
import { expect } from 'chai'
2021-07-07 06:38:26 -05:00
import { pathExists, readdir } from 'fs-extra'
import { join } from 'path'
2021-07-07 06:38:26 -05:00
import { root } from '@server/helpers/core-utils'
2021-07-16 02:47:51 -05:00
import { PeerTubeServer } from '../server'
2021-07-07 06:38:26 -05:00
async function expectAccountFollows (options: {
2021-07-16 02:47:51 -05:00
server: PeerTubeServer
2021-07-07 06:38:26 -05:00
handle: string
followers: number
following: number
}) {
const { server, handle, followers, following } = options
2021-07-16 02:04:35 -05:00
const body = await server.accounts.list()
2021-07-07 06:38:26 -05:00
const account = body.data.find(a => a.name + '@' + a.host === handle)
const message = `${handle} on ${server.url}`
expect(account.followersCount).to.equal(followers, message)
expect(account.followingCount).to.equal(following, message)
2018-01-12 04:47:45 -06:00
}
2019-05-31 07:02:26 -05: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 06:38:26 -05:00
const directoryExists = await pathExists(directoryPath)
expect(directoryExists).to.be.true
2018-08-27 09:23:34 -05:00
const files = await readdir(directoryPath)
for (const file of files) {
2019-05-31 07:02:26 -05:00
expect(file).to.not.contain(filename)
}
}
}
2018-01-03 09:38:50 -06:00
export {
2018-01-12 04:47:45 -06:00
expectAccountFollows,
2021-07-07 06:38:26 -05:00
checkActorFilesWereRemoved
2018-01-03 09:38:50 -06:00
}