diff options
Diffstat (limited to 'packages/tests/src/api/check-params/users-emails.ts')
-rw-r--r-- | packages/tests/src/api/check-params/users-emails.ts | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/packages/tests/src/api/check-params/users-emails.ts b/packages/tests/src/api/check-params/users-emails.ts new file mode 100644 index 000000000..e382190ec --- /dev/null +++ b/packages/tests/src/api/check-params/users-emails.ts | |||
@@ -0,0 +1,122 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | import { HttpStatusCode, UserRole } from '@peertube/peertube-models' | ||
3 | import { | ||
4 | cleanupTests, | ||
5 | createSingleServer, | ||
6 | makePostBodyRequest, | ||
7 | PeerTubeServer, | ||
8 | setAccessTokensToServers | ||
9 | } from '@peertube/peertube-server-commands' | ||
10 | |||
11 | describe('Test users API validators', function () { | ||
12 | let server: PeerTubeServer | ||
13 | |||
14 | // --------------------------------------------------------------- | ||
15 | |||
16 | before(async function () { | ||
17 | this.timeout(30000) | ||
18 | |||
19 | server = await createSingleServer(1, { | ||
20 | rates_limit: { | ||
21 | ask_send_email: { | ||
22 | max: 10 | ||
23 | } | ||
24 | } | ||
25 | }) | ||
26 | |||
27 | await setAccessTokensToServers([ server ]) | ||
28 | await server.config.enableSignup(true) | ||
29 | |||
30 | await server.users.generate('moderator2', UserRole.MODERATOR) | ||
31 | |||
32 | await server.registrations.requestRegistration({ | ||
33 | username: 'request1', | ||
34 | registrationReason: 'tt' | ||
35 | }) | ||
36 | }) | ||
37 | |||
38 | describe('When asking a password reset', function () { | ||
39 | const path = '/api/v1/users/ask-reset-password' | ||
40 | |||
41 | it('Should fail with a missing email', async function () { | ||
42 | const fields = {} | ||
43 | |||
44 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
45 | }) | ||
46 | |||
47 | it('Should fail with an invalid email', async function () { | ||
48 | const fields = { email: 'hello' } | ||
49 | |||
50 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
51 | }) | ||
52 | |||
53 | it('Should success with the correct params', async function () { | ||
54 | const fields = { email: 'admin@example.com' } | ||
55 | |||
56 | await makePostBodyRequest({ | ||
57 | url: server.url, | ||
58 | path, | ||
59 | fields, | ||
60 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
61 | }) | ||
62 | }) | ||
63 | }) | ||
64 | |||
65 | describe('When asking for an account verification email', function () { | ||
66 | const path = '/api/v1/users/ask-send-verify-email' | ||
67 | |||
68 | it('Should fail with a missing email', async function () { | ||
69 | const fields = {} | ||
70 | |||
71 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
72 | }) | ||
73 | |||
74 | it('Should fail with an invalid email', async function () { | ||
75 | const fields = { email: 'hello' } | ||
76 | |||
77 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
78 | }) | ||
79 | |||
80 | it('Should succeed with the correct params', async function () { | ||
81 | const fields = { email: 'admin@example.com' } | ||
82 | |||
83 | await makePostBodyRequest({ | ||
84 | url: server.url, | ||
85 | path, | ||
86 | fields, | ||
87 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
88 | }) | ||
89 | }) | ||
90 | }) | ||
91 | |||
92 | describe('When asking for a registration verification email', function () { | ||
93 | const path = '/api/v1/users/registrations/ask-send-verify-email' | ||
94 | |||
95 | it('Should fail with a missing email', async function () { | ||
96 | const fields = {} | ||
97 | |||
98 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
99 | }) | ||
100 | |||
101 | it('Should fail with an invalid email', async function () { | ||
102 | const fields = { email: 'hello' } | ||
103 | |||
104 | await makePostBodyRequest({ url: server.url, path, fields }) | ||
105 | }) | ||
106 | |||
107 | it('Should succeed with the correct params', async function () { | ||
108 | const fields = { email: 'request1@example.com' } | ||
109 | |||
110 | await makePostBodyRequest({ | ||
111 | url: server.url, | ||
112 | path, | ||
113 | fields, | ||
114 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
115 | }) | ||
116 | }) | ||
117 | }) | ||
118 | |||
119 | after(async function () { | ||
120 | await cleanupTests([ server ]) | ||
121 | }) | ||
122 | }) | ||