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 await MockSmtpServer.Instance.collectEmails(emails)
29 const overrideConfig = {
34 server = await flushAndRunServer(1, overrideConfig)
35 await setAccessTokensToServers([ server ])
38 it('Should send a contact form', async function () {
41 await sendContactForm({
43 fromEmail: 'toto@example.com',
44 body: 'my super message',
45 fromName: 'Super toto'
48 await waitJobs(server)
50 expect(emails).to.have.lengthOf(1)
52 const email = emails[0]
54 expect(email['from'][0]['address']).equal('test-admin@localhost')
55 expect(email['from'][0]['name']).equal('toto@example.com')
56 expect(email['to'][0]['address']).equal('admin1@example.com')
57 expect(email['subject']).contains('Contact form')
58 expect(email['text']).contains('my super message')
61 it('Should not be able to send another contact form because of the anti spam checker', async function () {
62 await sendContactForm({
64 fromEmail: 'toto@example.com',
65 body: 'my super message',
66 fromName: 'Super toto'
69 await sendContactForm({
71 fromEmail: 'toto@example.com',
72 body: 'my super message',
73 fromName: 'Super toto',
78 it('Should be able to send another contact form after a while', async function () {
81 await sendContactForm({
83 fromEmail: 'toto@example.com',
84 body: 'my super message',
85 fromName: 'Super toto'
89 after(async function () {
90 MockSmtpServer.Instance.kill()
92 await cleanupTests([ server ])