]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
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' | |
8 | ||
9 | const expect = chai.expect | |
10 | ||
11 | describe('Test contact form', function () { | |
12 | let server: ServerInfo | |
13 | const emails: object[] = [] | |
14 | let command: ContactFormCommand | |
15 | ||
16 | before(async function () { | |
17 | this.timeout(30000) | |
18 | ||
19 | const port = await MockSmtpServer.Instance.collectEmails(emails) | |
20 | ||
21 | const overrideConfig = { | |
22 | smtp: { | |
23 | hostname: 'localhost', | |
24 | port | |
25 | } | |
26 | } | |
27 | server = await flushAndRunServer(1, overrideConfig) | |
28 | await setAccessTokensToServers([ server ]) | |
29 | ||
30 | command = server.contactFormCommand | |
31 | }) | |
32 | ||
33 | it('Should send a contact form', async function () { | |
34 | this.timeout(10000) | |
35 | ||
36 | await command.send({ | |
37 | fromEmail: 'toto@example.com', | |
38 | body: 'my super message', | |
39 | subject: 'my subject', | |
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 | ||
49 | expect(email['from'][0]['address']).equal('test-admin@localhost') | |
50 | expect(email['replyTo'][0]['address']).equal('toto@example.com') | |
51 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') | |
52 | expect(email['subject']).contains('my subject') | |
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 () { | |
57 | this.timeout(10000) | |
58 | ||
59 | await wait(1000) | |
60 | ||
61 | await command.send({ | |
62 | fromEmail: 'toto@example.com', | |
63 | body: 'my super message', | |
64 | subject: 'my subject', | |
65 | fromName: 'Super toto' | |
66 | }) | |
67 | ||
68 | await command.send({ | |
69 | fromEmail: 'toto@example.com', | |
70 | body: 'my super message', | |
71 | fromName: 'Super toto', | |
72 | subject: 'my subject', | |
73 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
74 | }) | |
75 | }) | |
76 | ||
77 | it('Should be able to send another contact form after a while', async function () { | |
78 | await wait(1000) | |
79 | ||
80 | await command.send({ | |
81 | fromEmail: 'toto@example.com', | |
82 | fromName: 'Super toto', | |
83 | subject: 'my subject', | |
84 | body: 'my super message' | |
85 | }) | |
86 | }) | |
87 | ||
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 | ||
93 | after(async function () { | |
94 | MockSmtpServer.Instance.kill() | |
95 | ||
96 | await cleanupTests([ server ]) | |
97 | }) | |
98 | }) |