diff options
Diffstat (limited to 'packages/tests/src/api/server/contact-form.ts')
-rw-r--r-- | packages/tests/src/api/server/contact-form.ts | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/packages/tests/src/api/server/contact-form.ts b/packages/tests/src/api/server/contact-form.ts new file mode 100644 index 000000000..03389aa64 --- /dev/null +++ b/packages/tests/src/api/server/contact-form.ts | |||
@@ -0,0 +1,101 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { MockSmtpServer } from '@tests/shared/mock-servers/index.js' | ||
5 | import { wait } from '@peertube/peertube-core-utils' | ||
6 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | ConfigCommand, | ||
10 | ContactFormCommand, | ||
11 | createSingleServer, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers, | ||
14 | waitJobs | ||
15 | } from '@peertube/peertube-server-commands' | ||
16 | |||
17 | describe('Test contact form', function () { | ||
18 | let server: PeerTubeServer | ||
19 | const emails: object[] = [] | ||
20 | let command: ContactFormCommand | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(30000) | ||
24 | |||
25 | const port = await MockSmtpServer.Instance.collectEmails(emails) | ||
26 | |||
27 | server = await createSingleServer(1, ConfigCommand.getEmailOverrideConfig(port)) | ||
28 | await setAccessTokensToServers([ server ]) | ||
29 | |||
30 | command = server.contactForm | ||
31 | }) | ||
32 | |||
33 | it('Should send a contact form', async function () { | ||
34 | await command.send({ | ||
35 | fromEmail: 'toto@example.com', | ||
36 | body: 'my super message', | ||
37 | subject: 'my subject', | ||
38 | fromName: 'Super toto' | ||
39 | }) | ||
40 | |||
41 | await waitJobs(server) | ||
42 | |||
43 | expect(emails).to.have.lengthOf(1) | ||
44 | |||
45 | const email = emails[0] | ||
46 | |||
47 | expect(email['from'][0]['address']).equal('test-admin@127.0.0.1') | ||
48 | expect(email['replyTo'][0]['address']).equal('toto@example.com') | ||
49 | expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com') | ||
50 | expect(email['subject']).contains('my subject') | ||
51 | expect(email['text']).contains('my super message') | ||
52 | }) | ||
53 | |||
54 | it('Should not have duplicated email address in text message', async function () { | ||
55 | const text = emails[0]['text'] as string | ||
56 | |||
57 | const matches = text.match(/toto@example.com/g) | ||
58 | expect(matches).to.have.lengthOf(1) | ||
59 | }) | ||
60 | |||
61 | it('Should not be able to send another contact form because of the anti spam checker', async function () { | ||
62 | await wait(1000) | ||
63 | |||
64 | await command.send({ | ||
65 | fromEmail: 'toto@example.com', | ||
66 | body: 'my super message', | ||
67 | subject: 'my subject', | ||
68 | fromName: 'Super toto' | ||
69 | }) | ||
70 | |||
71 | await command.send({ | ||
72 | fromEmail: 'toto@example.com', | ||
73 | body: 'my super message', | ||
74 | fromName: 'Super toto', | ||
75 | subject: 'my subject', | ||
76 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
77 | }) | ||
78 | }) | ||
79 | |||
80 | it('Should be able to send another contact form after a while', async function () { | ||
81 | await wait(1000) | ||
82 | |||
83 | await command.send({ | ||
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 | }) | ||