]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/contact-form.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / contact-form.ts
index c7e014b1ff04a90fc296e719522764656c928fd7..f0f8819b923d7c1b0023279c1c999cc96ecf6589 100644 (file)
@@ -1,96 +1,86 @@
-/* tslint:disable:no-unused-expression */
-
-import 'mocha'
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
+import { MockSmtpServer } from '@server/tests/shared'
+import { HttpStatusCode } from '@shared/models'
 import {
-  flushTests,
-  immutableAssign,
+  cleanupTests,
+  ConfigCommand,
+  ContactFormCommand,
+  createSingleServer,
   killallServers,
-  reRunServer,
-  runServer,
-  ServerInfo,
-  setAccessTokensToServers
-} from '../../../../shared/utils'
-import {
-  checkBadCountPagination,
-  checkBadSortPagination,
-  checkBadStartPagination
-} from '../../../../shared/utils/requests/check-api-params'
-import { getAccount } from '../../../../shared/utils/users/accounts'
-import { sendContactForm } from '../../../../shared/utils/server/contact-form'
-import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
+  PeerTubeServer
+} from '@shared/server-commands'
 
 describe('Test contact form API validators', function () {
-  let server: ServerInfo
+  let server: PeerTubeServer
   const emails: object[] = []
   const defaultBody = {
     fromName: 'super name',
     fromEmail: 'toto@example.com',
+    subject: 'my subject',
     body: 'Hello, how are you?'
   }
+  let emailPort: number
+  let command: ContactFormCommand
 
   // ---------------------------------------------------------------
 
   before(async function () {
     this.timeout(60000)
 
-    await flushTests()
-    await MockSmtpServer.Instance.collectEmails(emails)
+    emailPort = await MockSmtpServer.Instance.collectEmails(emails)
 
     // Email is disabled
-    server = await runServer(1)
+    server = await createSingleServer(1)
+    command = server.contactForm
   })
 
   it('Should not accept a contact form if emails are disabled', async function () {
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
+    await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
   })
 
   it('Should not accept a contact form if it is disabled in the configuration', async function () {
-    this.timeout(10000)
+    this.timeout(25000)
 
-    killallServers([ server ])
+    await killallServers([ server ])
 
     // Contact form is disabled
-    await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } })
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
+    await server.run({ ...ConfigCommand.getEmailOverrideConfig(emailPort), contact_form: { enabled: false } })
+    await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
   })
 
   it('Should not accept a contact form if from email is invalid', async function () {
-    this.timeout(10000)
+    this.timeout(25000)
 
-    killallServers([ server ])
+    await killallServers([ server ])
 
     // Email & contact form enabled
-    await reRunServer(server, { smtp: { hostname: 'localhost' } })
+    await server.run(ConfigCommand.getEmailOverrideConfig(emailPort))
 
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: undefined }))
+    await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, fromEmail: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
   })
 
   it('Should not accept a contact form if from name is invalid', async function () {
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: 'name'.repeat(100) }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: '' }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromName: undefined }))
+    await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, fromName: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
   })
 
   it('Should not accept a contact form if body is invalid', async function () {
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'body'.repeat(5000) }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: 'a' }))
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, body: undefined }))
+    await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    await command.send({ ...defaultBody, body: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
   })
 
   it('Should accept a contact form with the correct parameters', async function () {
-    await sendContactForm(immutableAssign(defaultBody, { url: server.url }))
+    await command.send(defaultBody)
   })
 
   after(async function () {
     MockSmtpServer.Instance.kill()
-    killallServers([ server ])
 
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests([ server ])
   })
 })