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