2018-07-12 19:02:00 +02:00
|
|
|
import { makeDeleteRequest, makeGetRequest } from '../'
|
|
|
|
import { buildAbsoluteFixturePath, makeUploadRequest } from '../index'
|
|
|
|
import * as request from 'supertest'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
function createVideoCaption (args: {
|
|
|
|
url: string,
|
|
|
|
accessToken: string
|
|
|
|
videoId: string | number
|
|
|
|
language: string
|
2018-08-06 11:45:24 +02:00
|
|
|
fixture: string,
|
|
|
|
mimeType?: string,
|
|
|
|
statusCodeExpected?: number
|
2018-07-12 19:02:00 +02:00
|
|
|
}) {
|
|
|
|
const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
|
|
|
|
|
2018-08-06 11:45:24 +02:00
|
|
|
const captionfile = buildAbsoluteFixturePath(args.fixture)
|
|
|
|
const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
|
|
|
|
|
2018-07-12 19:02:00 +02:00
|
|
|
return makeUploadRequest({
|
|
|
|
method: 'PUT',
|
|
|
|
url: args.url,
|
|
|
|
path,
|
|
|
|
token: args.accessToken,
|
|
|
|
fields: {},
|
|
|
|
attaches: {
|
2018-08-06 11:45:24 +02:00
|
|
|
captionfile: captionfileAttach
|
2018-07-12 19:02:00 +02:00
|
|
|
},
|
2018-08-06 11:45:24 +02:00
|
|
|
statusCodeExpected: args.statusCodeExpected || 204
|
2018-07-12 19:02:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function listVideoCaptions (url: string, videoId: string | number) {
|
|
|
|
const path = '/api/v1/videos/' + videoId + '/captions'
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
|
|
|
|
const path = '/api/v1/videos/' + videoId + '/captions/' + language
|
|
|
|
|
|
|
|
return makeDeleteRequest({
|
|
|
|
url,
|
|
|
|
token,
|
|
|
|
path,
|
|
|
|
statusCodeExpected: 204
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testCaptionFile (url: string, captionPath: string, containsString: string) {
|
|
|
|
const res = await request(url)
|
|
|
|
.get(captionPath)
|
|
|
|
.expect(200)
|
|
|
|
|
|
|
|
expect(res.text).to.contain(containsString)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
createVideoCaption,
|
|
|
|
listVideoCaptions,
|
|
|
|
testCaptionFile,
|
|
|
|
deleteVideoCaption
|
|
|
|
}
|