]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/contact-form.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / contact-form.ts
index 1a165331ba803321a03dfdd7a23eecc20f14a033..e4e895acb3f6b050f8d449bc005a02ff0570fae5 100644 (file)
@@ -2,10 +2,18 @@
 
 import * as chai from 'chai'
 import 'mocha'
-import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/utils'
-import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
-import { waitJobs } from '../../../../shared/utils/server/jobs'
-import { sendContactForm } from '../../../../shared/utils/server/contact-form'
+import {
+  flushTests,
+  killallServers,
+  flushAndRunServer,
+  ServerInfo,
+  setAccessTokensToServers,
+  wait,
+  cleanupTests
+} from '../../../../shared/extra-utils'
+import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
+import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
 
 const expect = chai.expect
 
@@ -16,24 +24,26 @@ describe('Test contact form', function () {
   before(async function () {
     this.timeout(30000)
 
-    await MockSmtpServer.Instance.collectEmails(emails)
-
-    await flushTests()
+    const port = await MockSmtpServer.Instance.collectEmails(emails)
 
     const overrideConfig = {
       smtp: {
-        hostname: 'localhost'
+        hostname: 'localhost',
+        port
       }
     }
-    server = await runServer(1, overrideConfig)
+    server = await flushAndRunServer(1, overrideConfig)
     await setAccessTokensToServers([ server ])
   })
 
   it('Should send a contact form', async function () {
+    this.timeout(10000)
+
     await sendContactForm({
       url: server.url,
       fromEmail: 'toto@example.com',
       body: 'my super message',
+      subject: 'my subject',
       fromName: 'Super toto'
     })
 
@@ -43,9 +53,10 @@ describe('Test contact form', function () {
 
     const email = emails[0]
 
-    expect(email['from'][0]['address']).equal('toto@example.com')
-    expect(email['to'][0]['address']).equal('admin1@example.com')
-    expect(email['subject']).contains('Contact form')
+    expect(email['from'][0]['address']).equal('test-admin@localhost')
+    expect(email['from'][0]['name']).equal('toto@example.com')
+    expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
+    expect(email['subject']).contains('my subject')
     expect(email['text']).contains('my super message')
   })
 
@@ -54,6 +65,7 @@ describe('Test contact form', function () {
       url: server.url,
       fromEmail: 'toto@example.com',
       body: 'my super message',
+      subject: 'my subject',
       fromName: 'Super toto'
     })
 
@@ -62,6 +74,7 @@ describe('Test contact form', function () {
       fromEmail: 'toto@example.com',
       body: 'my super message',
       fromName: 'Super toto',
+      subject: 'my subject',
       expectedStatus: 403
     })
   })
@@ -72,13 +85,15 @@ describe('Test contact form', function () {
     await sendContactForm({
       url: server.url,
       fromEmail: 'toto@example.com',
-      body: 'my super message',
-      fromName: 'Super toto'
+      fromName: 'Super toto',
+      subject: 'my subject',
+      body: 'my super message'
     })
   })
 
   after(async function () {
     MockSmtpServer.Instance.kill()
-    killallServers([ server ])
+
+    await cleanupTests([ server ])
   })
 })