mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Add signup approval API tests
This commit is contained in:
parent
3e5716dd3a
commit
b379759f55
30 changed files with 1418 additions and 452 deletions
157
shared/server-commands/users/registrations-command.ts
Normal file
157
shared/server-commands/users/registrations-command.ts
Normal file
|
@ -0,0 +1,157 @@
|
|||
import { pick } from '@shared/core-utils'
|
||||
import { HttpStatusCode, ResultList, UserRegistration, UserRegistrationRequest } from '@shared/models'
|
||||
import { unwrapBody } from '../requests'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||
|
||||
export class RegistrationsCommand extends AbstractCommand {
|
||||
|
||||
register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) {
|
||||
const { password = 'password', email = options.username + '@example.com' } = options
|
||||
const path = '/api/v1/users/register'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: {
|
||||
...pick(options, [ 'username', 'displayName', 'channel' ]),
|
||||
|
||||
password,
|
||||
email
|
||||
},
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
requestRegistration (
|
||||
options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'>
|
||||
) {
|
||||
const { password = 'password', email = options.username + '@example.com' } = options
|
||||
const path = '/api/v1/users/registrations/request'
|
||||
|
||||
return unwrapBody<UserRegistration>(this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: {
|
||||
...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]),
|
||||
|
||||
password,
|
||||
email
|
||||
},
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
}))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
accept (options: OverrideCommandOptions & {
|
||||
id: number
|
||||
moderationResponse: string
|
||||
}) {
|
||||
const { id, moderationResponse } = options
|
||||
const path = '/api/v1/users/registrations/' + id + '/accept'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: { moderationResponse },
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
reject (options: OverrideCommandOptions & {
|
||||
id: number
|
||||
moderationResponse: string
|
||||
}) {
|
||||
const { id, moderationResponse } = options
|
||||
const path = '/api/v1/users/registrations/' + id + '/reject'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: { moderationResponse },
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
delete (options: OverrideCommandOptions & {
|
||||
id: number
|
||||
}) {
|
||||
const { id } = options
|
||||
const path = '/api/v1/users/registrations/' + id
|
||||
|
||||
return this.deleteRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
list (options: OverrideCommandOptions & {
|
||||
start?: number
|
||||
count?: number
|
||||
sort?: string
|
||||
search?: string
|
||||
} = {}) {
|
||||
const path = '/api/v1/users/registrations'
|
||||
|
||||
return this.getRequestBody<ResultList<UserRegistration>>({
|
||||
...options,
|
||||
|
||||
path,
|
||||
query: pick(options, [ 'start', 'count', 'sort', 'search' ]),
|
||||
implicitToken: true,
|
||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
askSendVerifyEmail (options: OverrideCommandOptions & {
|
||||
email: string
|
||||
}) {
|
||||
const { email } = options
|
||||
const path = '/api/v1/users/registrations/ask-send-verify-email'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: { email },
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
|
||||
verifyEmail (options: OverrideCommandOptions & {
|
||||
registrationId: number
|
||||
verificationString: string
|
||||
}) {
|
||||
const { registrationId, verificationString } = options
|
||||
const path = '/api/v1/users/registrations/' + registrationId + '/verify-email'
|
||||
|
||||
return this.postBodyRequest({
|
||||
...options,
|
||||
|
||||
path,
|
||||
fields: {
|
||||
verificationString
|
||||
},
|
||||
implicitToken: false,
|
||||
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue