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 subject: 'my subject',
47 fromName: 'Super toto'
50 await waitJobs(server)
52 expect(emails).to.have.lengthOf(1)
54 const email = emails[0]
56 expect(email['from'][0]['address']).equal('test-admin@localhost')
57 expect(email['from'][0]['name']).equal('toto@example.com')
58 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
59 expect(email['subject']).contains('my subject')
60 expect(email['text']).contains('my super message')
63 it('Should not be able to send another contact form because of the anti spam checker', async function () {
64 await sendContactForm({
66 fromEmail: 'toto@example.com',
67 body: 'my super message',
68 subject: 'my subject',
69 fromName: 'Super toto'
72 await sendContactForm({
74 fromEmail: 'toto@example.com',
75 body: 'my super message',
76 fromName: 'Super toto',
77 subject: 'my subject',
82 it('Should be able to send another contact form after a while', async function () {
85 await sendContactForm({
87 fromEmail: 'toto@example.com',
88 fromName: 'Super toto',
89 subject: 'my subject',
90 body: 'my super message'
94 after(async function () {
95 MockSmtpServer.Instance.kill()
97 await cleanupTests([ server ])