2019-01-09 09:14:29 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
|
|
|
flushTests,
|
|
|
|
immutableAssign,
|
|
|
|
killallServers,
|
|
|
|
reRunServer,
|
2019-04-24 04:53:40 -04:00
|
|
|
flushAndRunServer,
|
2019-01-09 09:14:29 -05:00
|
|
|
ServerInfo,
|
2019-04-24 09:10:37 -04:00
|
|
|
setAccessTokensToServers, cleanupTests
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils'
|
2019-01-09 09:14:29 -05:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
|
|
|
import { getAccount } from '../../../../shared/extra-utils/users/accounts'
|
|
|
|
import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
|
|
|
|
import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
|
2019-01-09 09:14:29 -05:00
|
|
|
|
|
|
|
describe('Test contact form API validators', function () {
|
|
|
|
let server: ServerInfo
|
|
|
|
const emails: object[] = []
|
|
|
|
const defaultBody = {
|
|
|
|
fromName: 'super name',
|
|
|
|
fromEmail: 'toto@example.com',
|
2019-06-21 02:49:35 -04:00
|
|
|
subject: 'my subject',
|
2019-01-09 09:14:29 -05:00
|
|
|
body: 'Hello, how are you?'
|
|
|
|
}
|
2019-04-24 09:10:37 -04:00
|
|
|
let emailPort: number
|
2019-01-09 09:14:29 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
emailPort = await MockSmtpServer.Instance.collectEmails(emails)
|
2019-01-09 09:14:29 -05:00
|
|
|
|
|
|
|
// Email is disabled
|
2019-04-24 04:53:40 -04:00
|
|
|
server = await flushAndRunServer(1)
|
2019-01-09 09:14:29 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not accept a contact form if emails are disabled', async function () {
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not accept a contact form if it is disabled in the configuration', async function () {
|
2019-01-15 05:14:12 -05:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2019-01-09 09:14:29 -05:00
|
|
|
killallServers([ server ])
|
|
|
|
|
|
|
|
// Contact form is disabled
|
2019-04-24 09:10:37 -04:00
|
|
|
await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
|
2019-01-09 09:14:29 -05:00
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not accept a contact form if from email is invalid', async function () {
|
2019-01-15 05:14:12 -05:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2019-01-09 09:14:29 -05:00
|
|
|
killallServers([ server ])
|
|
|
|
|
|
|
|
// Email & contact form enabled
|
2019-04-24 09:10:37 -04:00
|
|
|
await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
|
2019-01-09 09:14:29 -05:00
|
|
|
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not accept a contact form if from name is invalid', async function () {
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not accept a contact form if body is invalid', async function () {
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should accept a contact form with the correct parameters', async function () {
|
|
|
|
await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
2019-01-09 09:14:29 -05:00
|
|
|
MockSmtpServer.Instance.kill()
|
2019-04-24 09:10:37 -04:00
|
|
|
|
2019-04-24 11:19:00 -04:00
|
|
|
await cleanupTests([ server ])
|
2019-01-09 09:14:29 -05:00
|
|
|
})
|
|
|
|
})
|