aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-06 15:53:25 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commita9c58393d36d221197b48884a1960e6126ab31d7 (patch)
treeb504eeefd6449d26122a7ee69affa24d242c70da /shared
parent2d1ad5b96063d1e430ca99128a15e2e56cb614e0 (diff)
downloadPeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.tar.gz
PeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.tar.zst
PeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.zip
Introduce contact form command
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/server/contact-form-command.ts31
-rw-r--r--shared/extra-utils/server/contact-form.ts31
-rw-r--r--shared/extra-utils/server/index.ts1
-rw-r--r--shared/extra-utils/server/servers.ts3
4 files changed, 35 insertions, 31 deletions
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 @@
1import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
2import { ContactForm } from '../../models/server'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5export class ContactFormCommand extends AbstractCommand {
6
7 send (options: OverrideCommandOptions & {
8 fromEmail: string
9 fromName: string
10 subject: string
11 body: string
12 }) {
13 const path = '/api/v1/server/contact'
14
15 const body: ContactForm = {
16 fromEmail: options.fromEmail,
17 fromName: options.fromName,
18 subject: options.subject,
19 body: options.body
20 }
21
22 return this.postBodyRequest({
23 ...options,
24
25 path,
26 token: null,
27 fields: body,
28 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
29 })
30 }
31}
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 @@
1import * as request from 'supertest'
2import { ContactForm } from '../../models/server'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4
5function sendContactForm (options: {
6 url: string
7 fromEmail: string
8 fromName: string
9 subject: string
10 body: string
11 expectedStatus?: number
12}) {
13 const path = '/api/v1/server/contact'
14
15 const body: ContactForm = {
16 fromEmail: options.fromEmail,
17 fromName: options.fromName,
18 subject: options.subject,
19 body: options.body
20 }
21 return request(options.url)
22 .post(path)
23 .send(body)
24 .expect(options.expectedStatus || HttpStatusCode.NO_CONTENT_204)
25}
26
27// ---------------------------------------------------------------------------
28
29export {
30 sendContactForm
31}
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'
16import { OverviewsCommand } from '../overviews' 16import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { ContactFormCommand } from './contact-form-command'
19 20
20interface ServerInfo { 21interface ServerInfo {
21 app: ChildProcess 22 app: ChildProcess
@@ -77,6 +78,7 @@ interface ServerInfo {
77 abusesCommand?: AbusesCommand 78 abusesCommand?: AbusesCommand
78 overviewsCommand?: OverviewsCommand 79 overviewsCommand?: OverviewsCommand
79 searchCommand?: SearchCommand 80 searchCommand?: SearchCommand
81 contactFormCommand?: ContactFormCommand
80} 82}
81 83
82function parallelTests () { 84function parallelTests () {
@@ -290,6 +292,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
290 server.abusesCommand = new AbusesCommand(server) 292 server.abusesCommand = new AbusesCommand(server)
291 server.overviewsCommand = new OverviewsCommand(server) 293 server.overviewsCommand = new OverviewsCommand(server)
292 server.searchCommand = new SearchCommand(server) 294 server.searchCommand = new SearchCommand(server)
295 server.contactFormCommand = new ContactFormCommand(server)
293 296
294 res(server) 297 res(server)
295 }) 298 })