aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
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 /server/tests/api
parent2d1ad5b96063d1e430ca99128a15e2e56cb614e0 (diff)
downloadPeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.tar.gz
PeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.tar.zst
PeerTube-a9c58393d36d221197b48884a1960e6126ab31d7.zip
Introduce contact form command
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/contact-form.ts69
-rw-r--r--server/tests/api/server/contact-form.ts23
2 files changed, 27 insertions, 65 deletions
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index 274562cbb..fb30766d9 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '@shared/core-utils'
5import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' 5import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils'
6import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 6import { ContactFormCommand } from '@shared/extra-utils/server'
7import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
8 7
9describe('Test contact form API validators', function () { 8describe('Test contact form API validators', function () {
10 let server: ServerInfo 9 let server: ServerInfo
@@ -16,6 +15,7 @@ describe('Test contact form API validators', function () {
16 body: 'Hello, how are you?' 15 body: 'Hello, how are you?'
17 } 16 }
18 let emailPort: number 17 let emailPort: number
18 let command: ContactFormCommand
19 19
20 // --------------------------------------------------------------- 20 // ---------------------------------------------------------------
21 21
@@ -26,10 +26,11 @@ describe('Test contact form API validators', function () {
26 26
27 // Email is disabled 27 // Email is disabled
28 server = await flushAndRunServer(1) 28 server = await flushAndRunServer(1)
29 command = server.contactFormCommand
29 }) 30 })
30 31
31 it('Should not accept a contact form if emails are disabled', async function () { 32 it('Should not accept a contact form if emails are disabled', async function () {
32 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 33 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
33 }) 34 })
34 35
35 it('Should not accept a contact form if it is disabled in the configuration', async function () { 36 it('Should not accept a contact form if it is disabled in the configuration', async function () {
@@ -39,7 +40,7 @@ describe('Test contact form API validators', function () {
39 40
40 // Contact form is disabled 41 // Contact form is disabled
41 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) 42 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
42 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 43 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
43 }) 44 })
44 45
45 it('Should not accept a contact form if from email is invalid', async function () { 46 it('Should not accept a contact form if from email is invalid', async function () {
@@ -50,61 +51,25 @@ describe('Test contact form API validators', function () {
50 // Email & contact form enabled 51 // Email & contact form enabled
51 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) 52 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
52 53
53 await sendContactForm(immutableAssign(defaultBody, { 54 await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
54 url: server.url, 55 await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
55 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 56 await command.send({ ...defaultBody, fromEmail: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
56 fromEmail: 'badEmail'
57 }))
58 await sendContactForm(immutableAssign(defaultBody, {
59 url: server.url,
60 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
61 fromEmail: 'badEmail@'
62 }))
63 await sendContactForm(immutableAssign(defaultBody, {
64 url: server.url,
65 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
66 fromEmail: undefined
67 }))
68 }) 57 })
69 58
70 it('Should not accept a contact form if from name is invalid', async function () { 59 it('Should not accept a contact form if from name is invalid', async function () {
71 await sendContactForm(immutableAssign(defaultBody, { 60 await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
72 url: server.url, 61 await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
73 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 62 await command.send({ ...defaultBody, fromName: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
74 fromName: 'name'.repeat(100)
75 }))
76 await sendContactForm(immutableAssign(defaultBody, {
77 url: server.url,
78 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
79 fromName: ''
80 }))
81 await sendContactForm(immutableAssign(defaultBody, {
82 url: server.url,
83 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
84 fromName: undefined
85 }))
86 }) 63 })
87 64
88 it('Should not accept a contact form if body is invalid', async function () { 65 it('Should not accept a contact form if body is invalid', async function () {
89 await sendContactForm(immutableAssign(defaultBody, { 66 await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
90 url: server.url, 67 await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
91 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 68 await command.send({ ...defaultBody, body: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
92 body: 'body'.repeat(5000)
93 }))
94 await sendContactForm(immutableAssign(defaultBody, {
95 url: server.url,
96 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
97 body: 'a'
98 }))
99 await sendContactForm(immutableAssign(defaultBody, {
100 url: server.url,
101 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
102 body: undefined
103 }))
104 }) 69 })
105 70
106 it('Should accept a contact form with the correct parameters', async function () { 71 it('Should accept a contact form with the correct parameters', async function () {
107 await sendContactForm(immutableAssign(defaultBody, { url: server.url })) 72 await command.send({ ...defaultBody })
108 }) 73 })
109 74
110 after(async function () { 75 after(async function () {
diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts
index 71205723d..79c4c6748 100644
--- a/server/tests/api/server/contact-form.ts
+++ b/server/tests/api/server/contact-form.ts
@@ -2,17 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '@shared/core-utils'
6import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' 6import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils'
7import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 7import { ContactFormCommand } from '@shared/extra-utils/server'
8import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
9import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
10 8
11const expect = chai.expect 9const expect = chai.expect
12 10
13describe('Test contact form', function () { 11describe('Test contact form', function () {
14 let server: ServerInfo 12 let server: ServerInfo
15 const emails: object[] = [] 13 const emails: object[] = []
14 let command: ContactFormCommand
16 15
17 before(async function () { 16 before(async function () {
18 this.timeout(30000) 17 this.timeout(30000)
@@ -27,13 +26,14 @@ describe('Test contact form', function () {
27 } 26 }
28 server = await flushAndRunServer(1, overrideConfig) 27 server = await flushAndRunServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
29
30 command = server.contactFormCommand
30 }) 31 })
31 32
32 it('Should send a contact form', async function () { 33 it('Should send a contact form', async function () {
33 this.timeout(10000) 34 this.timeout(10000)
34 35
35 await sendContactForm({ 36 await command.send({
36 url: server.url,
37 fromEmail: 'toto@example.com', 37 fromEmail: 'toto@example.com',
38 body: 'my super message', 38 body: 'my super message',
39 subject: 'my subject', 39 subject: 'my subject',
@@ -58,16 +58,14 @@ describe('Test contact form', function () {
58 58
59 await wait(1000) 59 await wait(1000)
60 60
61 await sendContactForm({ 61 await command.send({
62 url: server.url,
63 fromEmail: 'toto@example.com', 62 fromEmail: 'toto@example.com',
64 body: 'my super message', 63 body: 'my super message',
65 subject: 'my subject', 64 subject: 'my subject',
66 fromName: 'Super toto' 65 fromName: 'Super toto'
67 }) 66 })
68 67
69 await sendContactForm({ 68 await command.send({
70 url: server.url,
71 fromEmail: 'toto@example.com', 69 fromEmail: 'toto@example.com',
72 body: 'my super message', 70 body: 'my super message',
73 fromName: 'Super toto', 71 fromName: 'Super toto',
@@ -79,8 +77,7 @@ describe('Test contact form', function () {
79 it('Should be able to send another contact form after a while', async function () { 77 it('Should be able to send another contact form after a while', async function () {
80 await wait(1000) 78 await wait(1000)
81 79
82 await sendContactForm({ 80 await command.send({
83 url: server.url,
84 fromEmail: 'toto@example.com', 81 fromEmail: 'toto@example.com',
85 fromName: 'Super toto', 82 fromName: 'Super toto',
86 subject: 'my subject', 83 subject: 'my subject',