]>
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', | |
4e9fa5b7 | 46 | subject: 'my subject', |
a4101923 C |
47 | fromName: 'Super toto' |
48 | }) | |
49 | ||
50 | await waitJobs(server) | |
51 | ||
52 | expect(emails).to.have.lengthOf(1) | |
53 | ||
54 | const email = emails[0] | |
55 | ||
4759fedc C |
56 | expect(email['from'][0]['address']).equal('test-admin@localhost') |
57 | expect(email['from'][0]['name']).equal('toto@example.com') | |
48f07b4a | 58 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') |
4e9fa5b7 | 59 | expect(email['subject']).contains('my subject') |
a4101923 C |
60 | expect(email['text']).contains('my super message') |
61 | }) | |
62 | ||
63 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | |
64 | await sendContactForm({ | |
65 | url: server.url, | |
66 | fromEmail: 'toto@example.com', | |
67 | body: 'my super message', | |
4e9fa5b7 | 68 | subject: 'my subject', |
a4101923 C |
69 | fromName: 'Super toto' |
70 | }) | |
71 | ||
72 | await sendContactForm({ | |
73 | url: server.url, | |
74 | fromEmail: 'toto@example.com', | |
75 | body: 'my super message', | |
76 | fromName: 'Super toto', | |
4e9fa5b7 | 77 | subject: 'my subject', |
a4101923 C |
78 | expectedStatus: 403 |
79 | }) | |
80 | }) | |
81 | ||
82 | it('Should be able to send another contact form after a while', async function () { | |
83 | await wait(1000) | |
84 | ||
85 | await sendContactForm({ | |
86 | url: server.url, | |
87 | fromEmail: 'toto@example.com', | |
4e9fa5b7 NB |
88 | fromName: 'Super toto', |
89 | subject: 'my subject', | |
90 | body: 'my super message' | |
a4101923 C |
91 | }) |
92 | }) | |
93 | ||
7c3b7976 | 94 | after(async function () { |
a4101923 | 95 | MockSmtpServer.Instance.kill() |
7c3b7976 C |
96 | |
97 | await cleanupTests([ server ]) | |
a4101923 C |
98 | }) |
99 | }) |