]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/email.ts
Cleanup req files on bad request
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / email.ts
index 8eb9c0fa4058f8aff060752b250aaa902e5396ae..4be013c84e9f3f170d7be2090c36c081618822af 100644 (file)
@@ -2,15 +2,17 @@
 
 import * as chai from 'chai'
 import 'mocha'
-import { askResetPassword, createUser, resetPassword, runServer, userLogin, wait } from '../../utils'
+import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils'
 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
 import { mockSmtpServer } from '../../utils/miscs/email'
+import { waitJobs } from '../../utils/server/jobs'
 
 const expect = chai.expect
 
 describe('Test emails', function () {
   let server: ServerInfo
   let userId: number
+  let videoUUID: string
   let verificationString: string
   const emails: object[] = []
   const user = {
@@ -31,12 +33,20 @@ describe('Test emails', function () {
       }
     }
     server = await runServer(1, overrideConfig)
-
-    await wait(5000)
     await setAccessTokensToServers([ server ])
 
-    const res = await createUser(server.url, server.accessToken, user.username, user.password)
-    userId = res.body.user.id
+    {
+      const res = await createUser(server.url, server.accessToken, user.username, user.password)
+      userId = res.body.user.id
+    }
+
+    {
+      const attributes = {
+        name: 'my super name'
+      }
+      const res = await uploadVideo(server.url, server.accessToken, attributes)
+      videoUUID = res.body.video.uuid
+    }
   })
 
   describe('When resetting user password', function () {
@@ -46,7 +56,7 @@ describe('Test emails', function () {
 
       await askResetPassword(server.url, 'user_1@example.com')
 
-      await wait(3000)
+      await waitJobs(server)
       expect(emails).to.have.lengthOf(1)
 
       const email = emails[0]
@@ -83,12 +93,26 @@ describe('Test emails', function () {
     })
   })
 
+  describe('When creating a video abuse', function () {
+    it('Should send the notification email', async function () {
+      this.timeout(10000)
+
+      const reason = 'my super bad reason'
+      await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
+
+      await waitJobs(server)
+      expect(emails).to.have.lengthOf(2)
+
+      const email = emails[1]
+
+      expect(email['from'][0]['address']).equal('test-admin@localhost')
+      expect(email['to'][0]['address']).equal('admin1@example.com')
+      expect(email['subject']).contains('abuse')
+      expect(email['text']).contains(videoUUID)
+    })
+  })
+
   after(async function () {
     killallServers([ server ])
-
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
   })
 })