]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/contact-form.ts
More robust actor image lazy load
[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
C
2
3import * as chai from 'chai'
4import 'mocha'
a1587156 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils'
94565d52
C
6import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
7import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
8import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
f2eb23cd 9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
a4101923
C
10
11const expect = chai.expect
12
13describe('Test contact form', function () {
14 let server: ServerInfo
15 const emails: object[] = []
16
17 before(async function () {
18 this.timeout(30000)
19
7243f84d 20 const port = await MockSmtpServer.Instance.collectEmails(emails)
a4101923 21
a4101923
C
22 const overrideConfig = {
23 smtp: {
7243f84d
C
24 hostname: 'localhost',
25 port
a4101923
C
26 }
27 }
210feb6c 28 server = await flushAndRunServer(1, overrideConfig)
a4101923
C
29 await setAccessTokensToServers([ server ])
30 })
31
32 it('Should send a contact form', async function () {
26a008fe
C
33 this.timeout(10000)
34
a4101923
C
35 await sendContactForm({
36 url: server.url,
37 fromEmail: 'toto@example.com',
38 body: 'my super message',
4e9fa5b7 39 subject: 'my subject',
a4101923
C
40 fromName: 'Super toto'
41 })
42
43 await waitJobs(server)
44
45 expect(emails).to.have.lengthOf(1)
46
47 const email = emails[0]
48
4759fedc 49 expect(email['from'][0]['address']).equal('test-admin@localhost')
df4c603d 50 expect(email['replyTo'][0]['address']).equal('toto@example.com')
48f07b4a 51 expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
4e9fa5b7 52 expect(email['subject']).contains('my subject')
a4101923
C
53 expect(email['text']).contains('my super message')
54 })
55
56 it('Should not be able to send another contact form because of the anti spam checker', async function () {
57 await sendContactForm({
58 url: server.url,
59 fromEmail: 'toto@example.com',
60 body: 'my super message',
4e9fa5b7 61 subject: 'my subject',
a4101923
C
62 fromName: 'Super toto'
63 })
64
65 await sendContactForm({
66 url: server.url,
67 fromEmail: 'toto@example.com',
68 body: 'my super message',
69 fromName: 'Super toto',
4e9fa5b7 70 subject: 'my subject',
f2eb23cd 71 expectedStatus: HttpStatusCode.FORBIDDEN_403
a4101923
C
72 })
73 })
74
75 it('Should be able to send another contact form after a while', async function () {
76 await wait(1000)
77
78 await sendContactForm({
79 url: server.url,
80 fromEmail: 'toto@example.com',
4e9fa5b7
NB
81 fromName: 'Super toto',
82 subject: 'my subject',
83 body: 'my super message'
a4101923
C
84 })
85 })
86
b9cf3fb6
C
87 it('Should not have the manage preferences link in the email', async function () {
88 const email = emails[0]
89 expect(email['text']).to.not.contain('Manage your notification preferences')
90 })
91
7c3b7976 92 after(async function () {
a4101923 93 MockSmtpServer.Instance.kill()
7c3b7976
C
94
95 await cleanupTests([ server ])
a4101923
C
96 })
97})