]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/contact-form.ts
More robust actor image lazy load
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils'
6 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
7 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
8 import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
9 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10
11 const expect = chai.expect
12
13 describe('Test contact form', function () {
14 let server: ServerInfo
15 const emails: object[] = []
16
17 before(async function () {
18 this.timeout(30000)
19
20 const port = await MockSmtpServer.Instance.collectEmails(emails)
21
22 const overrideConfig = {
23 smtp: {
24 hostname: 'localhost',
25 port
26 }
27 }
28 server = await flushAndRunServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ])
30 })
31
32 it('Should send a contact form', async function () {
33 this.timeout(10000)
34
35 await sendContactForm({
36 url: server.url,
37 fromEmail: 'toto@example.com',
38 body: 'my super message',
39 subject: 'my subject',
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
49 expect(email['from'][0]['address']).equal('test-admin@localhost')
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')
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',
61 subject: 'my subject',
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',
70 subject: 'my subject',
71 expectedStatus: HttpStatusCode.FORBIDDEN_403
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',
81 fromName: 'Super toto',
82 subject: 'my subject',
83 body: 'my super message'
84 })
85 })
86
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
92 after(async function () {
93 MockSmtpServer.Instance.kill()
94
95 await cleanupTests([ server ])
96 })
97 })