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 () {
37 fromEmail: 'toto@example.com',
38 body: 'my super message',
39 subject: 'my subject',
40 fromName: 'Super toto'
43 await waitJobs(server)
45 expect(emails).to.have.lengthOf(1)
47 const email = emails[0]
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')
56 it('Should not have duplicated email address in text message', async function () {
57 const text = emails[0]['text'] as string
59 const matches = text.match(/toto@example.com/g)
60 expect(matches).to.have.lengthOf(1)
63 it('Should not be able to send another contact form because of the anti spam checker', async function () {
69 fromEmail: 'toto@example.com',
70 body: 'my super message',
71 subject: 'my subject',
72 fromName: 'Super toto'
76 fromEmail: 'toto@example.com',
77 body: 'my super message',
78 fromName: 'Super toto',
79 subject: 'my subject',
80 expectedStatus: HttpStatusCode.FORBIDDEN_403
84 it('Should be able to send another contact form after a while', async function () {
88 fromEmail: 'toto@example.com',
89 fromName: 'Super toto',
90 subject: 'my subject',
91 body: 'my super message'
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')
100 after(async function () {
101 MockSmtpServer.Instance.kill()
103 await cleanupTests([ server ])