1 /* tslint:disable:no-unused-expression */
12 setAccessTokensToServers, cleanupTests
13 } from '../../../../shared/extra-utils'
15 checkBadCountPagination,
16 checkBadSortPagination,
17 checkBadStartPagination
18 } from '../../../../shared/extra-utils/requests/check-api-params'
19 import { getAccount } from '../../../../shared/extra-utils/users/accounts'
20 import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
21 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
23 describe('Test contact form API validators', function () {
24 let server: ServerInfo
25 const emails: object[] = []
27 fromName: 'super name',
28 fromEmail: 'toto@example.com',
29 subject: 'my subject',
30 body: 'Hello, how are you?'
34 // ---------------------------------------------------------------
36 before(async function () {
39 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
42 server = await flushAndRunServer(1)
45 it('Should not accept a contact form if emails are disabled', async function () {
46 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
49 it('Should not accept a contact form if it is disabled in the configuration', async function () {
52 killallServers([ server ])
54 // Contact form is disabled
55 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
56 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
59 it('Should not accept a contact form if from email is invalid', async function () {
62 killallServers([ server ])
64 // Email & contact form enabled
65 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
68 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
69 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
72 it('Should not accept a contact form if from name is invalid', async function () {
73 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
74 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
75 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
78 it('Should not accept a contact form if body is invalid', async function () {
79 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
80 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
81 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
84 it('Should accept a contact form with the correct parameters', async function () {
85 await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
88 after(async function () {
89 MockSmtpServer.Instance.kill()
91 await cleanupTests([ server ])