Add hls support on server
[oweals/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('toto@example.com')
49     expect(email['to'][0]['address']).equal('admin1@example.com')
50     expect(email['subject']).contains('Contact form')
51     expect(email['text']).contains('my super message')
52   })
53
54   it('Should not be able to send another contact form because of the anti spam checker', async function () {
55     await sendContactForm({
56       url: server.url,
57       fromEmail: 'toto@example.com',
58       body: 'my super message',
59       fromName: 'Super toto'
60     })
61
62     await sendContactForm({
63       url: server.url,
64       fromEmail: 'toto@example.com',
65       body: 'my super message',
66       fromName: 'Super toto',
67       expectedStatus: 403
68     })
69   })
70
71   it('Should be able to send another contact form after a while', async function () {
72     await wait(1000)
73
74     await sendContactForm({
75       url: server.url,
76       fromEmail: 'toto@example.com',
77       body: 'my super message',
78       fromName: 'Super toto'
79     })
80   })
81
82   after(async function () {
83     MockSmtpServer.Instance.kill()
84     killallServers([ server ])
85   })
86 })