]>
Commit | Line | Data |
---|---|---|
a4101923 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
210feb6c | 5 | import { flushTests, killallServers, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' |
94565d52 C |
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' | |
a4101923 C |
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 | ||
a4101923 C |
21 | const overrideConfig = { |
22 | smtp: { | |
23 | hostname: 'localhost' | |
24 | } | |
25 | } | |
210feb6c | 26 | server = await flushAndRunServer(1, overrideConfig) |
a4101923 C |
27 | await setAccessTokensToServers([ server ]) |
28 | }) | |
29 | ||
30 | it('Should send a contact form', async function () { | |
26a008fe C |
31 | this.timeout(10000) |
32 | ||
a4101923 C |
33 | await sendContactForm({ |
34 | url: server.url, | |
35 | fromEmail: 'toto@example.com', | |
36 | body: 'my super message', | |
37 | fromName: 'Super toto' | |
38 | }) | |
39 | ||
40 | await waitJobs(server) | |
41 | ||
42 | expect(emails).to.have.lengthOf(1) | |
43 | ||
44 | const email = emails[0] | |
45 | ||
4759fedc C |
46 | expect(email['from'][0]['address']).equal('test-admin@localhost') |
47 | expect(email['from'][0]['name']).equal('toto@example.com') | |
a4101923 C |
48 | expect(email['to'][0]['address']).equal('admin1@example.com') |
49 | expect(email['subject']).contains('Contact form') | |
50 | expect(email['text']).contains('my super message') | |
51 | }) | |
52 | ||
53 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | |
54 | await sendContactForm({ | |
55 | url: server.url, | |
56 | fromEmail: 'toto@example.com', | |
57 | body: 'my super message', | |
58 | fromName: 'Super toto' | |
59 | }) | |
60 | ||
61 | await sendContactForm({ | |
62 | url: server.url, | |
63 | fromEmail: 'toto@example.com', | |
64 | body: 'my super message', | |
65 | fromName: 'Super toto', | |
66 | expectedStatus: 403 | |
67 | }) | |
68 | }) | |
69 | ||
70 | it('Should be able to send another contact form after a while', async function () { | |
71 | await wait(1000) | |
72 | ||
73 | await sendContactForm({ | |
74 | url: server.url, | |
75 | fromEmail: 'toto@example.com', | |
76 | body: 'my super message', | |
77 | fromName: 'Super toto' | |
78 | }) | |
79 | }) | |
80 | ||
210feb6c | 81 | after(function () { |
a4101923 C |
82 | MockSmtpServer.Instance.kill() |
83 | killallServers([ server ]) | |
84 | }) | |
85 | }) |