1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils'
6 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
7 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
8 import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
9 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
11 const expect = chai.expect
13 describe('Test contact form', function () {
14 let server: ServerInfo
15 const emails: object[] = []
17 before(async function () {
20 const port = await MockSmtpServer.Instance.collectEmails(emails)
22 const overrideConfig = {
24 hostname: 'localhost',
28 server = await flushAndRunServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ])
32 it('Should send a contact form', async function () {
35 await sendContactForm({
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 () {
57 await sendContactForm({
59 fromEmail: 'toto@example.com',
60 body: 'my super message',
61 subject: 'my subject',
62 fromName: 'Super toto'
65 await sendContactForm({
67 fromEmail: 'toto@example.com',
68 body: 'my super message',
69 fromName: 'Super toto',
70 subject: 'my subject',
71 expectedStatus: HttpStatusCode.FORBIDDEN_403
75 it('Should be able to send another contact form after a while', async function () {
78 await sendContactForm({
80 fromEmail: 'toto@example.com',
81 fromName: 'Super toto',
82 subject: 'my subject',
83 body: 'my super message'
87 it('Should not have the manage preferences link in the email', async function () {
88 const email = emails[0]
89 expect(email['text']).to.not.contain('Manage your notification preferences')
92 after(async function () {
93 MockSmtpServer.Instance.kill()
95 await cleanupTests([ server ])