1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/utils'
6 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
7 import { waitJobs } from '../../../../shared/utils/server/jobs'
8 import { sendContactForm } from '../../../../shared/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 await MockSmtpServer.Instance.collectEmails(emails)
23 const overrideConfig = {
28 server = await runServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ])
32 it('Should send a contact form', async function () {
33 await sendContactForm({
35 fromEmail: 'toto@example.com',
36 body: 'my super message',
37 fromName: 'Super toto'
40 await waitJobs(server)
42 expect(emails).to.have.lengthOf(1)
44 const email = emails[0]
46 expect(email['from'][0]['address']).equal('toto@example.com')
47 expect(email['to'][0]['address']).equal('admin1@example.com')
48 expect(email['subject']).contains('Contact form')
49 expect(email['text']).contains('my super message')
52 it('Should not be able to send another contact form because of the anti spam checker', async function () {
53 await sendContactForm({
55 fromEmail: 'toto@example.com',
56 body: 'my super message',
57 fromName: 'Super toto'
60 await sendContactForm({
62 fromEmail: 'toto@example.com',
63 body: 'my super message',
64 fromName: 'Super toto',
69 it('Should be able to send another contact form after a while', async function () {
72 await sendContactForm({
74 fromEmail: 'toto@example.com',
75 body: 'my super message',
76 fromName: 'Super toto'
80 after(async function () {
81 MockSmtpServer.Instance.kill()
82 killallServers([ server ])