From a4101923e699e49ceb9ff36e971c75417fafc9f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 Jan 2019 15:14:29 +0100 Subject: Implement contact form on server side --- shared/utils/miscs/email.ts | 4 ++++ shared/utils/server/config.ts | 3 +++ shared/utils/server/contact-form.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 shared/utils/server/contact-form.ts (limited to 'shared/utils') diff --git a/shared/utils/miscs/email.ts b/shared/utils/miscs/email.ts index 6fac7621f..f9f1bd95b 100644 --- a/shared/utils/miscs/email.ts +++ b/shared/utils/miscs/email.ts @@ -15,6 +15,8 @@ class MockSmtpServer { return this.emails.push(msg.email) } }) + + process.on('exit', () => this.kill()) } collectEmails (emailsCollection: object[]) { @@ -42,6 +44,8 @@ class MockSmtpServer { } kill () { + if (!this.emailChildProcess) return + process.kill(this.emailChildProcess.pid) this.emailChildProcess = null diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts index ff5288c82..0c5512bab 100644 --- a/shared/utils/server/config.ts +++ b/shared/utils/server/config.ts @@ -80,6 +80,9 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { admin: { email: 'superadmin1@example.com' }, + contactForm: { + enabled: true + }, user: { videoQuota: 5242881, videoQuotaDaily: 318742 diff --git a/shared/utils/server/contact-form.ts b/shared/utils/server/contact-form.ts new file mode 100644 index 000000000..80394cf99 --- /dev/null +++ b/shared/utils/server/contact-form.ts @@ -0,0 +1,28 @@ +import * as request from 'supertest' +import { ContactForm } from '../../models/server' + +function sendContactForm (options: { + url: string, + fromEmail: string, + fromName: string, + body: string, + expectedStatus?: number +}) { + const path = '/api/v1/server/contact' + + const body: ContactForm = { + fromEmail: options.fromEmail, + fromName: options.fromName, + body: options.body + } + return request(options.url) + .post(path) + .send(body) + .expect(options.expectedStatus || 204) +} + +// --------------------------------------------------------------------------- + +export { + sendContactForm +} -- cgit v1.2.3