]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/contact-form.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { MockSmtpServer } from '@server/tests/shared'
6 import { wait } from '@shared/core-utils'
7 import { HttpStatusCode } from '@shared/models'
8 import {
9 cleanupTests,
10 ContactFormCommand,
11 createSingleServer,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15 } from '@shared/server-commands'
16
17 const expect = chai.expect
18
19 describe('Test contact form', function () {
20 let server: PeerTubeServer
21 const emails: object[] = []
22 let command: ContactFormCommand
23
24 before(async function () {
25 this.timeout(30000)
26
27 const port = await MockSmtpServer.Instance.collectEmails(emails)
28
29 const overrideConfig = {
30 smtp: {
31 hostname: 'localhost',
32 port
33 }
34 }
35 server = await createSingleServer(1, overrideConfig)
36 await setAccessTokensToServers([ server ])
37
38 command = server.contactForm
39 })
40
41 it('Should send a contact form', async function () {
42 this.timeout(10000)
43
44 await command.send({
45 fromEmail: 'toto@example.com',
46 body: 'my super message',
47 subject: 'my subject',
48 fromName: 'Super toto'
49 })
50
51 await waitJobs(server)
52
53 expect(emails).to.have.lengthOf(1)
54
55 const email = emails[0]
56
57 expect(email['from'][0]['address']).equal('test-admin@localhost')
58 expect(email['replyTo'][0]['address']).equal('toto@example.com')
59 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
60 expect(email['subject']).contains('my subject')
61 expect(email['text']).contains('my super message')
62 })
63
64 it('Should not have duplicated email address in text message', async function () {
65 const text = emails[0]['text'] as string
66
67 const matches = text.match(/toto@example.com/g)
68 expect(matches).to.have.lengthOf(1)
69 })
70
71 it('Should not be able to send another contact form because of the anti spam checker', async function () {
72 this.timeout(10000)
73
74 await wait(1000)
75
76 await command.send({
77 fromEmail: 'toto@example.com',
78 body: 'my super message',
79 subject: 'my subject',
80 fromName: 'Super toto'
81 })
82
83 await command.send({
84 fromEmail: 'toto@example.com',
85 body: 'my super message',
86 fromName: 'Super toto',
87 subject: 'my subject',
88 expectedStatus: HttpStatusCode.FORBIDDEN_403
89 })
90 })
91
92 it('Should be able to send another contact form after a while', async function () {
93 await wait(1000)
94
95 await command.send({
96 fromEmail: 'toto@example.com',
97 fromName: 'Super toto',
98 subject: 'my subject',
99 body: 'my super message'
100 })
101 })
102
103 it('Should not have the manage preferences link in the email', async function () {
104 const email = emails[0]
105 expect(email['text']).to.not.contain('Manage your notification preferences')
106 })
107
108 after(async function () {
109 MockSmtpServer.Instance.kill()
110
111 await cleanupTests([ server ])
112 })
113 })