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