]>
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' | |
f2eb23cd | 9 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
a4101923 C |
10 | |
11 | const expect = chai.expect | |
12 | ||
13 | describe('Test contact form', function () { | |
14 | let server: ServerInfo | |
15 | const emails: object[] = [] | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(30000) | |
19 | ||
7243f84d | 20 | const port = await MockSmtpServer.Instance.collectEmails(emails) |
a4101923 | 21 | |
a4101923 C |
22 | const overrideConfig = { |
23 | smtp: { | |
7243f84d C |
24 | hostname: 'localhost', |
25 | port | |
a4101923 C |
26 | } |
27 | } | |
210feb6c | 28 | server = await flushAndRunServer(1, overrideConfig) |
a4101923 C |
29 | await setAccessTokensToServers([ server ]) |
30 | }) | |
31 | ||
32 | it('Should send a contact form', async function () { | |
26a008fe C |
33 | this.timeout(10000) |
34 | ||
a4101923 C |
35 | await sendContactForm({ |
36 | url: server.url, | |
37 | fromEmail: 'toto@example.com', | |
38 | body: 'my super message', | |
4e9fa5b7 | 39 | subject: 'my subject', |
a4101923 C |
40 | fromName: 'Super toto' |
41 | }) | |
42 | ||
43 | await waitJobs(server) | |
44 | ||
45 | expect(emails).to.have.lengthOf(1) | |
46 | ||
47 | const email = emails[0] | |
48 | ||
4759fedc | 49 | expect(email['from'][0]['address']).equal('test-admin@localhost') |
df4c603d | 50 | expect(email['replyTo'][0]['address']).equal('toto@example.com') |
48f07b4a | 51 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') |
4e9fa5b7 | 52 | expect(email['subject']).contains('my subject') |
a4101923 C |
53 | expect(email['text']).contains('my super message') |
54 | }) | |
55 | ||
56 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | |
3d470a53 C |
57 | this.timeout(10000) |
58 | ||
59 | await wait(1000) | |
60 | ||
a4101923 C |
61 | await sendContactForm({ |
62 | url: server.url, | |
63 | fromEmail: 'toto@example.com', | |
64 | body: 'my super message', | |
4e9fa5b7 | 65 | subject: 'my subject', |
a4101923 C |
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', | |
4e9fa5b7 | 74 | subject: 'my subject', |
f2eb23cd | 75 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
a4101923 C |
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', | |
4e9fa5b7 NB |
85 | fromName: 'Super toto', |
86 | subject: 'my subject', | |
87 | body: 'my super message' | |
a4101923 C |
88 | }) |
89 | }) | |
90 | ||
b9cf3fb6 C |
91 | it('Should not have the manage preferences link in the email', async function () { |
92 | const email = emails[0] | |
93 | expect(email['text']).to.not.contain('Manage your notification preferences') | |
94 | }) | |
95 | ||
7c3b7976 | 96 | after(async function () { |
a4101923 | 97 | MockSmtpServer.Instance.kill() |
7c3b7976 C |
98 | |
99 | await cleanupTests([ server ]) | |
a4101923 C |
100 | }) |
101 | }) |