]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/videos-common-filters.ts
Fix s3 mock cleanup
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-common-filters.ts
index b176d90ab97aeddcaa711cfe83d69464ae28aaa5..30251706b6d74b27b3c4142f78de2b60ad083ced 100644 (file)
@@ -20,6 +20,8 @@ describe('Test videos filter', function () {
   let paths: string[]
   let remotePaths: string[]
 
+  const subscriptionVideosPath = '/api/v1/users/me/subscriptions/videos'
+
   // ---------------------------------------------------------------
 
   before(async function () {
@@ -31,6 +33,8 @@ describe('Test videos filter', function () {
     await setDefaultVideoChannel(servers)
     await setDefaultAccountAvatar(servers)
 
+    await servers[1].config.enableMinimumTranscoding()
+
     for (const server of servers) {
       const moderator = { username: 'moderator', password: 'my super password' }
       await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
@@ -47,6 +51,9 @@ describe('Test videos filter', function () {
         const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
         await server.videos.upload({ attributes })
       }
+
+      // Subscribing to itself
+      await server.subscriptions.add({ targetUri: 'root_channel@' + server.host })
     }
 
     await doubleFollow(servers[0], servers[1])
@@ -55,7 +62,8 @@ describe('Test videos filter', function () {
       `/api/v1/video-channels/root_channel/videos`,
       `/api/v1/accounts/root/videos`,
       '/api/v1/videos',
-      '/api/v1/search/videos'
+      '/api/v1/search/videos',
+      subscriptionVideosPath
     ]
 
     remotePaths = [
@@ -68,10 +76,20 @@ describe('Test videos filter', function () {
 
   describe('Check deprecated videos filter', function () {
 
-    async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) {
+    async function getVideosNames (options: {
+      server: PeerTubeServer
+      token: string
+      filter: string
+      skipSubscription?: boolean
+      expectedStatus?: HttpStatusCode
+    }) {
+      const { server, token, filter, skipSubscription = false, expectedStatus = HttpStatusCode.OK_200 } = options
+
       const videosResults: Video[][] = []
 
       for (const path of paths) {
+        if (skipSubscription && path === subscriptionVideosPath) continue
+
         const res = await makeGetRequest({
           url: server.url,
           path,
@@ -91,7 +109,7 @@ describe('Test videos filter', function () {
 
     it('Should display local videos', async function () {
       for (const server of servers) {
-        const namesResults = await getVideosNames(server, server.accessToken, 'local')
+        const namesResults = await getVideosNames({ server, token: server.accessToken, filter: 'local' })
         for (const names of namesResults) {
           expect(names).to.have.lengthOf(1)
           expect(names[0]).to.equal('public ' + server.serverNumber)
@@ -103,7 +121,7 @@ describe('Test videos filter', function () {
       for (const server of servers) {
         for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
 
-          const namesResults = await getVideosNames(server, token, 'all-local')
+          const namesResults = await getVideosNames({ server, token, filter: 'all-local', skipSubscription: true })
           for (const names of namesResults) {
             expect(names).to.have.lengthOf(3)
 
@@ -119,7 +137,7 @@ describe('Test videos filter', function () {
       for (const server of servers) {
         for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
 
-          const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
+          const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({ server, token, filter: 'all' })
           expect(channelVideos).to.have.lengthOf(3)
           expect(accountVideos).to.have.lengthOf(3)
 
@@ -144,13 +162,23 @@ describe('Test videos filter', function () {
       tagsAllOf?: string[]
       token?: string
       expectedStatus?: HttpStatusCode
+      excludeAlreadyWatched?: boolean
     }) {
       const res = await makeGetRequest({
         url: options.server.url,
         path: options.path,
         token: options.token ?? options.server.accessToken,
         query: {
-          ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf', 'hasWebtorrentFiles', 'hasHLSFiles', 'privacyOneOf' ]),
+          ...pick(options, [
+            'isLocal',
+            'include',
+            'category',
+            'tagsAllOf',
+            'hasWebtorrentFiles',
+            'hasHLSFiles',
+            'privacyOneOf',
+            'excludeAlreadyWatched'
+          ]),
 
           sort: 'createdAt'
         },
@@ -160,17 +188,24 @@ describe('Test videos filter', function () {
       return res.body.data as Video[]
     }
 
-    async function getVideosNames (options: {
-      server: PeerTubeServer
-      isLocal?: boolean
-      include?: VideoInclude
-      privacyOneOf?: VideoPrivacy[]
-      token?: string
-      expectedStatus?: HttpStatusCode
-    }) {
+    async function getVideosNames (
+      options: {
+        server: PeerTubeServer
+        isLocal?: boolean
+        include?: VideoInclude
+        privacyOneOf?: VideoPrivacy[]
+        token?: string
+        expectedStatus?: HttpStatusCode
+        skipSubscription?: boolean
+        excludeAlreadyWatched?: boolean
+      }
+    ) {
+      const { skipSubscription = false } = options
       const videosResults: string[][] = []
 
       for (const path of paths) {
+        if (skipSubscription && path === subscriptionVideosPath) continue
+
         const videos = await listVideos({ ...options, path })
 
         videosResults.push(videos.map(v => v.name))
@@ -194,12 +229,15 @@ describe('Test videos filter', function () {
       for (const server of servers) {
         for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
 
-          const namesResults = await getVideosNames({
-            server,
-            token,
-            isLocal: true,
-            privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ]
-          })
+          const namesResults = await getVideosNames(
+            {
+              server,
+              token,
+              isLocal: true,
+              privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ],
+              skipSubscription: true
+            }
+          )
 
           for (const names of namesResults) {
             expect(names).to.have.lengthOf(3)
@@ -498,6 +536,25 @@ describe('Test videos filter', function () {
         }
       }
     })
+
+    it('Should filter already watched videos by the user', async function () {
+      const { id } = await servers[0].videos.upload({ attributes: { name: 'video for history' } })
+
+      for (const path of paths) {
+        const videos = await listVideos({ server: servers[0], path, isLocal: true, excludeAlreadyWatched: true })
+        const foundVideo = videos.find(video => video.id === id)
+
+        expect(foundVideo).to.not.be.undefined
+      }
+      await servers[0].views.view({ id, token: servers[0].accessToken })
+
+      for (const path of paths) {
+        const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true })
+        const foundVideo = videos.find(video => video.id === id)
+
+        expect(foundVideo).to.be.undefined
+      }
+    })
   })
 
   after(async function () {