]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/contact-form.ts
Handle rejected follows in client
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
a4101923 2
a4101923 3import 'mocha'
8ef9457f 4import * as chai from 'chai'
c55e3d72
C
5import { MockSmtpServer } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
7import { HttpStatusCode } from '@shared/models'
254d3579
C
8import {
9 cleanupTests,
10 ContactFormCommand,
11 createSingleServer,
254d3579
C
12 PeerTubeServer,
13 setAccessTokensToServers,
254d3579 14 waitJobs
bf54587a 15} from '@shared/server-commands'
a4101923
C
16
17const expect = chai.expect
18
19describe('Test contact form', function () {
254d3579 20 let server: PeerTubeServer
a4101923 21 const emails: object[] = []
a9c58393 22 let command: ContactFormCommand
a4101923
C
23
24 before(async function () {
25 this.timeout(30000)
26
7243f84d 27 const port = await MockSmtpServer.Instance.collectEmails(emails)
a4101923 28
a4101923
C
29 const overrideConfig = {
30 smtp: {
7243f84d
C
31 hostname: 'localhost',
32 port
a4101923
C
33 }
34 }
254d3579 35 server = await createSingleServer(1, overrideConfig)
a4101923 36 await setAccessTokensToServers([ server ])
a9c58393 37
89d241a7 38 command = server.contactForm
a4101923
C
39 })
40
41 it('Should send a contact form', async function () {
26a008fe
C
42 this.timeout(10000)
43
a9c58393 44 await command.send({
a4101923
C
45 fromEmail: 'toto@example.com',
46 body: 'my super message',
4e9fa5b7 47 subject: 'my subject',
a4101923
C
48 fromName: 'Super toto'
49 })
50
51 await waitJobs(server)
52
53 expect(emails).to.have.lengthOf(1)
54
55 const email = emails[0]
56
4759fedc 57 expect(email['from'][0]['address']).equal('test-admin@localhost')
df4c603d 58 expect(email['replyTo'][0]['address']).equal('toto@example.com')
48f07b4a 59 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
4e9fa5b7 60 expect(email['subject']).contains('my subject')
a4101923
C
61 expect(email['text']).contains('my super message')
62 })
63
7a4fd56c 64 it('Should not have duplicated email address in text message', async function () {
3c7ddd7d
C
65 const text = emails[0]['text'] as string
66
67 const matches = text.match(/toto@example.com/g)
68 expect(matches).to.have.lengthOf(1)
69 })
70
a4101923 71 it('Should not be able to send another contact form because of the anti spam checker', async function () {
3d470a53
C
72 this.timeout(10000)
73
74 await wait(1000)
75
a9c58393 76 await command.send({
a4101923
C
77 fromEmail: 'toto@example.com',
78 body: 'my super message',
4e9fa5b7 79 subject: 'my subject',
a4101923
C
80 fromName: 'Super toto'
81 })
82
a9c58393 83 await command.send({
a4101923
C
84 fromEmail: 'toto@example.com',
85 body: 'my super message',
86 fromName: 'Super toto',
4e9fa5b7 87 subject: 'my subject',
f2eb23cd 88 expectedStatus: HttpStatusCode.FORBIDDEN_403
a4101923
C
89 })
90 })
91
92 it('Should be able to send another contact form after a while', async function () {
93 await wait(1000)
94
a9c58393 95 await command.send({
a4101923 96 fromEmail: 'toto@example.com',
4e9fa5b7
NB
97 fromName: 'Super toto',
98 subject: 'my subject',
99 body: 'my super message'
a4101923
C
100 })
101 })
102
b9cf3fb6
C
103 it('Should not have the manage preferences link in the email', async function () {
104 const email = emails[0]
105 expect(email['text']).to.not.contain('Manage your notification preferences')
106 })
107
7c3b7976 108 after(async function () {
a4101923 109 MockSmtpServer.Instance.kill()
7c3b7976
C
110
111 await cleanupTests([ server ])
a4101923
C
112 })
113})