mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Add user import/export tests
This commit is contained in:
parent
8573e5a80a
commit
f6af3f701c
51 changed files with 2852 additions and 433 deletions
77
packages/server-commands/src/users/user-exports-command.ts
Normal file
77
packages/server-commands/src/users/user-exports-command.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
import { HttpStatusCode, ResultList, UserExport, UserExportRequestResult, UserExportState } from '@peertube/peertube-models'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
|
||||
import { wait } from '@peertube/peertube-core-utils'
|
||||
import { unwrapBody } from '../requests/requests.js'
|
||||
|
||||
export class UserExportsCommand extends AbstractCommand {
|
||||
|
||||
request (options: OverrideCommandOptions & {
|
||||
userId: number
|
||||
withVideoFiles: boolean
|
||||
}) {
|
||||
const { userId, withVideoFiles } = options
|
||||
|
||||
return unwrapBody<UserExportRequestResult>(this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path: `/api/v1/users/${userId}/exports/request`,
|
||||
fields: { withVideoFiles },
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
}))
|
||||
}
|
||||
|
||||
async waitForCreation (options: OverrideCommandOptions & {
|
||||
userId: number
|
||||
}) {
|
||||
const { userId } = options
|
||||
|
||||
while (true) {
|
||||
const { data } = await this.list({ ...options, userId })
|
||||
|
||||
if (data.some(e => e.state.id === UserExportState.COMPLETED)) break
|
||||
|
||||
await wait(250)
|
||||
}
|
||||
}
|
||||
|
||||
list (options: OverrideCommandOptions & {
|
||||
userId: number
|
||||
}) {
|
||||
const { userId } = options
|
||||
|
||||
return this.getRequestBody<ResultList<UserExport>>({
|
||||
...options,
|
||||
|
||||
path: `/api/v1/users/${userId}/exports`,
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
})
|
||||
}
|
||||
|
||||
async deleteAllArchives (options: OverrideCommandOptions & {
|
||||
userId: number
|
||||
}) {
|
||||
const { data } = await this.list(options)
|
||||
|
||||
for (const { id } of data) {
|
||||
await this.delete({ ...options, exportId: id })
|
||||
}
|
||||
}
|
||||
|
||||
delete (options: OverrideCommandOptions & {
|
||||
exportId: number
|
||||
userId: number
|
||||
}) {
|
||||
const { userId, exportId } = options
|
||||
|
||||
return this.deleteRequest({
|
||||
...options,
|
||||
|
||||
path: `/api/v1/users/${userId}/exports/${exportId}`,
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue