]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/videos/video-captions.ts
Render CSS/title/description tags on server side
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / video-captions.ts
CommitLineData
40e87e9e
C
1import { makeDeleteRequest, makeGetRequest } from '../'
2import { buildAbsoluteFixturePath, makeUploadRequest } from '../index'
3import * as request from 'supertest'
4import * as chai from 'chai'
5
6const expect = chai.expect
7
8function createVideoCaption (args: {
9 url: string,
10 accessToken: string
11 videoId: string | number
12 language: string
13 fixture: string
14}) {
15 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
16
17 return makeUploadRequest({
18 method: 'PUT',
19 url: args.url,
20 path,
21 token: args.accessToken,
22 fields: {},
23 attaches: {
24 captionfile: buildAbsoluteFixturePath(args.fixture)
25 },
26 statusCodeExpected: 204
27 })
28}
29
30function listVideoCaptions (url: string, videoId: string | number) {
31 const path = '/api/v1/videos/' + videoId + '/captions'
32
33 return makeGetRequest({
34 url,
35 path,
36 statusCodeExpected: 200
37 })
38}
39
40function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
41 const path = '/api/v1/videos/' + videoId + '/captions/' + language
42
43 return makeDeleteRequest({
44 url,
45 token,
46 path,
47 statusCodeExpected: 204
48 })
49}
50
51async function testCaptionFile (url: string, captionPath: string, containsString: string) {
52 const res = await request(url)
53 .get(captionPath)
54 .expect(200)
55
56 expect(res.text).to.contain(containsString)
57}
58
59// ---------------------------------------------------------------------------
60
61export {
62 createVideoCaption,
63 listVideoCaptions,
64 testCaptionFile,
65 deleteVideoCaption
66}