From a9c58393d36d221197b48884a1960e6126ab31d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:53:25 +0200 Subject: Introduce contact form command --- shared/extra-utils/server/contact-form-command.ts | 31 +++++++++++++++++++++++ shared/extra-utils/server/contact-form.ts | 31 ----------------------- shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/servers.ts | 3 +++ 4 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 shared/extra-utils/server/contact-form-command.ts delete mode 100644 shared/extra-utils/server/contact-form.ts create mode 100644 shared/extra-utils/server/index.ts (limited to 'shared') diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts new file mode 100644 index 000000000..943e5ccbb --- /dev/null +++ b/shared/extra-utils/server/contact-form-command.ts @@ -0,0 +1,31 @@ +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { ContactForm } from '../../models/server' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class ContactFormCommand extends AbstractCommand { + + send (options: OverrideCommandOptions & { + fromEmail: string + fromName: string + subject: string + body: string + }) { + const path = '/api/v1/server/contact' + + const body: ContactForm = { + fromEmail: options.fromEmail, + fromName: options.fromName, + subject: options.subject, + body: options.body + } + + return this.postBodyRequest({ + ...options, + + path, + token: null, + fields: body, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} diff --git a/shared/extra-utils/server/contact-form.ts b/shared/extra-utils/server/contact-form.ts deleted file mode 100644 index 6c9232cc6..000000000 --- a/shared/extra-utils/server/contact-form.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as request from 'supertest' -import { ContactForm } from '../../models/server' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function sendContactForm (options: { - url: string - fromEmail: string - fromName: string - subject: string - body: string - expectedStatus?: number -}) { - const path = '/api/v1/server/contact' - - const body: ContactForm = { - fromEmail: options.fromEmail, - fromName: options.fromName, - subject: options.subject, - body: options.body - } - return request(options.url) - .post(path) - .send(body) - .expect(options.expectedStatus || HttpStatusCode.NO_CONTENT_204) -} - -// --------------------------------------------------------------------------- - -export { - sendContactForm -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts new file mode 100644 index 000000000..4121c8828 --- /dev/null +++ b/shared/extra-utils/server/index.ts @@ -0,0 +1 @@ +export * from './contact-form-command' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 8ccf790fc..b58639ba6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' +import { ContactFormCommand } from './contact-form-command' interface ServerInfo { app: ChildProcess @@ -77,6 +78,7 @@ interface ServerInfo { abusesCommand?: AbusesCommand overviewsCommand?: OverviewsCommand searchCommand?: SearchCommand + contactFormCommand?: ContactFormCommand } function parallelTests () { @@ -290,6 +292,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.abusesCommand = new AbusesCommand(server) server.overviewsCommand = new OverviewsCommand(server) server.searchCommand = new SearchCommand(server) + server.contactFormCommand = new ContactFormCommand(server) res(server) }) -- cgit v1.2.3