2019-01-09 14:14:29 +00:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import 'mocha'
|
2019-04-24 13:10:37 +00:00
|
|
|
import {
|
|
|
|
flushTests,
|
|
|
|
killallServers,
|
|
|
|
flushAndRunServer,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
wait,
|
|
|
|
cleanupTests
|
|
|
|
} from '../../../../shared/extra-utils'
|
2019-04-15 13:26:15 +00:00
|
|
|
import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
|
|
|
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
|
|
|
import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
|
2019-01-09 14:14:29 +00:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test contact form', function () {
|
|
|
|
let server: ServerInfo
|
|
|
|
const emails: object[] = []
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-25 15:14:49 +00:00
|
|
|
const port = await MockSmtpServer.Instance.collectEmails(emails)
|
2019-01-09 14:14:29 +00:00
|
|
|
|
|
|
|
const overrideConfig = {
|
|
|
|
smtp: {
|
2019-04-25 15:14:49 +00:00
|
|
|
hostname: 'localhost',
|
|
|
|
port
|
2019-01-09 14:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-24 08:53:40 +00:00
|
|
|
server = await flushAndRunServer(1, overrideConfig)
|
2019-01-09 14:14:29 +00:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a contact form', async function () {
|
2019-01-10 10:51:25 +00:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2019-01-09 14:14:29 +00:00
|
|
|
await sendContactForm({
|
|
|
|
url: server.url,
|
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitJobs(server)
|
|
|
|
|
|
|
|
expect(emails).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
const email = emails[0]
|
|
|
|
|
2019-02-14 10:56:23 +00:00
|
|
|
expect(email['from'][0]['address']).equal('test-admin@localhost')
|
|
|
|
expect(email['from'][0]['name']).equal('toto@example.com')
|
2019-04-26 06:50:52 +00:00
|
|
|
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
|
2019-01-09 14:14:29 +00:00
|
|
|
expect(email['subject']).contains('Contact form')
|
|
|
|
expect(email['text']).contains('my super message')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to send another contact form because of the anti spam checker', async function () {
|
|
|
|
await sendContactForm({
|
|
|
|
url: server.url,
|
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
|
|
|
|
await sendContactForm({
|
|
|
|
url: server.url,
|
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto',
|
|
|
|
expectedStatus: 403
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to send another contact form after a while', async function () {
|
|
|
|
await wait(1000)
|
|
|
|
|
|
|
|
await sendContactForm({
|
|
|
|
url: server.url,
|
|
|
|
fromEmail: 'toto@example.com',
|
|
|
|
body: 'my super message',
|
|
|
|
fromName: 'Super toto'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 13:10:37 +00:00
|
|
|
after(async function () {
|
2019-01-09 14:14:29 +00:00
|
|
|
MockSmtpServer.Instance.kill()
|
2019-04-24 13:10:37 +00:00
|
|
|
|
|
|
|
await cleanupTests([ server ])
|
2019-01-09 14:14:29 +00:00
|
|
|
})
|
|
|
|
})
|