]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/contact-form.ts
Merge branch 'release/2.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / contact-form.ts
index 2407ac0b50d9ac69ee8f441eebb1d60529ca7d8a..b2126b9b09981b7d80771d409a1ea743d86a2f83 100644 (file)
@@ -1,24 +1,10 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
 
-import {
-  flushTests,
-  immutableAssign,
-  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'
+import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils'
+import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
+import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
 
 describe('Test contact form API validators', function () {
   let server: ServerInfo
@@ -26,19 +12,20 @@ describe('Test contact form API validators', function () {
   const defaultBody = {
     fromName: 'super name',
     fromEmail: 'toto@example.com',
+    subject: 'my subject',
     body: 'Hello, how are you?'
   }
+  let emailPort: number
 
   // ---------------------------------------------------------------
 
   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 flushAndRunServer(1)
   })
 
   it('Should not accept a contact form if emails are disabled', async function () {
@@ -46,18 +33,22 @@ describe('Test contact form API validators', function () {
   })
 
   it('Should not accept a contact form if it is disabled in the configuration', async function () {
+    this.timeout(10000)
+
     killallServers([ server ])
 
     // Contact form is disabled
-    await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } })
+    await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
     await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
   })
 
   it('Should not accept a contact form if from email is invalid', async function () {
+    this.timeout(10000)
+
     killallServers([ server ])
 
     // Email & contact form enabled
-    await reRunServer(server, { smtp: { hostname: 'localhost' } })
+    await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
 
     await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
     await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
@@ -82,11 +73,7 @@ describe('Test contact form API validators', function () {
 
   after(async function () {
     MockSmtpServer.Instance.kill()
-    killallServers([ server ])
 
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests([ server ])
   })
 })