]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-privacy.ts
Merge branch 'feature/parallel-tests' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-privacy.ts
index 469274921f8059ad15dd647addf4c753912fcdeb..ef1cf0f071ed23f7544f32013aecc1c2d27ddf71 100644 (file)
@@ -4,27 +4,28 @@ import * as chai from 'chai'
 import 'mocha'
 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
 import {
+  cleanupTests,
   flushAndRunMultipleServers,
-  flushTests,
   getVideosList,
   killallServers,
   ServerInfo,
   setAccessTokensToServers,
-  uploadVideo,
-  wait
-} from '../../utils/index'
-import { doubleFollow } from '../../utils/server/follows'
-import { userLogin } from '../../utils/users/login'
-import { createUser } from '../../utils/users/users'
-import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
+  uploadVideo
+} from '../../../../shared/extra-utils/index'
+import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
+import { userLogin } from '../../../../shared/extra-utils/users/login'
+import { createUser } from '../../../../shared/extra-utils/users/users'
+import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
+import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 
 const expect = chai.expect
 
 describe('Test video privacy', function () {
   let servers: ServerInfo[] = []
-  let privateVideoId
-  let privateVideoUUID
-  let unlistedVideoUUID
+  let privateVideoId: number
+  let privateVideoUUID: string
+  let unlistedVideoUUID: string
+  let now: number
 
   before(async function () {
     this.timeout(50000)
@@ -47,7 +48,7 @@ describe('Test video privacy', function () {
     }
     await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
 
-    await wait(5000)
+    await waitJobs(servers)
   })
 
   it('Should not have this private video on server 2', async function () {
@@ -72,11 +73,13 @@ describe('Test video privacy', function () {
   })
 
   it('Should not be able to watch this private video with another user', async function () {
+    this.timeout(10000)
+
     const user = {
       username: 'hello',
       password: 'super password'
     }
-    await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
+    await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
 
     const token = await userLogin(servers[0], user)
     await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
@@ -96,7 +99,7 @@ describe('Test video privacy', function () {
     await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
 
     // Server 2 has transcoding enabled
-    await wait(10000)
+    await waitJobs(servers)
   })
 
   it('Should not have this unlisted video listed on server 1 and 2', async function () {
@@ -133,9 +136,10 @@ describe('Test video privacy', function () {
       privacy: VideoPrivacy.PUBLIC
     }
 
+    now = Date.now()
     await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
 
-    await wait(5000)
+    await waitJobs(servers)
   })
 
   it('Should have this new public video listed on server 1 and 2', async function () {
@@ -145,15 +149,11 @@ describe('Test video privacy', function () {
       expect(res.body.total).to.equal(1)
       expect(res.body.data).to.have.lengthOf(1)
       expect(res.body.data[0].name).to.equal('super video public')
+      expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
     }
   })
 
   after(async function () {
-    killallServers(servers)
-
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests(servers)
   })
 })