1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 import { MockSmtpServer } from '@server/tests/shared'
3 import { HttpStatusCode, UserRole } from '@shared/models'
4 import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6 describe('Test users API validators', function () {
7 let server: PeerTubeServer
9 // ---------------------------------------------------------------
11 before(async function () {
14 server = await createSingleServer(1, {
22 await setAccessTokensToServers([ server ])
23 await server.config.enableSignup(true)
25 await server.users.generate('moderator2', UserRole.MODERATOR)
27 await server.registrations.requestRegistration({
29 registrationReason: 'tt'
33 describe('When asking a password reset', function () {
34 const path = '/api/v1/users/ask-reset-password'
36 it('Should fail with a missing email', async function () {
39 await makePostBodyRequest({ url: server.url, path, fields })
42 it('Should fail with an invalid email', async function () {
43 const fields = { email: 'hello' }
45 await makePostBodyRequest({ url: server.url, path, fields })
48 it('Should success with the correct params', async function () {
49 const fields = { email: 'admin@example.com' }
51 await makePostBodyRequest({
55 expectedStatus: HttpStatusCode.NO_CONTENT_204
60 describe('When asking for an account verification email', function () {
61 const path = '/api/v1/users/ask-send-verify-email'
63 it('Should fail with a missing email', async function () {
66 await makePostBodyRequest({ url: server.url, path, fields })
69 it('Should fail with an invalid email', async function () {
70 const fields = { email: 'hello' }
72 await makePostBodyRequest({ url: server.url, path, fields })
75 it('Should succeed with the correct params', async function () {
76 const fields = { email: 'admin@example.com' }
78 await makePostBodyRequest({
82 expectedStatus: HttpStatusCode.NO_CONTENT_204
87 describe('When asking for a registration verification email', function () {
88 const path = '/api/v1/users/registrations/ask-send-verify-email'
90 it('Should fail with a missing email', async function () {
93 await makePostBodyRequest({ url: server.url, path, fields })
96 it('Should fail with an invalid email', async function () {
97 const fields = { email: 'hello' }
99 await makePostBodyRequest({ url: server.url, path, fields })
102 it('Should succeed with the correct params', async function () {
103 const fields = { email: 'request1@example.com' }
105 await makePostBodyRequest({
109 expectedStatus: HttpStatusCode.NO_CONTENT_204
114 after(async function () {
115 MockSmtpServer.Instance.kill()
117 await cleanupTests([ server ])