aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/contact-form.ts69
1 files changed, 17 insertions, 52 deletions
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index 274562cbb..fb30766d9 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '@shared/core-utils'
5import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' 5import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils'
6import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 6import { ContactFormCommand } from '@shared/extra-utils/server'
7import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
8 7
9describe('Test contact form API validators', function () { 8describe('Test contact form API validators', function () {
10 let server: ServerInfo 9 let server: ServerInfo
@@ -16,6 +15,7 @@ describe('Test contact form API validators', function () {
16 body: 'Hello, how are you?' 15 body: 'Hello, how are you?'
17 } 16 }
18 let emailPort: number 17 let emailPort: number
18 let command: ContactFormCommand
19 19
20 // --------------------------------------------------------------- 20 // ---------------------------------------------------------------
21 21
@@ -26,10 +26,11 @@ describe('Test contact form API validators', function () {
26 26
27 // Email is disabled 27 // Email is disabled
28 server = await flushAndRunServer(1) 28 server = await flushAndRunServer(1)
29 command = server.contactFormCommand
29 }) 30 })
30 31
31 it('Should not accept a contact form if emails are disabled', async function () { 32 it('Should not accept a contact form if emails are disabled', async function () {
32 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 33 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
33 }) 34 })
34 35
35 it('Should not accept a contact form if it is disabled in the configuration', async function () { 36 it('Should not accept a contact form if it is disabled in the configuration', async function () {
@@ -39,7 +40,7 @@ describe('Test contact form API validators', function () {
39 40
40 // Contact form is disabled 41 // Contact form is disabled
41 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) 42 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
42 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 43 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
43 }) 44 })
44 45
45 it('Should not accept a contact form if from email is invalid', async function () { 46 it('Should not accept a contact form if from email is invalid', async function () {
@@ -50,61 +51,25 @@ describe('Test contact form API validators', function () {
50 // Email & contact form enabled 51 // Email & contact form enabled
51 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) 52 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
52 53
53 await sendContactForm(immutableAssign(defaultBody, { 54 await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
54 url: server.url, 55 await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
55 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 56 await command.send({ ...defaultBody, fromEmail: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
56 fromEmail: 'badEmail'
57 }))
58 await sendContactForm(immutableAssign(defaultBody, {
59 url: server.url,
60 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
61 fromEmail: 'badEmail@'
62 }))
63 await sendContactForm(immutableAssign(defaultBody, {
64 url: server.url,
65 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
66 fromEmail: undefined
67 }))
68 }) 57 })
69 58
70 it('Should not accept a contact form if from name is invalid', async function () { 59 it('Should not accept a contact form if from name is invalid', async function () {
71 await sendContactForm(immutableAssign(defaultBody, { 60 await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
72 url: server.url, 61 await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
73 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 62 await command.send({ ...defaultBody, fromName: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
74 fromName: 'name'.repeat(100)
75 }))
76 await sendContactForm(immutableAssign(defaultBody, {
77 url: server.url,
78 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
79 fromName: ''
80 }))
81 await sendContactForm(immutableAssign(defaultBody, {
82 url: server.url,
83 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
84 fromName: undefined
85 }))
86 }) 63 })
87 64
88 it('Should not accept a contact form if body is invalid', async function () { 65 it('Should not accept a contact form if body is invalid', async function () {
89 await sendContactForm(immutableAssign(defaultBody, { 66 await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
90 url: server.url, 67 await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
91 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 68 await command.send({ ...defaultBody, body: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
92 body: 'body'.repeat(5000)
93 }))
94 await sendContactForm(immutableAssign(defaultBody, {
95 url: server.url,
96 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
97 body: 'a'
98 }))
99 await sendContactForm(immutableAssign(defaultBody, {
100 url: server.url,
101 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
102 body: undefined
103 }))
104 }) 69 })
105 70
106 it('Should accept a contact form with the correct parameters', async function () { 71 it('Should accept a contact form with the correct parameters', async function () {
107 await sendContactForm(immutableAssign(defaultBody, { url: server.url })) 72 await command.send({ ...defaultBody })
108 }) 73 })
109 74
110 after(async function () { 75 after(async function () {