/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import 'mocha'
+import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
createSingleServer,
PeerTubeServer,
setAccessTokensToServers,
setDefaultVideoChannel
-} from '@shared/extra-utils'
-import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models'
+} from '@shared/server-commands'
describe('Test video filters validators', function () {
let server: PeerTubeServer
'/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) {
include?: VideoInclude
privacyOneOf?: VideoPrivacy[]
expectedStatus: HttpStatusCode
+ excludeAlreadyWatched?: boolean
+ unauthenticatedUser?: boolean
}) {
const paths = [
'/api/v1/video-channels/root_channel/videos',
]
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,
privacyOneOf: options.privacyOneOf,
- include: options.include
+ include: options.include,
+ excludeAlreadyWatched: options.excludeAlreadyWatched
},
expectedStatus: options.expectedStatus
})
}
})
})
+
+ 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 () {