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