]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/contact-form.ts
Fix video channel API route param in doc
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / contact-form.ts
CommitLineData
a4101923
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 flushTests,
7 immutableAssign,
8 killallServers,
9 reRunServer,
210feb6c 10 flushAndRunServer,
a4101923 11 ServerInfo,
7c3b7976 12 setAccessTokensToServers, cleanupTests
94565d52 13} from '../../../../shared/extra-utils'
a4101923
C
14import {
15 checkBadCountPagination,
16 checkBadSortPagination,
17 checkBadStartPagination
94565d52
C
18} from '../../../../shared/extra-utils/requests/check-api-params'
19import { getAccount } from '../../../../shared/extra-utils/users/accounts'
20import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
21import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
a4101923
C
22
23describe('Test contact form API validators', function () {
24 let server: ServerInfo
25 const emails: object[] = []
26 const defaultBody = {
27 fromName: 'super name',
28 fromEmail: 'toto@example.com',
29 body: 'Hello, how are you?'
30 }
7c3b7976 31 let emailPort: number
a4101923
C
32
33 // ---------------------------------------------------------------
34
35 before(async function () {
36 this.timeout(60000)
37
7c3b7976 38 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
a4101923
C
39
40 // Email is disabled
210feb6c 41 server = await flushAndRunServer(1)
a4101923
C
42 })
43
44 it('Should not accept a contact form if emails are disabled', async function () {
45 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
46 })
47
48 it('Should not accept a contact form if it is disabled in the configuration', async function () {
848f499d
C
49 this.timeout(10000)
50
a4101923
C
51 killallServers([ server ])
52
53 // Contact form is disabled
7c3b7976 54 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
a4101923
C
55 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
56 })
57
58 it('Should not accept a contact form if from email is invalid', async function () {
848f499d
C
59 this.timeout(10000)
60
a4101923
C
61 killallServers([ server ])
62
63 // Email & contact form enabled
7c3b7976 64 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
a4101923
C
65
66 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
68 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
69 })
70
71 it('Should not accept a contact form if from name is invalid', async function () {
72 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
73 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
74 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
75 })
76
77 it('Should not accept a contact form if body is invalid', async function () {
78 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
79 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
80 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
81 })
82
83 it('Should accept a contact form with the correct parameters', async function () {
84 await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
85 })
86
7c3b7976 87 after(async function () {
a4101923 88 MockSmtpServer.Instance.kill()
7c3b7976
C
89
90 // await cleanupTests([ server ])
a4101923
C
91 })
92})