1
0
Fork 0
peertube/server/tests/api/server/contact-form.ts

111 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-01-31 15:56:52 +00:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2019-01-09 14:14:29 +00:00
2022-08-17 13:44:32 +00:00
import { expect } from 'chai'
import { MockSmtpServer } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
import { HttpStatusCode } from '@shared/models'
2021-07-16 07:47:51 +00:00
import {
cleanupTests,
ContactFormCommand,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@shared/server-commands'
2019-01-09 14:14:29 +00:00
describe('Test contact form', function () {
2021-07-16 07:47:51 +00:00
let server: PeerTubeServer
2019-01-09 14:14:29 +00:00
const emails: object[] = []
2021-07-06 13:53:25 +00:00
let command: ContactFormCommand
2019-01-09 14:14:29 +00:00
before(async function () {
this.timeout(30000)
const port = await MockSmtpServer.Instance.collectEmails(emails)
2019-01-09 14:14:29 +00:00
const overrideConfig = {
smtp: {
2022-12-09 10:14:47 +00:00
hostname: '127.0.0.1',
port
2019-01-09 14:14:29 +00:00
}
}
2021-07-16 07:47:51 +00:00
server = await createSingleServer(1, overrideConfig)
2019-01-09 14:14:29 +00:00
await setAccessTokensToServers([ server ])
2021-07-06 13:53:25 +00:00
2021-07-16 07:04:35 +00:00
command = server.contactForm
2019-01-09 14:14:29 +00:00
})
it('Should send a contact form', async function () {
2019-01-10 10:51:25 +00:00
this.timeout(10000)
2021-07-06 13:53:25 +00:00
await command.send({
2019-01-09 14:14:29 +00:00
fromEmail: 'toto@example.com',
body: 'my super message',
subject: 'my subject',
2019-01-09 14:14:29 +00:00
fromName: 'Super toto'
})
await waitJobs(server)
expect(emails).to.have.lengthOf(1)
const email = emails[0]
2022-12-09 10:14:47 +00:00
expect(email['from'][0]['address']).equal('test-admin@127.0.0.1')
expect(email['replyTo'][0]['address']).equal('toto@example.com')
2019-04-26 06:50:52 +00:00
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
expect(email['subject']).contains('my subject')
2019-01-09 14:14:29 +00:00
expect(email['text']).contains('my super message')
})
it('Should not have duplicated email address in text message', async function () {
const text = emails[0]['text'] as string
const matches = text.match(/toto@example.com/g)
expect(matches).to.have.lengthOf(1)
})
2019-01-09 14:14:29 +00:00
it('Should not be able to send another contact form because of the anti spam checker', async function () {
2021-06-14 14:52:22 +00:00
this.timeout(10000)
await wait(1000)
2021-07-06 13:53:25 +00:00
await command.send({
2019-01-09 14:14:29 +00:00
fromEmail: 'toto@example.com',
body: 'my super message',
subject: 'my subject',
2019-01-09 14:14:29 +00:00
fromName: 'Super toto'
})
2021-07-06 13:53:25 +00:00
await command.send({
2019-01-09 14:14:29 +00:00
fromEmail: 'toto@example.com',
body: 'my super message',
fromName: 'Super toto',
subject: 'my subject',
expectedStatus: HttpStatusCode.FORBIDDEN_403
2019-01-09 14:14:29 +00:00
})
})
it('Should be able to send another contact form after a while', async function () {
await wait(1000)
2021-07-06 13:53:25 +00:00
await command.send({
2019-01-09 14:14:29 +00:00
fromEmail: 'toto@example.com',
fromName: 'Super toto',
subject: 'my subject',
body: 'my super message'
2019-01-09 14:14:29 +00:00
})
})
it('Should not have the manage preferences link in the email', async function () {
const email = emails[0]
expect(email['text']).to.not.contain('Manage your notification preferences')
})
2019-04-24 13:10:37 +00:00
after(async function () {
2019-01-09 14:14:29 +00:00
MockSmtpServer.Instance.kill()
2019-04-24 13:10:37 +00:00
await cleanupTests([ server ])
2019-01-09 14:14:29 +00:00
})
})