1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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'
13 setAccessTokensToServers,
15 } from '@shared/server-commands'
17 describe('Test contact form', function () {
18 let server: PeerTubeServer
19 const emails: object[] = []
20 let command: ContactFormCommand
22 before(async function () {
25 const port = await MockSmtpServer.Instance.collectEmails(emails)
27 server = await createSingleServer(1, ConfigCommand.getEmailOverrideConfig(port))
28 await setAccessTokensToServers([ server ])
30 command = server.contactForm
33 it('Should send a contact form', async function () {
35 fromEmail: 'toto@example.com',
36 body: 'my super message',
37 subject: 'my subject',
38 fromName: 'Super toto'
41 await waitJobs(server)
43 expect(emails).to.have.lengthOf(1)
45 const email = emails[0]
47 expect(email['from'][0]['address']).equal('test-admin@127.0.0.1')
48 expect(email['replyTo'][0]['address']).equal('toto@example.com')
49 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
50 expect(email['subject']).contains('my subject')
51 expect(email['text']).contains('my super message')
54 it('Should not have duplicated email address in text message', async function () {
55 const text = emails[0]['text'] as string
57 const matches = text.match(/toto@example.com/g)
58 expect(matches).to.have.lengthOf(1)
61 it('Should not be able to send another contact form because of the anti spam checker', async function () {
65 fromEmail: 'toto@example.com',
66 body: 'my super message',
67 subject: 'my subject',
68 fromName: 'Super toto'
72 fromEmail: 'toto@example.com',
73 body: 'my super message',
74 fromName: 'Super toto',
75 subject: 'my subject',
76 expectedStatus: HttpStatusCode.FORBIDDEN_403
80 it('Should be able to send another contact form after a while', async function () {
84 fromEmail: 'toto@example.com',
85 fromName: 'Super toto',
86 subject: 'my subject',
87 body: 'my super message'
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')
96 after(async function () {
97 MockSmtpServer.Instance.kill()
99 await cleanupTests([ server ])