]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-playlists.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
index 6279f5cd05482dfc50354043ed572b3ef0971d04..d9c5bdf163236c6694ca15f90297e0fb01f039c8 100644 (file)
@@ -1,31 +1,29 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
+import { wait } from '@shared/core-utils'
+import { uuidToShort } from '@shared/extra-utils'
+import {
+  HttpStatusCode,
+  VideoPlaylist,
+  VideoPlaylistCreateResult,
+  VideoPlaylistElementType,
+  VideoPlaylistPrivacy,
+  VideoPlaylistType,
+  VideoPrivacy
+} from '@shared/models'
 import {
-  checkPlaylistFilesWereRemoved,
   cleanupTests,
   createMultipleServers,
   doubleFollow,
   PeerTubeServer,
   PlaylistsCommand,
   setAccessTokensToServers,
+  setDefaultAccountAvatar,
   setDefaultVideoChannel,
-  testImage,
-  wait,
   waitJobs
 } from '@shared/server-commands'
-import {
-  HttpStatusCode,
-  VideoPlaylist,
-  VideoPlaylistCreateResult,
-  VideoPlaylistElementType,
-  VideoPlaylistPrivacy,
-  VideoPlaylistType,
-  VideoPrivacy
-} from '@shared/models'
-
-const expect = chai.expect
 
 async function checkPlaylistElementType (
   servers: PeerTubeServer[],
@@ -59,6 +57,7 @@ describe('Test video playlists', function () {
   let playlistServer2UUID2: string
 
   let playlistServer1Id: number
+  let playlistServer1DisplayName: string
   let playlistServer1UUID: string
   let playlistServer1UUID2: string
 
@@ -73,13 +72,18 @@ describe('Test video playlists', function () {
   let commands: PlaylistsCommand[]
 
   before(async function () {
-    this.timeout(120000)
+    this.timeout(240000)
 
-    servers = await createMultipleServers(3, { transcoding: { enabled: false } })
+    servers = await createMultipleServers(3)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
+    await setDefaultAccountAvatar(servers)
+
+    for (const server of servers) {
+      await server.config.disableTranscoding()
+    }
 
     // Server 1 and server 2 follow each other
     await doubleFollow(servers[0], servers[1])
@@ -110,7 +114,7 @@ describe('Test video playlists', function () {
     await waitJobs(servers)
   })
 
-  describe('Get default playlists', function () {
+  describe('Check playlists filters and privacies', function () {
 
     it('Should list video playlist privacies', async function () {
       const privacies = await commands[0].getPrivacies()
@@ -119,9 +123,21 @@ describe('Test video playlists', function () {
       expect(privacies[3]).to.equal('Private')
     })
 
-    it('Should list watch later playlist', async function () {
+    it('Should filter on playlist type', async function () {
+      this.timeout(30000)
+
       const token = servers[0].accessToken
 
+      await commands[0].create({
+        attributes: {
+          displayName: 'my super playlist',
+          privacy: VideoPlaylistPrivacy.PUBLIC,
+          description: 'my super description',
+          thumbnailfile: 'thumbnail.jpg',
+          videoChannelId: servers[0].store.channel.id
+        }
+      })
+
       {
         const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER })
 
@@ -132,13 +148,51 @@ describe('Test video playlists', function () {
         expect(playlist.displayName).to.equal('Watch later')
         expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
         expect(playlist.type.label).to.equal('Watch later')
+        expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
       }
 
       {
-        const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR })
+        const bodyList = await commands[0].list({ playlistType: VideoPlaylistType.WATCH_LATER })
+        const bodyChannel = await commands[0].listByChannel({ handle: 'root_channel', playlistType: VideoPlaylistType.WATCH_LATER })
 
-        expect(body.total).to.equal(0)
-        expect(body.data).to.have.lengthOf(0)
+        for (const body of [ bodyList, bodyChannel ]) {
+          expect(body.total).to.equal(0)
+          expect(body.data).to.have.lengthOf(0)
+        }
+      }
+
+      {
+        const bodyList = await commands[0].list({ playlistType: VideoPlaylistType.REGULAR })
+        const bodyChannel = await commands[0].listByChannel({ handle: 'root_channel', playlistType: VideoPlaylistType.REGULAR })
+
+        let playlist: VideoPlaylist = null
+        for (const body of [ bodyList, bodyChannel ]) {
+
+          expect(body.total).to.equal(1)
+          expect(body.data).to.have.lengthOf(1)
+
+          playlist = body.data[0]
+          expect(playlist.displayName).to.equal('my super playlist')
+          expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
+          expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
+        }
+
+        await commands[0].update({
+          playlistId: playlist.id,
+          attributes: {
+            privacy: VideoPlaylistPrivacy.PRIVATE
+          }
+        })
+      }
+
+      {
+        const bodyList = await commands[0].list({ playlistType: VideoPlaylistType.REGULAR })
+        const bodyChannel = await commands[0].listByChannel({ handle: 'root_channel', playlistType: VideoPlaylistType.REGULAR })
+
+        for (const body of [ bodyList, bodyChannel ]) {
+          expect(body.total).to.equal(0)
+          expect(body.data).to.have.lengthOf(0)
+        }
       }
 
       {
@@ -400,7 +454,7 @@ describe('Test video playlists', function () {
     it('Should not list unlisted or private playlists', async function () {
       for (const server of servers) {
         const results = [
-          await server.playlists.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }),
+          await server.playlists.listByAccount({ handle: 'root@' + servers[1].host, sort: '-createdAt' }),
           await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' })
         ]
 
@@ -487,15 +541,17 @@ describe('Test video playlists', function () {
         return commands[0].addElement({ playlistId: playlistServer1Id, attributes })
       }
 
+      const playlistDisplayName = 'playlist 4'
       const playlist = await commands[0].create({
         attributes: {
-          displayName: 'playlist 4',
+          displayName: playlistDisplayName,
           privacy: VideoPlaylistPrivacy.PUBLIC,
           videoChannelId: servers[0].store.channel.id
         }
       })
 
       playlistServer1Id = playlist.id
+      playlistServer1DisplayName = playlistDisplayName
       playlistServer1UUID = playlist.uuid
 
       await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
@@ -695,70 +751,57 @@ describe('Test video playlists', function () {
       const position = 2
 
       {
-        await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port })
+        await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@' + servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
 
-        await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port })
+        await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@' + servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
       }
 
       {
-        await command.addToMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port })
+        await command.addToMyBlocklist({ token: userTokenServer1, server: servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
 
-        await command.removeFromMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port })
+        await command.removeFromMyBlocklist({ token: userTokenServer1, server: servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
       }
 
       {
-        await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
+        await command.addToServerBlocklist({ account: 'root@' + servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
 
-        await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port })
+        await command.removeFromServerBlocklist({ account: 'root@' + servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
       }
 
       {
-        await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port })
+        await command.addToServerBlocklist({ server: servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
 
-        await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
+        await command.removeFromServerBlocklist({ server: servers[1].host })
         await waitJobs(servers)
 
         await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
       }
     })
-
-    it('Should hide the video if it is NSFW', async function () {
-      const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
-      expect(body.total).to.equal(3)
-
-      const elements = body.data
-      const element = elements.find(e => e.position === 3)
-
-      expect(element).to.exist
-      expect(element.video).to.be.null
-      expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
-    })
-
   })
 
   describe('Managing playlist elements', function () {
@@ -906,6 +949,8 @@ describe('Test video playlists', function () {
         const elem = obj[servers[0].store.videos[0].id]
         expect(elem).to.have.lengthOf(1)
         expect(elem[0].playlistElementId).to.exist
+        expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
+        expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
         expect(elem[0].playlistId).to.equal(playlistServer1Id)
         expect(elem[0].startTimestamp).to.equal(15)
         expect(elem[0].stopTimestamp).to.equal(28)
@@ -915,6 +960,8 @@ describe('Test video playlists', function () {
         const elem = obj[servers[0].store.videos[3].id]
         expect(elem).to.have.lengthOf(1)
         expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4)
+        expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
+        expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
         expect(elem[0].playlistId).to.equal(playlistServer1Id)
         expect(elem[0].startTimestamp).to.equal(1)
         expect(elem[0].stopTimestamp).to.equal(35)
@@ -924,6 +971,8 @@ describe('Test video playlists', function () {
         const elem = obj[servers[0].store.videos[4].id]
         expect(elem).to.have.lengthOf(1)
         expect(elem[0].playlistId).to.equal(playlistServer1Id)
+        expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName)
+        expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID))
         expect(elem[0].startTimestamp).to.equal(45)
         expect(elem[0].stopTimestamp).to.equal(null)
       }
@@ -1047,7 +1096,7 @@ describe('Test video playlists', function () {
       this.timeout(30000)
 
       for (const server of servers) {
-        await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber)
+        await checkPlaylistFilesWereRemoved(playlistServer1UUID, server)
       }
     })