]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/videos-common-filters.ts
Improve remote runner config UX
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-common-filters.ts
index afe42b0d5226143627a034b8ecd67eba28885fe4..3e44e2f674a3930eed57bfeb93a597172724cd74 100644 (file)
@@ -1,6 +1,6 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
+import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createSingleServer,
@@ -8,8 +8,7 @@ import {
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel
-} from '@shared/extra-utils'
-import { HttpStatusCode, UserRole, VideoInclude } from '@shared/models'
+} from '@shared/server-commands'
 
 describe('Test video filters validators', function () {
   let server: PeerTubeServer
@@ -43,7 +42,8 @@ describe('Test video filters validators', function () {
         '/api/v1/video-channels/root_channel/videos',
         '/api/v1/accounts/root/videos',
         '/api/v1/videos',
-        '/api/v1/search/videos'
+        '/api/v1/search/videos',
+        '/api/v1/users/me/subscriptions/videos'
       ]
 
       for (const path of paths) {
@@ -112,7 +112,7 @@ describe('Test video filters validators', function () {
 
     const validIncludes = [
       VideoInclude.NONE,
-      VideoInclude.HIDDEN_PRIVACY,
+      VideoInclude.BLOCKED_OWNER,
       VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED
     ]
 
@@ -120,7 +120,10 @@ describe('Test video filters validators', function () {
       token?: string
       isLocal?: boolean
       include?: VideoInclude
+      privacyOneOf?: VideoPrivacy[]
       expectedStatus: HttpStatusCode
+      excludeAlreadyWatched?: boolean
+      unauthenticatedUser?: boolean
     }) {
       const paths = [
         '/api/v1/video-channels/root_channel/videos',
@@ -130,19 +133,41 @@ describe('Test video filters validators', function () {
       ]
 
       for (const path of paths) {
+        const token = options.unauthenticatedUser
+          ? undefined
+          : options.token || server.accessToken
+
         await makeGetRequest({
           url: server.url,
           path,
-          token: options.token || server.accessToken,
+          token,
           query: {
             isLocal: options.isLocal,
-            include: options.include
+            privacyOneOf: options.privacyOneOf,
+            include: options.include,
+            excludeAlreadyWatched: options.excludeAlreadyWatched
           },
           expectedStatus: options.expectedStatus
         })
       }
     }
 
+    it('Should fail with a bad privacyOneOf', async function () {
+      await testEndpoints({ privacyOneOf: [ 'toto' ] as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    })
+
+    it('Should succeed with a good privacyOneOf', async function () {
+      await testEndpoints({ privacyOneOf: [ VideoPrivacy.INTERNAL ], expectedStatus: HttpStatusCode.OK_200 })
+    })
+
+    it('Should fail to use privacyOneOf with a simple user', async function () {
+      await testEndpoints({
+        privacyOneOf: [ VideoPrivacy.INTERNAL ],
+        token: userAccessToken,
+        expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+      })
+    })
+
     it('Should fail with a bad include', async function () {
       await testEndpoints({ include: 'toto' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
     })
@@ -195,6 +220,14 @@ describe('Test video filters validators', function () {
         }
       })
     })
+
+    it('Should fail when trying to exclude already watched videos for an unlogged user', async function () {
+      await testEndpoints({ excludeAlreadyWatched: true, unauthenticatedUser: true, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+    })
+
+    it('Should succeed when trying to exclude already watched videos for a logged user', async function () {
+      await testEndpoints({ token: userAccessToken, excludeAlreadyWatched: true, expectedStatus: HttpStatusCode.OK_200 })
+    })
   })
 
   after(async function () {