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