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