1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { MockSmtpServer } from '@server/tests/shared'
5 import { wait } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
16 const expect = chai.expect
18 describe('Test contact form', function () {
19 let server: PeerTubeServer
20 const emails: object[] = []
21 let command: ContactFormCommand
23 before(async function () {
26 const port = await MockSmtpServer.Instance.collectEmails(emails)
28 const overrideConfig = {
30 hostname: 'localhost',
34 server = await createSingleServer(1, overrideConfig)
35 await setAccessTokensToServers([ server ])
37 command = server.contactForm
40 it('Should send a contact form', async function () {
44 fromEmail: 'toto@example.com',
45 body: 'my super message',
46 subject: 'my subject',
47 fromName: 'Super toto'
50 await waitJobs(server)
52 expect(emails).to.have.lengthOf(1)
54 const email = emails[0]
56 expect(email['from'][0]['address']).equal('test-admin@localhost')
57 expect(email['replyTo'][0]['address']).equal('toto@example.com')
58 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
59 expect(email['subject']).contains('my subject')
60 expect(email['text']).contains('my super message')
63 it('Should not have duplicated email address in text message', async function () {
64 const text = emails[0]['text'] as string
66 const matches = text.match(/toto@example.com/g)
67 expect(matches).to.have.lengthOf(1)
70 it('Should not be able to send another contact form because of the anti spam checker', async function () {
76 fromEmail: 'toto@example.com',
77 body: 'my super message',
78 subject: 'my subject',
79 fromName: 'Super toto'
83 fromEmail: 'toto@example.com',
84 body: 'my super message',
85 fromName: 'Super toto',
86 subject: 'my subject',
87 expectedStatus: HttpStatusCode.FORBIDDEN_403
91 it('Should be able to send another contact form after a while', async function () {
95 fromEmail: 'toto@example.com',
96 fromName: 'Super toto',
97 subject: 'my subject',
98 body: 'my super message'
102 it('Should not have the manage preferences link in the email', async function () {
103 const email = emails[0]
104 expect(email['text']).to.not.contain('Manage your notification preferences')
107 after(async function () {
108 MockSmtpServer.Instance.kill()
110 await cleanupTests([ server ])