1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 import { HttpStatusCode, UserRole } from '@shared/models'
3 import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 describe('Test users API validators', function () {
6 let server: PeerTubeServer
8 // ---------------------------------------------------------------
10 before(async function () {
13 server = await createSingleServer(1, {
21 await setAccessTokensToServers([ server ])
22 await server.config.enableSignup(true)
24 await server.users.generate('moderator2', UserRole.MODERATOR)
26 await server.registrations.requestRegistration({
28 registrationReason: 'tt'
32 describe('When asking a password reset', function () {
33 const path = '/api/v1/users/ask-reset-password'
35 it('Should fail with a missing email', async function () {
38 await makePostBodyRequest({ url: server.url, path, fields })
41 it('Should fail with an invalid email', async function () {
42 const fields = { email: 'hello' }
44 await makePostBodyRequest({ url: server.url, path, fields })
47 it('Should success with the correct params', async function () {
48 const fields = { email: 'admin@example.com' }
50 await makePostBodyRequest({
54 expectedStatus: HttpStatusCode.NO_CONTENT_204
59 describe('When asking for an account verification email', function () {
60 const path = '/api/v1/users/ask-send-verify-email'
62 it('Should fail with a missing email', async function () {
65 await makePostBodyRequest({ url: server.url, path, fields })
68 it('Should fail with an invalid email', async function () {
69 const fields = { email: 'hello' }
71 await makePostBodyRequest({ url: server.url, path, fields })
74 it('Should succeed with the correct params', async function () {
75 const fields = { email: 'admin@example.com' }
77 await makePostBodyRequest({
81 expectedStatus: HttpStatusCode.NO_CONTENT_204
86 describe('When asking for a registration verification email', function () {
87 const path = '/api/v1/users/registrations/ask-send-verify-email'
89 it('Should fail with a missing email', async function () {
92 await makePostBodyRequest({ url: server.url, path, fields })
95 it('Should fail with an invalid email', async function () {
96 const fields = { email: 'hello' }
98 await makePostBodyRequest({ url: server.url, path, fields })
101 it('Should succeed with the correct params', async function () {
102 const fields = { email: 'request1@example.com' }
104 await makePostBodyRequest({
108 expectedStatus: HttpStatusCode.NO_CONTENT_204
113 after(async function () {
114 await cleanupTests([ server ])