]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/contact-form.ts
Use an object to represent a server
[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'
a9c58393 5import { HttpStatusCode } from '@shared/core-utils'
254d3579
C
6import {
7 cleanupTests,
8 ContactFormCommand,
9 createSingleServer,
10 MockSmtpServer,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 wait,
14 waitJobs
15} from '@shared/extra-utils'
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
64 it('Should not be able to send another contact form because of the anti spam checker', async function () {
3d470a53
C
65 this.timeout(10000)
66
67 await wait(1000)
68
a9c58393 69 await command.send({
a4101923
C
70 fromEmail: 'toto@example.com',
71 body: 'my super message',
4e9fa5b7 72 subject: 'my subject',
a4101923
C
73 fromName: 'Super toto'
74 })
75
a9c58393 76 await command.send({
a4101923
C
77 fromEmail: 'toto@example.com',
78 body: 'my super message',
79 fromName: 'Super toto',
4e9fa5b7 80 subject: 'my subject',
f2eb23cd 81 expectedStatus: HttpStatusCode.FORBIDDEN_403
a4101923
C
82 })
83 })
84
85 it('Should be able to send another contact form after a while', async function () {
86 await wait(1000)
87
a9c58393 88 await command.send({
a4101923 89 fromEmail: 'toto@example.com',
4e9fa5b7
NB
90 fromName: 'Super toto',
91 subject: 'my subject',
92 body: 'my super message'
a4101923
C
93 })
94 })
95
b9cf3fb6
C
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')
99 })
100
7c3b7976 101 after(async function () {
a4101923 102 MockSmtpServer.Instance.kill()
7c3b7976
C
103
104 await cleanupTests([ server ])
a4101923
C
105 })
106})