1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushTests, killallServers, 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 await MockSmtpServer.Instance.collectEmails(emails)
21 const overrideConfig = {
26 server = await flushAndRunServer(1, overrideConfig)
27 await setAccessTokensToServers([ server ])
30 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('test-admin@localhost')
47 expect(email['from'][0]['name']).equal('toto@example.com')
48 expect(email['to'][0]['address']).equal('admin1@example.com')
49 expect(email['subject']).contains('Contact form')
50 expect(email['text']).contains('my super message')
53 it('Should not be able to send another contact form because of the anti spam checker', async function () {
54 await sendContactForm({
56 fromEmail: 'toto@example.com',
57 body: 'my super message',
58 fromName: 'Super toto'
61 await sendContactForm({
63 fromEmail: 'toto@example.com',
64 body: 'my super message',
65 fromName: 'Super toto',
70 it('Should be able to send another contact form after a while', async function () {
73 await sendContactForm({
75 fromEmail: 'toto@example.com',
76 body: 'my super message',
77 fromName: 'Super toto'
82 MockSmtpServer.Instance.kill()
83 killallServers([ server ])