aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/videos/video-captions.ts
blob: 41e52be0702fcf97244cc3b6b67aca54964c29f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
  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
}