]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
a4101923 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
a1587156 | 5 | import { cleanupTests, 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 | ||
7243f84d | 19 | const port = await MockSmtpServer.Instance.collectEmails(emails) |
a4101923 | 20 | |
a4101923 C |
21 | const overrideConfig = { |
22 | smtp: { | |
7243f84d C |
23 | hostname: 'localhost', |
24 | port | |
a4101923 C |
25 | } |
26 | } | |
210feb6c | 27 | server = await flushAndRunServer(1, overrideConfig) |
a4101923 C |
28 | await setAccessTokensToServers([ server ]) |
29 | }) | |
30 | ||
31 | it('Should send a contact form', async function () { | |
26a008fe C |
32 | this.timeout(10000) |
33 | ||
a4101923 C |
34 | await sendContactForm({ |
35 | url: server.url, | |
36 | fromEmail: 'toto@example.com', | |
37 | body: 'my super message', | |
4e9fa5b7 | 38 | subject: 'my subject', |
a4101923 C |
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 | ||
4759fedc C |
48 | expect(email['from'][0]['address']).equal('test-admin@localhost') |
49 | expect(email['from'][0]['name']).equal('toto@example.com') | |
48f07b4a | 50 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') |
4e9fa5b7 | 51 | expect(email['subject']).contains('my subject') |
a4101923 C |
52 | expect(email['text']).contains('my super message') |
53 | }) | |
54 | ||
55 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | |
56 | await sendContactForm({ | |
57 | url: server.url, | |
58 | fromEmail: 'toto@example.com', | |
59 | body: 'my super message', | |
4e9fa5b7 | 60 | subject: 'my subject', |
a4101923 C |
61 | fromName: 'Super toto' |
62 | }) | |
63 | ||
64 | await sendContactForm({ | |
65 | url: server.url, | |
66 | fromEmail: 'toto@example.com', | |
67 | body: 'my super message', | |
68 | fromName: 'Super toto', | |
4e9fa5b7 | 69 | subject: 'my subject', |
a4101923 C |
70 | expectedStatus: 403 |
71 | }) | |
72 | }) | |
73 | ||
74 | it('Should be able to send another contact form after a while', async function () { | |
75 | await wait(1000) | |
76 | ||
77 | await sendContactForm({ | |
78 | url: server.url, | |
79 | fromEmail: 'toto@example.com', | |
4e9fa5b7 NB |
80 | fromName: 'Super toto', |
81 | subject: 'my subject', | |
82 | body: 'my super message' | |
a4101923 C |
83 | }) |
84 | }) | |
85 | ||
7c3b7976 | 86 | after(async function () { |
a4101923 | 87 | MockSmtpServer.Instance.kill() |
7c3b7976 C |
88 | |
89 | await cleanupTests([ server ]) | |
a4101923 C |
90 | }) |
91 | }) |