]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' | |
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' | |
9 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
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 | ||
20 | const port = await MockSmtpServer.Instance.collectEmails(emails) | |
21 | ||
22 | const overrideConfig = { | |
23 | smtp: { | |
24 | hostname: 'localhost', | |
25 | port | |
26 | } | |
27 | } | |
28 | server = await flushAndRunServer(1, overrideConfig) | |
29 | await setAccessTokensToServers([ server ]) | |
30 | }) | |
31 | ||
32 | it('Should send a contact form', async function () { | |
33 | this.timeout(10000) | |
34 | ||
35 | await sendContactForm({ | |
36 | url: server.url, | |
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 sendContactForm({ | |
62 | url: server.url, | |
63 | fromEmail: 'toto@example.com', | |
64 | body: 'my super message', | |
65 | subject: 'my subject', | |
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', | |
74 | subject: 'my subject', | |
75 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
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', | |
85 | fromName: 'Super toto', | |
86 | subject: 'my subject', | |
87 | body: 'my super message' | |
88 | }) | |
89 | }) | |
90 | ||
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 | ||
96 | after(async function () { | |
97 | MockSmtpServer.Instance.kill() | |
98 | ||
99 | await cleanupTests([ server ]) | |
100 | }) | |
101 | }) |