]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/contact-form.ts
Bumped to version v5.2.1
[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 () {
a9c58393 34 await command.send({
a4101923
C
35 fromEmail: 'toto@example.com',
36 body: 'my super message',
4e9fa5b7 37 subject: 'my subject',
a4101923
C
38 fromName: 'Super toto'
39 })
40
41 await waitJobs(server)
42
43 expect(emails).to.have.lengthOf(1)
44
45 const email = emails[0]
46
2732eeff 47 expect(email['from'][0]['address']).equal('test-admin@127.0.0.1')
df4c603d 48 expect(email['replyTo'][0]['address']).equal('toto@example.com')
48f07b4a 49 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
4e9fa5b7 50 expect(email['subject']).contains('my subject')
a4101923
C
51 expect(email['text']).contains('my super message')
52 })
53
7a4fd56c 54 it('Should not have duplicated email address in text message', async function () {
3c7ddd7d
C
55 const text = emails[0]['text'] as string
56
57 const matches = text.match(/toto@example.com/g)
58 expect(matches).to.have.lengthOf(1)
59 })
60
a4101923 61 it('Should not be able to send another contact form because of the anti spam checker', async function () {
3d470a53
C
62 await wait(1000)
63
a9c58393 64 await command.send({
a4101923
C
65 fromEmail: 'toto@example.com',
66 body: 'my super message',
4e9fa5b7 67 subject: 'my subject',
a4101923
C
68 fromName: 'Super toto'
69 })
70
a9c58393 71 await command.send({
a4101923
C
72 fromEmail: 'toto@example.com',
73 body: 'my super message',
74 fromName: 'Super toto',
4e9fa5b7 75 subject: 'my subject',
f2eb23cd 76 expectedStatus: HttpStatusCode.FORBIDDEN_403
a4101923
C
77 })
78 })
79
80 it('Should be able to send another contact form after a while', async function () {
81 await wait(1000)
82
a9c58393 83 await command.send({
a4101923 84 fromEmail: 'toto@example.com',
4e9fa5b7
NB
85 fromName: 'Super toto',
86 subject: 'my subject',
87 body: 'my super message'
a4101923
C
88 })
89 })
90
b9cf3fb6
C
91 it('Should not have the manage preferences link in the email', async function () {
92 const email = emails[0]
93 expect(email['text']).to.not.contain('Manage your notification preferences')
94 })
95
7c3b7976 96 after(async function () {
a4101923 97 MockSmtpServer.Instance.kill()
7c3b7976
C
98
99 await cleanupTests([ server ])
a4101923
C
100 })
101})