]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/videos-common-filters.ts
Implement avatar miniatures (#4639)
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-common-filters.ts
index eb2d2ab509192fc5eba78b27f14e8af56614e967..317de90a9fce002f1b92c8ef34e22cc4e8741198 100644 (file)
@@ -3,6 +3,7 @@
 import 'mocha'
 import { expect } from 'chai'
 import { pick } from '@shared/core-utils'
+import { HttpStatusCode, UserRole, Video, VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createMultipleServers,
@@ -10,10 +11,10 @@ import {
   makeGetRequest,
   PeerTubeServer,
   setAccessTokensToServers,
+  setDefaultAccountAvatar,
   setDefaultVideoChannel,
   waitJobs
-} from '@shared/extra-utils'
-import { HttpStatusCode, UserRole, Video, VideoInclude, VideoPrivacy } from '@shared/models'
+} from '@shared/server-commands'
 
 describe('Test videos filter', function () {
   let servers: PeerTubeServer[]
@@ -29,6 +30,7 @@ describe('Test videos filter', function () {
 
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
+    await setDefaultAccountAvatar(servers)
 
     for (const server of servers) {
       const moderator = { username: 'moderator', password: 'my super password' }
@@ -135,7 +137,10 @@ describe('Test videos filter', function () {
       server: PeerTubeServer
       path: string
       isLocal?: boolean
+      hasWebtorrentFiles?: boolean
+      hasHLSFiles?: boolean
       include?: VideoInclude
+      privacyOneOf?: VideoPrivacy[]
       category?: number
       tagsAllOf?: string[]
       token?: string
@@ -146,7 +151,7 @@ describe('Test videos filter', function () {
         path: options.path,
         token: options.token ?? options.server.accessToken,
         query: {
-          ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf' ]),
+          ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf', 'hasWebtorrentFiles', 'hasHLSFiles', 'privacyOneOf' ]),
 
           sort: 'createdAt'
         },
@@ -160,6 +165,7 @@ describe('Test videos filter', function () {
       server: PeerTubeServer
       isLocal?: boolean
       include?: VideoInclude
+      privacyOneOf?: VideoPrivacy[]
       token?: string
       expectedStatus?: HttpStatusCode
     }) {
@@ -193,7 +199,7 @@ describe('Test videos filter', function () {
             server,
             token,
             isLocal: true,
-            include: VideoInclude.HIDDEN_PRIVACY
+            privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ]
           })
 
           for (const names of namesResults) {
@@ -214,7 +220,7 @@ describe('Test videos filter', function () {
           const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({
             server,
             token,
-            include: VideoInclude.HIDDEN_PRIVACY
+            privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ]
           })
 
           expect(channelVideos).to.have.lengthOf(3)
@@ -365,17 +371,41 @@ describe('Test videos filter', function () {
       await servers[0].blocklist.removeFromServerBlocklist({ server: servers[1].host })
     })
 
+    it('Should include video files', async function () {
+      for (const path of paths) {
+        {
+          const videos = await listVideos({ server: servers[0], path })
+
+          for (const video of videos) {
+            const videoWithFiles = video as VideoDetails
+
+            expect(videoWithFiles.files).to.not.exist
+            expect(videoWithFiles.streamingPlaylists).to.not.exist
+          }
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, include: VideoInclude.FILES })
+
+          for (const video of videos) {
+            const videoWithFiles = video as VideoDetails
+
+            expect(videoWithFiles.files).to.exist
+            expect(videoWithFiles.files).to.have.length.at.least(1)
+          }
+        }
+      }
+    })
+
     it('Should filter by tags and category', async function () {
       await servers[0].videos.upload({ attributes: { name: 'tag filter', tags: [ 'tag1', 'tag2' ] } })
       await servers[0].videos.upload({ attributes: { name: 'tag filter with category', tags: [ 'tag3' ], category: 4 } })
 
       for (const path of paths) {
         {
-
           const videos = await listVideos({ server: servers[0], path, tagsAllOf: [ 'tag1', 'tag2' ] })
           expect(videos).to.have.lengthOf(1)
           expect(videos[0].name).to.equal('tag filter')
-
         }
 
         {
@@ -395,6 +425,80 @@ describe('Test videos filter', function () {
         }
       }
     })
+
+    it('Should filter by HLS or WebTorrent files', async function () {
+      this.timeout(360000)
+
+      const finderFactory = (name: string) => (videos: Video[]) => videos.some(v => v.name === name)
+
+      await servers[0].config.enableTranscoding(true, false)
+      await servers[0].videos.upload({ attributes: { name: 'webtorrent video' } })
+      const hasWebtorrent = finderFactory('webtorrent video')
+
+      await waitJobs(servers)
+
+      await servers[0].config.enableTranscoding(false, true)
+      await servers[0].videos.upload({ attributes: { name: 'hls video' } })
+      const hasHLS = finderFactory('hls video')
+
+      await waitJobs(servers)
+
+      await servers[0].config.enableTranscoding(true, true)
+      await servers[0].videos.upload({ attributes: { name: 'hls and webtorrent video' } })
+      const hasBoth = finderFactory('hls and webtorrent video')
+
+      await waitJobs(servers)
+
+      for (const path of paths) {
+        {
+          const videos = await listVideos({ server: servers[0], path, hasWebtorrentFiles: true })
+
+          expect(hasWebtorrent(videos)).to.be.true
+          expect(hasHLS(videos)).to.be.false
+          expect(hasBoth(videos)).to.be.true
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, hasWebtorrentFiles: false })
+
+          expect(hasWebtorrent(videos)).to.be.false
+          expect(hasHLS(videos)).to.be.true
+          expect(hasBoth(videos)).to.be.false
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, hasHLSFiles: true })
+
+          expect(hasWebtorrent(videos)).to.be.false
+          expect(hasHLS(videos)).to.be.true
+          expect(hasBoth(videos)).to.be.true
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, hasHLSFiles: false })
+
+          expect(hasWebtorrent(videos)).to.be.true
+          expect(hasHLS(videos)).to.be.false
+          expect(hasBoth(videos)).to.be.false
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, hasHLSFiles: false, hasWebtorrentFiles: false })
+
+          expect(hasWebtorrent(videos)).to.be.false
+          expect(hasHLS(videos)).to.be.false
+          expect(hasBoth(videos)).to.be.false
+        }
+
+        {
+          const videos = await listVideos({ server: servers[0], path, hasHLSFiles: true, hasWebtorrentFiles: true })
+
+          expect(hasWebtorrent(videos)).to.be.false
+          expect(hasHLS(videos)).to.be.false
+          expect(hasBoth(videos)).to.be.true
+        }
+      }
+    })
   })
 
   after(async function () {