1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { MockSmtpServer } from '@server/tests/shared'
6 import { wait } from '@shared/core-utils'
7 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers,
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test contact form', function () {
20 let server: PeerTubeServer
21 const emails: object[] = []
22 let command: ContactFormCommand
24 before(async function () {
27 const port = await MockSmtpServer.Instance.collectEmails(emails)
29 const overrideConfig = {
31 hostname: 'localhost',
35 server = await createSingleServer(1, overrideConfig)
36 await setAccessTokensToServers([ server ])
38 command = server.contactForm
41 it('Should send a contact form', async function () {
45 fromEmail: 'toto@example.com',
46 body: 'my super message',
47 subject: 'my subject',
48 fromName: 'Super toto'
51 await waitJobs(server)
53 expect(emails).to.have.lengthOf(1)
55 const email = emails[0]
57 expect(email['from'][0]['address']).equal('test-admin@localhost')
58 expect(email['replyTo'][0]['address']).equal('toto@example.com')
59 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
60 expect(email['subject']).contains('my subject')
61 expect(email['text']).contains('my super message')
64 it('Should not be able to send another contact form because of the anti spam checker', async function () {
70 fromEmail: 'toto@example.com',
71 body: 'my super message',
72 subject: 'my subject',
73 fromName: 'Super toto'
77 fromEmail: 'toto@example.com',
78 body: 'my super message',
79 fromName: 'Super toto',
80 subject: 'my subject',
81 expectedStatus: HttpStatusCode.FORBIDDEN_403
85 it('Should be able to send another contact form after a while', async function () {
89 fromEmail: 'toto@example.com',
90 fromName: 'Super toto',
91 subject: 'my subject',
92 body: 'my super message'
96 it('Should not have the manage preferences link in the email', async function () {
97 const email = emails[0]
98 expect(email['text']).to.not.contain('Manage your notification preferences')
101 after(async function () {
102 MockSmtpServer.Instance.kill()
104 await cleanupTests([ server ])