]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/contact-form.ts
Fix from header in contact form
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/utils'
6 import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
7 import { waitJobs } from '../../../../shared/utils/server/jobs'
8 import { sendContactForm } from '../../../../shared/utils/server/contact-form'
9
10 const expect = chai.expect
11
12 describe('Test contact form', function () {
13 let server: ServerInfo
14 const emails: object[] = []
15
16 before(async function () {
17 this.timeout(30000)
18
19 await MockSmtpServer.Instance.collectEmails(emails)
20
21 await flushTests()
22
23 const overrideConfig = {
24 smtp: {
25 hostname: 'localhost'
26 }
27 }
28 server = await runServer(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 fromName: 'Super toto'
40 })
41
42 await waitJobs(server)
43
44 expect(emails).to.have.lengthOf(1)
45
46 const email = emails[0]
47
48 expect(email['from'][0]['address']).equal('test-admin@localhost')
49 expect(email['from'][0]['name']).equal('toto@example.com')
50 expect(email['to'][0]['address']).equal('admin1@example.com')
51 expect(email['subject']).contains('Contact form')
52 expect(email['text']).contains('my super message')
53 })
54
55 it('Should not be able to send another contact form because of the anti spam checker', async function () {
56 await sendContactForm({
57 url: server.url,
58 fromEmail: 'toto@example.com',
59 body: 'my super message',
60 fromName: 'Super toto'
61 })
62
63 await sendContactForm({
64 url: server.url,
65 fromEmail: 'toto@example.com',
66 body: 'my super message',
67 fromName: 'Super toto',
68 expectedStatus: 403
69 })
70 })
71
72 it('Should be able to send another contact form after a while', async function () {
73 await wait(1000)
74
75 await sendContactForm({
76 url: server.url,
77 fromEmail: 'toto@example.com',
78 body: 'my super message',
79 fromName: 'Super toto'
80 })
81 })
82
83 after(async function () {
84 MockSmtpServer.Instance.kill()
85 killallServers([ server ])
86 })
87 })