1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils'
7 import { ContactFormCommand } from '@shared/extra-utils/server'
9 const expect = chai.expect
11 describe('Test contact form', function () {
12 let server: ServerInfo
13 const emails: object[] = []
14 let command: ContactFormCommand
16 before(async function () {
19 const port = await MockSmtpServer.Instance.collectEmails(emails)
21 const overrideConfig = {
23 hostname: 'localhost',
27 server = await flushAndRunServer(1, overrideConfig)
28 await setAccessTokensToServers([ server ])
30 command = server.contactFormCommand
33 it('Should send a contact form', async function () {
37 fromEmail: 'toto@example.com',
38 body: 'my super message',
39 subject: 'my subject',
40 fromName: 'Super toto'
43 await waitJobs(server)
45 expect(emails).to.have.lengthOf(1)
47 const email = emails[0]
49 expect(email['from'][0]['address']).equal('test-admin@localhost')
50 expect(email['replyTo'][0]['address']).equal('toto@example.com')
51 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
52 expect(email['subject']).contains('my subject')
53 expect(email['text']).contains('my super message')
56 it('Should not be able to send another contact form because of the anti spam checker', async function () {
62 fromEmail: 'toto@example.com',
63 body: 'my super message',
64 subject: 'my subject',
65 fromName: 'Super toto'
69 fromEmail: 'toto@example.com',
70 body: 'my super message',
71 fromName: 'Super toto',
72 subject: 'my subject',
73 expectedStatus: HttpStatusCode.FORBIDDEN_403
77 it('Should be able to send another contact form after a while', async function () {
81 fromEmail: 'toto@example.com',
82 fromName: 'Super toto',
83 subject: 'my subject',
84 body: 'my super message'
88 it('Should not have the manage preferences link in the email', async function () {
89 const email = emails[0]
90 expect(email['text']).to.not.contain('Manage your notification preferences')
93 after(async function () {
94 MockSmtpServer.Instance.kill()
96 await cleanupTests([ server ])