]>
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 { MockSmtpServer } from '@server/tests/shared' | |
6 | import { wait } from '@shared/core-utils' | |
7 | import { HttpStatusCode } from '@shared/models' | |
8 | import { | |
9 | cleanupTests, | |
10 | ContactFormCommand, | |
11 | createSingleServer, | |
12 | PeerTubeServer, | |
13 | setAccessTokensToServers, | |
14 | waitJobs | |
15 | } from '@shared/server-commands' | |
16 | ||
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test contact form', function () { | |
20 | let server: PeerTubeServer | |
21 | const emails: object[] = [] | |
22 | let command: ContactFormCommand | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(30000) | |
26 | ||
27 | const port = await MockSmtpServer.Instance.collectEmails(emails) | |
28 | ||
29 | const overrideConfig = { | |
30 | smtp: { | |
31 | hostname: 'localhost', | |
32 | port | |
33 | } | |
34 | } | |
35 | server = await createSingleServer(1, overrideConfig) | |
36 | await setAccessTokensToServers([ server ]) | |
37 | ||
38 | command = server.contactForm | |
39 | }) | |
40 | ||
41 | it('Should send a contact form', async function () { | |
42 | this.timeout(10000) | |
43 | ||
44 | await command.send({ | |
45 | fromEmail: 'toto@example.com', | |
46 | body: 'my super message', | |
47 | subject: 'my subject', | |
48 | fromName: 'Super toto' | |
49 | }) | |
50 | ||
51 | await waitJobs(server) | |
52 | ||
53 | expect(emails).to.have.lengthOf(1) | |
54 | ||
55 | const email = emails[0] | |
56 | ||
57 | expect(email['from'][0]['address']).equal('test-admin@localhost') | |
58 | expect(email['replyTo'][0]['address']).equal('toto@example.com') | |
59 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') | |
60 | expect(email['subject']).contains('my subject') | |
61 | expect(email['text']).contains('my super message') | |
62 | }) | |
63 | ||
64 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | |
65 | this.timeout(10000) | |
66 | ||
67 | await wait(1000) | |
68 | ||
69 | await command.send({ | |
70 | fromEmail: 'toto@example.com', | |
71 | body: 'my super message', | |
72 | subject: 'my subject', | |
73 | fromName: 'Super toto' | |
74 | }) | |
75 | ||
76 | await command.send({ | |
77 | fromEmail: 'toto@example.com', | |
78 | body: 'my super message', | |
79 | fromName: 'Super toto', | |
80 | subject: 'my subject', | |
81 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
82 | }) | |
83 | }) | |
84 | ||
85 | it('Should be able to send another contact form after a while', async function () { | |
86 | await wait(1000) | |
87 | ||
88 | await command.send({ | |
89 | fromEmail: 'toto@example.com', | |
90 | fromName: 'Super toto', | |
91 | subject: 'my subject', | |
92 | body: 'my super message' | |
93 | }) | |
94 | }) | |
95 | ||
96 | it('Should not have the manage preferences link in the email', async function () { | |
97 | const email = emails[0] | |
98 | expect(email['text']).to.not.contain('Manage your notification preferences') | |
99 | }) | |
100 | ||
101 | after(async function () { | |
102 | MockSmtpServer.Instance.kill() | |
103 | ||
104 | await cleanupTests([ server ]) | |
105 | }) | |
106 | }) |