1 /* tslint:disable:no-unused-expression */
12 setAccessTokensToServers
13 } from '../../../../shared/utils'
15 checkBadCountPagination,
16 checkBadSortPagination,
17 checkBadStartPagination
18 } from '../../../../shared/utils/requests/check-api-params'
19 import { getAccount } from '../../../../shared/utils/users/accounts'
20 import { sendContactForm } from '../../../../shared/utils/server/contact-form'
21 import { MockSmtpServer } from '../../../../shared/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 body: 'Hello, how are you?'
32 // ---------------------------------------------------------------
34 before(async function () {
38 await MockSmtpServer.Instance.collectEmails(emails)
41 server = await runServer(1)
44 it('Should not accept a contact form if emails are disabled', async function () {
45 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
48 it('Should not accept a contact form if it is disabled in the configuration', async function () {
51 killallServers([ server ])
53 // Contact form is disabled
54 await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } })
55 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
58 it('Should not accept a contact form if from email is invalid', async function () {
61 killallServers([ server ])
63 // Email & contact form enabled
64 await reRunServer(server, { smtp: { hostname: 'localhost' } })
66 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
68 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
71 it('Should not accept a contact form if from name is invalid', async function () {
72 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
73 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
74 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
77 it('Should not accept a contact form if body is invalid', async function () {
78 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
79 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
80 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
83 it('Should accept a contact form with the correct parameters', async function () {
84 await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
87 after(async function () {
88 MockSmtpServer.Instance.kill()
89 killallServers([ server ])
91 // Keep the logs if the test failed