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'
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
16 describe('Test contact form', function () {
17 let server: PeerTubeServer
18 const emails: object[] = []
19 let command: ContactFormCommand
21 before(async function () {
24 const port = await MockSmtpServer.Instance.collectEmails(emails)
26 const overrideConfig = {
28 hostname: '127.0.0.1',
32 server = await createSingleServer(1, overrideConfig)
33 await setAccessTokensToServers([ server ])
35 command = server.contactForm
38 it('Should send a contact form', async function () {
42 fromEmail: 'toto@example.com',
43 body: 'my super message',
44 subject: 'my subject',
45 fromName: 'Super toto'
48 await waitJobs(server)
50 expect(emails).to.have.lengthOf(1)
52 const email = emails[0]
54 expect(email['from'][0]['address']).equal('test-admin@127.0.0.1')
55 expect(email['replyTo'][0]['address']).equal('toto@example.com')
56 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
57 expect(email['subject']).contains('my subject')
58 expect(email['text']).contains('my super message')
61 it('Should not have duplicated email address in text message', async function () {
62 const text = emails[0]['text'] as string
64 const matches = text.match(/toto@example.com/g)
65 expect(matches).to.have.lengthOf(1)
68 it('Should not be able to send another contact form because of the anti spam checker', async function () {
74 fromEmail: 'toto@example.com',
75 body: 'my super message',
76 subject: 'my subject',
77 fromName: 'Super toto'
81 fromEmail: 'toto@example.com',
82 body: 'my super message',
83 fromName: 'Super toto',
84 subject: 'my subject',
85 expectedStatus: HttpStatusCode.FORBIDDEN_403
89 it('Should be able to send another contact form after a while', async function () {
93 fromEmail: 'toto@example.com',
94 fromName: 'Super toto',
95 subject: 'my subject',
96 body: 'my super message'
100 it('Should not have the manage preferences link in the email', async function () {
101 const email = emails[0]
102 expect(email['text']).to.not.contain('Manage your notification preferences')
105 after(async function () {
106 MockSmtpServer.Instance.kill()
108 await cleanupTests([ server ])