From 94565d52bb2883e09f16d1363170ac9c0dccb7a1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 15:26:15 +0200 Subject: Shared utils -> extra-utils Because they need dev dependencies --- shared/extra-utils/videos/video-captions.ts | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 shared/extra-utils/videos/video-captions.ts (limited to 'shared/extra-utils/videos/video-captions.ts') diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts new file mode 100644 index 000000000..8d67f617b --- /dev/null +++ b/shared/extra-utils/videos/video-captions.ts @@ -0,0 +1,71 @@ +import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests' +import * as request from 'supertest' +import * as chai from 'chai' +import { buildAbsoluteFixturePath } from '../miscs/miscs' + +const expect = chai.expect + +function createVideoCaption (args: { + url: string, + accessToken: string + videoId: string | number + language: string + fixture: string, + mimeType?: string, + statusCodeExpected?: number +}) { + const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language + + const captionfile = buildAbsoluteFixturePath(args.fixture) + const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile + + return makeUploadRequest({ + method: 'PUT', + url: args.url, + path, + token: args.accessToken, + fields: {}, + attaches: { + captionfile: captionfileAttach + }, + statusCodeExpected: args.statusCodeExpected || 204 + }) +} + +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 +} -- cgit v1.2.3