1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 setAccessTokensToServers,
13 } from '../../../../shared/extra-utils'
14 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
15 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16 import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
18 const expect = chai.expect
20 describe('Test contact form', function () {
21 let server: ServerInfo
22 const emails: object[] = []
24 before(async function () {
27 const port = await MockSmtpServer.Instance.collectEmails(emails)
29 const overrideConfig = {
31 hostname: 'localhost',
35 server = await flushAndRunServer(1, overrideConfig)
36 await setAccessTokensToServers([ server ])
39 it('Should send a contact form', async function () {
42 await sendContactForm({
44 fromEmail: 'toto@example.com',
45 body: 'my super message',
46 fromName: 'Super toto'
49 await waitJobs(server)
51 expect(emails).to.have.lengthOf(1)
53 const email = emails[0]
55 expect(email['from'][0]['address']).equal('test-admin@localhost')
56 expect(email['from'][0]['name']).equal('toto@example.com')
57 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
58 expect(email['subject']).contains('Contact form')
59 expect(email['text']).contains('my super message')
62 it('Should not be able to send another contact form because of the anti spam checker', async function () {
63 await sendContactForm({
65 fromEmail: 'toto@example.com',
66 body: 'my super message',
67 fromName: 'Super toto'
70 await sendContactForm({
72 fromEmail: 'toto@example.com',
73 body: 'my super message',
74 fromName: 'Super toto',
79 it('Should be able to send another contact form after a while', async function () {
82 await sendContactForm({
84 fromEmail: 'toto@example.com',
85 body: 'my super message',
86 fromName: 'Super toto'
90 after(async function () {
91 MockSmtpServer.Instance.kill()
93 await cleanupTests([ server ])