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'
10 const expect = chai.expect
12 describe('Test contact form', function () {
13 let server: ServerInfo
14 const emails: object[] = []
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 ])
31 it('Should send a contact form', async function () {
34 await sendContactForm({
36 fromEmail: 'toto@example.com',
37 body: 'my super message',
38 subject: 'my subject',
39 fromName: 'Super toto'
42 await waitJobs(server)
44 expect(emails).to.have.lengthOf(1)
46 const email = emails[0]
48 expect(email['from'][0]['address']).equal('test-admin@localhost')
49 expect(email['replyTo'][0]['address']).equal('toto@example.com')
50 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
51 expect(email['subject']).contains('my subject')
52 expect(email['text']).contains('my super message')
55 it('Should not be able to send another contact form because of the anti spam checker', async function () {
56 await sendContactForm({
58 fromEmail: 'toto@example.com',
59 body: 'my super message',
60 subject: 'my subject',
61 fromName: 'Super toto'
64 await sendContactForm({
66 fromEmail: 'toto@example.com',
67 body: 'my super message',
68 fromName: 'Super toto',
69 subject: 'my subject',
74 it('Should be able to send another contact form after a while', async function () {
77 await sendContactForm({
79 fromEmail: 'toto@example.com',
80 fromName: 'Super toto',
81 subject: 'my subject',
82 body: 'my super message'
86 it('Should not have the manage preferences link in the email', async function () {
87 const email = emails[0]
88 expect(email['text']).to.not.contain('Manage your notification preferences')
91 after(async function () {
92 MockSmtpServer.Instance.kill()
94 await cleanupTests([ server ])