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

107 lines
2.6 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
import 'mocha'
2021-07-06 08:36:54 +00:00
import * as chai from 'chai'
2021-07-16 07:47:51 +00:00
import {
cleanupTests,
ContactFormCommand,
createSingleServer,
MockSmtpServer,
PeerTubeServer,
setAccessTokensToServers,
wait,
waitJobs
} from '@shared/server-commands'
2021-07-16 12:27:30 +00:00
import { HttpStatusCode } from '@shared/models'
2019-01-09 14:14:29 +00:00
const expect = chai.expect
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: {
hostname: 'localhost',
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]
2019-02-14 10:56:23 +00:00
expect(email['from'][0]['address']).equal('test-admin@localhost')
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 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
})
})