/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
-import { HttpStatusCode } from '@shared/models'
+import { buildAbsoluteFixturePath } from '@shared/core-utils'
+import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
import {
- buildAbsoluteFixturePath,
cleanupTests,
createSingleServer,
makeDeleteRequest,
makeUploadRequest,
PeerTubeServer,
setAccessTokensToServers
-} from '@shared/extra-utils'
-import { VideoCreateResult } from '@shared/models'
+} from '@shared/server-commands'
describe('Test video captions API validator', function () {
const path = '/api/v1/videos/'
let server: PeerTubeServer
let userAccessToken: string
let video: VideoCreateResult
+ let privateVideo: VideoCreateResult
// ---------------------------------------------------------------
await setAccessTokensToServers([ server ])
video = await server.videos.upload()
+ privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
{
const user = {
// })
it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
- await server.captions.createVideoCaption({
+ await server.captions.add({
language: 'zh',
videoId: video.uuid,
fixture: 'subtitle-good.srt',
})
})
+ it('Should fail with a private video without token', async function () {
+ await makeGetRequest({
+ url: server.url,
+ path: path + privateVideo.shortUUID + '/captions',
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
+ })
+ })
+
+ it('Should fail with another user token', async function () {
+ await makeGetRequest({
+ url: server.url,
+ token: userAccessToken,
+ path: path + privateVideo.shortUUID + '/captions',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ })
+
it('Should success with the correct parameters', async function () {
await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
+
+ await makeGetRequest({
+ url: server.url,
+ path: path + privateVideo.shortUUID + '/captions',
+ token: server.accessToken,
+ expectedStatus: HttpStatusCode.OK_200
+ })
})
})