]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/contact-form.ts
Merge branch 'release/5.0.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 { expect } from 'chai'
4 import { MockSmtpServer } from '@server/tests/shared'
5 import { wait } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
7 import {
8 cleanupTests,
9 ConfigCommand,
10 ContactFormCommand,
11 createSingleServer,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15 } from '@shared/server-commands'
16
17 describe('Test contact form', function () {
18 let server: PeerTubeServer
19 const emails: object[] = []
20 let command: ContactFormCommand
21
22 before(async function () {
23 this.timeout(30000)
24
25 const port = await MockSmtpServer.Instance.collectEmails(emails)
26
27 server = await createSingleServer(1, ConfigCommand.getEmailOverrideConfig(port))
28 await setAccessTokensToServers([ server ])
29
30 command = server.contactForm
31 })
32
33 it('Should send a contact form', async function () {
34 this.timeout(10000)
35
36 await command.send({
37 fromEmail: 'toto@example.com',
38 body: 'my super message',
39 subject: 'my subject',
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
49 expect(email['from'][0]['address']).equal('test-admin@127.0.0.1')
50 expect(email['replyTo'][0]['address']).equal('toto@example.com')
51 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
52 expect(email['subject']).contains('my subject')
53 expect(email['text']).contains('my super message')
54 })
55
56 it('Should not have duplicated email address in text message', async function () {
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
63 it('Should not be able to send another contact form because of the anti spam checker', async function () {
64 this.timeout(10000)
65
66 await wait(1000)
67
68 await command.send({
69 fromEmail: 'toto@example.com',
70 body: 'my super message',
71 subject: 'my subject',
72 fromName: 'Super toto'
73 })
74
75 await command.send({
76 fromEmail: 'toto@example.com',
77 body: 'my super message',
78 fromName: 'Super toto',
79 subject: 'my subject',
80 expectedStatus: HttpStatusCode.FORBIDDEN_403
81 })
82 })
83
84 it('Should be able to send another contact form after a while', async function () {
85 await wait(1000)
86
87 await command.send({
88 fromEmail: 'toto@example.com',
89 fromName: 'Super toto',
90 subject: 'my subject',
91 body: 'my super message'
92 })
93 })
94
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
100 after(async function () {
101 MockSmtpServer.Instance.kill()
102
103 await cleanupTests([ server ])
104 })
105 })