]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
a4101923 | 2 | |
a4101923 | 3 | import 'mocha' |
8ef9457f | 4 | import * as chai from 'chai' |
a9c58393 C |
5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils' | |
7 | import { ContactFormCommand } from '@shared/extra-utils/server' | |
a4101923 C |
8 | |
9 | const expect = chai.expect | |
10 | ||
11 | describe('Test contact form', function () { | |
12 | let server: ServerInfo | |
13 | const emails: object[] = [] | |
a9c58393 | 14 | let command: ContactFormCommand |
a4101923 C |
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 | 28 | await setAccessTokensToServers([ server ]) |
a9c58393 C |
29 | |
30 | command = server.contactFormCommand | |
a4101923 C |
31 | }) |
32 | ||
33 | it('Should send a contact form', async function () { | |
26a008fe C |
34 | this.timeout(10000) |
35 | ||
a9c58393 | 36 | await command.send({ |
a4101923 C |
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 | ||
a9c58393 | 61 | await command.send({ |
a4101923 C |
62 | fromEmail: 'toto@example.com', |
63 | body: 'my super message', | |
4e9fa5b7 | 64 | subject: 'my subject', |
a4101923 C |
65 | fromName: 'Super toto' |
66 | }) | |
67 | ||
a9c58393 | 68 | await command.send({ |
a4101923 C |
69 | fromEmail: 'toto@example.com', |
70 | body: 'my super message', | |
71 | fromName: 'Super toto', | |
4e9fa5b7 | 72 | subject: 'my subject', |
f2eb23cd | 73 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
a4101923 C |
74 | }) |
75 | }) | |
76 | ||
77 | it('Should be able to send another contact form after a while', async function () { | |
78 | await wait(1000) | |
79 | ||
a9c58393 | 80 | await command.send({ |
a4101923 | 81 | fromEmail: 'toto@example.com', |
4e9fa5b7 NB |
82 | fromName: 'Super toto', |
83 | subject: 'my subject', | |
84 | body: 'my super message' | |
a4101923 C |
85 | }) |
86 | }) | |
87 | ||
b9cf3fb6 C |
88 | it('Should not have the manage preferences link in the email', async function () { |
89 | const email = emails[0] | |
90 | expect(email['text']).to.not.contain('Manage your notification preferences') | |
91 | }) | |
92 | ||
7c3b7976 | 93 | after(async function () { |
a4101923 | 94 | MockSmtpServer.Instance.kill() |
7c3b7976 C |
95 | |
96 | await cleanupTests([ server ]) | |
a4101923 C |
97 | }) |
98 | }) |