]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-privacy.ts
Fix video comments display with deleted comments
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-privacy.ts
index 4bbbb90f3df9a63d00d937b60561055c5a5bab9e..fed6ca0e0ac9e1b848a401ed63cfd19419592135 100644 (file)
@@ -5,7 +5,7 @@ import 'mocha'
 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
 import {
   cleanupTests,
-  flushAndRunMultipleServers,
+  flushAndRunServer,
   getVideosList,
   getVideosListWithToken,
   ServerInfo,
@@ -18,11 +18,12 @@ 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'
 import { Video } from '@shared/models'
+import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
 
 const expect = chai.expect
 
 describe('Test video privacy', function () {
-  let servers: ServerInfo[] = []
+  const servers: ServerInfo[] = []
   let anotherUserToken: string
 
   let privateVideoId: number
@@ -32,14 +33,24 @@ describe('Test video privacy', function () {
   let internalVideoUUID: string
 
   let unlistedVideoUUID: string
+  let nonFederatedUnlistedVideoUUID: string
 
   let now: number
 
+  const dontFederateUnlistedConfig = {
+    federation: {
+      videos: {
+        federate_unlisted: false
+      }
+    }
+  }
+
   before(async function () {
     this.timeout(50000)
 
     // Run servers
-    servers = await flushAndRunMultipleServers(2)
+    servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig))
+    servers.push(await flushAndRunServer(2))
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
@@ -100,8 +111,8 @@ describe('Test video privacy', function () {
   })
 
   it('Should not be able to watch the private/internal video with non authenticated user', async function () {
-    await getVideo(servers[0].url, privateVideoUUID, 401)
-    await getVideo(servers[0].url, internalVideoUUID, 401)
+    await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
+    await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
   })
 
   it('Should not be able to watch the private video with another user', async function () {
@@ -114,19 +125,19 @@ describe('Test video privacy', function () {
     await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
 
     anotherUserToken = await userLogin(servers[0], user)
-    await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403)
+    await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403)
   })
 
   it('Should be able to watch the internal video with another user', async function () {
-    await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200)
+    await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200)
   })
 
   it('Should be able to watch the private video with the correct user', async function () {
-    await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200)
+    await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200)
   })
 
   it('Should upload an unlisted video on server 2', async function () {
-    this.timeout(30000)
+    this.timeout(60000)
 
     const attributes = {
       name: 'unlisted video',
@@ -164,6 +175,37 @@ describe('Test video privacy', function () {
     }
   })
 
+  it('Should upload a non-federating unlisted video to server 1', async function () {
+    this.timeout(30000)
+
+    const attributes = {
+      name: 'unlisted video',
+      privacy: VideoPrivacy.UNLISTED
+    }
+    await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
+
+    await waitJobs(servers)
+  })
+
+  it('Should list my new unlisted video', async function () {
+    const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3)
+
+    expect(res.body.total).to.equal(3)
+    expect(res.body.data).to.have.lengthOf(3)
+
+    nonFederatedUnlistedVideoUUID = res.body.data[0].uuid
+  })
+
+  it('Should be able to get non-federated unlisted video from origin', async function () {
+    const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID)
+
+    expect(res.body.name).to.equal('unlisted video')
+  })
+
+  it('Should not be able to get non-federated unlisted video from federated server', async function () {
+    await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404)
+  })
+
   it('Should update the private and internal videos to public on server 1', async function () {
     this.timeout(10000)
 
@@ -230,8 +272,8 @@ describe('Test video privacy', function () {
       const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
       const videos = res.body.data
 
-      expect(res.body.total).to.equal(2)
-      expect(videos).to.have.lengthOf(2)
+      expect(res.body.total).to.equal(3)
+      expect(videos).to.have.lengthOf(3)
 
       const privateVideo = videos.find(v => v.name === 'private video becomes public')
       const internalVideo = videos.find(v => v.name === 'internal video becomes public')