]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/contact-form.ts
Try to fix travis
[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
C
11 ServerInfo,
12 setAccessTokensToServers
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 }
31
32 // ---------------------------------------------------------------
33
34 before(async function () {
35 this.timeout(60000)
36
a4101923
C
37 await MockSmtpServer.Instance.collectEmails(emails)
38
39 // Email is disabled
210feb6c 40 server = await flushAndRunServer(1)
a4101923
C
41 })
42
43 it('Should not accept a contact form if emails are disabled', async function () {
44 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
45 })
46
47 it('Should not accept a contact form if it is disabled in the configuration', async function () {
848f499d
C
48 this.timeout(10000)
49
a4101923
C
50 killallServers([ server ])
51
52 // Contact form is disabled
53 await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } })
54 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
55 })
56
57 it('Should not accept a contact form if from email is invalid', async function () {
848f499d
C
58 this.timeout(10000)
59
a4101923
C
60 killallServers([ server ])
61
62 // Email & contact form enabled
63 await reRunServer(server, { smtp: { hostname: 'localhost' } })
64
65 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
66 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
68 })
69
70 it('Should not accept a contact form if from name is invalid', async function () {
71 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
72 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
73 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
74 })
75
76 it('Should not accept a contact form if body is invalid', async function () {
77 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
78 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
79 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
80 })
81
82 it('Should accept a contact form with the correct parameters', async function () {
83 await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
84 })
85
210feb6c 86 after(function () {
a4101923
C
87 MockSmtpServer.Instance.kill()
88 killallServers([ server ])
a4101923
C
89 })
90})