]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/server/contact-form.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import * as chai from 'chai'
4import 'mocha'
5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils'
6import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
7import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
8import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
9
10const expect = chai.expect
11
12describe('Test contact form', function () {
13 let server: ServerInfo
14 const emails: object[] = []
15
16 before(async function () {
17 this.timeout(30000)
18
19 const port = await MockSmtpServer.Instance.collectEmails(emails)
20
21 const overrideConfig = {
22 smtp: {
23 hostname: 'localhost',
24 port
25 }
26 }
27 server = await flushAndRunServer(1, overrideConfig)
28 await setAccessTokensToServers([ server ])
29 })
30
31 it('Should send a contact form', async function () {
32 this.timeout(10000)
33
34 await sendContactForm({
35 url: server.url,
36 fromEmail: 'toto@example.com',
37 body: 'my super message',
38 subject: 'my subject',
39 fromName: 'Super toto'
40 })
41
42 await waitJobs(server)
43
44 expect(emails).to.have.lengthOf(1)
45
46 const email = emails[0]
47
48 expect(email['from'][0]['address']).equal('test-admin@localhost')
49 expect(email['from'][0]['name']).equal('toto@example.com')
50 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
51 expect(email['subject']).contains('my subject')
52 expect(email['text']).contains('my super message')
53 })
54
55 it('Should not be able to send another contact form because of the anti spam checker', async function () {
56 await sendContactForm({
57 url: server.url,
58 fromEmail: 'toto@example.com',
59 body: 'my super message',
60 subject: 'my subject',
61 fromName: 'Super toto'
62 })
63
64 await sendContactForm({
65 url: server.url,
66 fromEmail: 'toto@example.com',
67 body: 'my super message',
68 fromName: 'Super toto',
69 subject: 'my subject',
70 expectedStatus: 403
71 })
72 })
73
74 it('Should be able to send another contact form after a while', async function () {
75 await wait(1000)
76
77 await sendContactForm({
78 url: server.url,
79 fromEmail: 'toto@example.com',
80 fromName: 'Super toto',
81 subject: 'my subject',
82 body: 'my super message'
83 })
84 })
85
86 after(async function () {
87 MockSmtpServer.Instance.kill()
88
89 await cleanupTests([ server ])
90 })
91})