1 import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests'
2 import * as request from 'supertest'
3 import * as chai from 'chai'
4 import { buildAbsoluteFixturePath } from '../miscs/miscs'
5 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7 const expect = chai.expect
9 function createVideoCaption (args: {
12 videoId: string | number
16 statusCodeExpected?: number
18 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
20 const captionfile = buildAbsoluteFixturePath(args.fixture)
21 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
23 return makeUploadRequest({
27 token: args.accessToken,
30 captionfile: captionfileAttach
32 statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
36 function listVideoCaptions (url: string, videoId: string | number) {
37 const path = '/api/v1/videos/' + videoId + '/captions'
39 return makeGetRequest({
42 statusCodeExpected: HttpStatusCode.OK_200
46 function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
47 const path = '/api/v1/videos/' + videoId + '/captions/' + language
49 return makeDeleteRequest({
53 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
57 async function testCaptionFile (url: string, captionPath: string, containsString: string) {
58 const res = await request(url)
60 .expect(HttpStatusCode.OK_200)
62 expect(res.text).to.contain(containsString)
65 // ---------------------------------------------------------------------------