]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-captions.ts
fixing tests to deal with new transcoding parameters
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-captions.ts
CommitLineData
40e87e9e
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
f4001cf4 5import { checkVideoFilesWereRemoved, doubleFollow, flushAndRunMultipleServers, removeVideo, uploadVideo, wait } from '../../utils'
40e87e9e
C
6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7import { waitJobs } from '../../utils/server/jobs'
8import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions'
9import { VideoCaption } from '../../../../shared/models/videos/video-caption.model'
10
11const expect = chai.expect
12
13describe('Test video captions', function () {
14 let servers: ServerInfo[]
15 let videoUUID: string
16
17 before(async function () {
18 this.timeout(30000)
19
20 await flushTests()
21
22 servers = await flushAndRunMultipleServers(2)
23
24 await setAccessTokensToServers(servers)
25 await doubleFollow(servers[0], servers[1])
26
27 await waitJobs(servers)
28
29 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
30 videoUUID = res.body.video.uuid
31
32 await waitJobs(servers)
33 })
34
35 it('Should list the captions and return an empty list', async function () {
36 for (const server of servers) {
37 const res = await listVideoCaptions(server.url, videoUUID)
38 expect(res.body.total).to.equal(0)
39 expect(res.body.data).to.have.lengthOf(0)
40 }
41 })
42
43 it('Should create two new captions', async function () {
44 this.timeout(30000)
45
46 await createVideoCaption({
47 url: servers[0].url,
48 accessToken: servers[0].accessToken,
49 language: 'ar',
50 videoId: videoUUID,
51 fixture: 'subtitle-good1.vtt'
52 })
53
54 await createVideoCaption({
55 url: servers[0].url,
56 accessToken: servers[0].accessToken,
57 language: 'zh',
58 videoId: videoUUID,
59 fixture: 'subtitle-good2.vtt'
60 })
61
62 await waitJobs(servers)
63 })
64
65 it('Should list these uploaded captions', async function () {
66 for (const server of servers) {
67 const res = await listVideoCaptions(server.url, videoUUID)
68 expect(res.body.total).to.equal(2)
69 expect(res.body.data).to.have.lengthOf(2)
70
71 const caption1: VideoCaption = res.body.data[0]
72 expect(caption1.language.id).to.equal('ar')
73 expect(caption1.language.label).to.equal('Arabic')
74 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
75 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
76
77 const caption2: VideoCaption = res.body.data[1]
78 expect(caption2.language.id).to.equal('zh')
79 expect(caption2.language.label).to.equal('Chinese')
80 expect(caption2.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
81 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
82 }
83 })
84
85 it('Should replace an existing caption', async function () {
86 this.timeout(30000)
87
88 await createVideoCaption({
89 url: servers[0].url,
90 accessToken: servers[0].accessToken,
91 language: 'ar',
92 videoId: videoUUID,
93 fixture: 'subtitle-good2.vtt'
94 })
95
96 await waitJobs(servers)
97 })
98
99 it('Should have this caption updated', async function () {
100 for (const server of servers) {
101 const res = await listVideoCaptions(server.url, videoUUID)
102 expect(res.body.total).to.equal(2)
103 expect(res.body.data).to.have.lengthOf(2)
104
105 const caption1: VideoCaption = res.body.data[0]
106 expect(caption1.language.id).to.equal('ar')
107 expect(caption1.language.label).to.equal('Arabic')
108 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
109 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
110 }
111 })
112
f4001cf4
C
113 it('Should replace an existing caption with a srt file and convert it', async function () {
114 this.timeout(30000)
115
116 await createVideoCaption({
117 url: servers[0].url,
118 accessToken: servers[0].accessToken,
119 language: 'ar',
120 videoId: videoUUID,
121 fixture: 'subtitle-good.srt'
122 })
123
124 await waitJobs(servers)
125
126 // Cache invalidation
127 await wait(3000)
128 })
129
130 it('Should have this caption updated and converted', async function () {
131 for (const server of servers) {
132 const res = await listVideoCaptions(server.url, videoUUID)
133 expect(res.body.total).to.equal(2)
134 expect(res.body.data).to.have.lengthOf(2)
135
136 const caption1: VideoCaption = res.body.data[0]
137 expect(caption1.language.id).to.equal('ar')
138 expect(caption1.language.label).to.equal('Arabic')
139 expect(caption1.captionPath).to.equal('/static/video-captions/' + videoUUID + '-ar.vtt')
140
141 const expected = 'WEBVTT FILE\r\n' +
142 '\r\n' +
143 '1\r\n' +
144 '00:00:01.600 --> 00:00:04.200\r\n' +
145 'English (US)\r\n' +
146 '\r\n' +
147 '2\r\n' +
148 '00:00:05.900 --> 00:00:07.999\r\n' +
149 'This is a subtitle in American English\r\n' +
150 '\r\n' +
151 '3\r\n' +
152 '00:00:10.000 --> 00:00:14.000\r\n' +
153 'Adding subtitles is very easy to do\r\n'
154 await testCaptionFile(server.url, caption1.captionPath, expected)
155 }
156 })
157
40e87e9e
C
158 it('Should remove one caption', async function () {
159 this.timeout(30000)
160
161 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
162
163 await waitJobs(servers)
164 })
165
166 it('Should only list the caption that was not deleted', async function () {
167 for (const server of servers) {
168 const res = await listVideoCaptions(server.url, videoUUID)
169 expect(res.body.total).to.equal(1)
170 expect(res.body.data).to.have.lengthOf(1)
171
172 const caption: VideoCaption = res.body.data[0]
173
174 expect(caption.language.id).to.equal('zh')
175 expect(caption.language.label).to.equal('Chinese')
176 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
177 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
178 }
179 })
180
f4001cf4
C
181 it('Should remove the video, and thus all video captions', async function () {
182 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
183
184 await checkVideoFilesWereRemoved(videoUUID, 1)
185 })
186
40e87e9e
C
187 after(async function () {
188 killallServers(servers)
189 })
190})