aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-captions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-captions.ts')
-rw-r--r--server/tests/api/videos/video-captions.ts96
1 files changed, 42 insertions, 54 deletions
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 14ecedfa6..3bb0d131c 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -1,72 +1,61 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 checkVideoFilesWereRemoved, 6 checkVideoFilesWereRemoved,
7 cleanupTests, 7 cleanupTests,
8 createMultipleServers,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 PeerTubeServer,
10 removeVideo, 11 setAccessTokensToServers,
11 uploadVideo, 12 testCaptionFile,
12 wait 13 wait,
13} from '../../../../shared/extra-utils' 14 waitJobs
14import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' 15} from '@shared/extra-utils'
15import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16import {
17 createVideoCaption,
18 deleteVideoCaption,
19 listVideoCaptions,
20 testCaptionFile
21} from '../../../../shared/extra-utils/videos/video-captions'
22import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
23 16
24const expect = chai.expect 17const expect = chai.expect
25 18
26describe('Test video captions', function () { 19describe('Test video captions', function () {
27 const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' 20 const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
28 21
29 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
30 let videoUUID: string 23 let videoUUID: string
31 24
32 before(async function () { 25 before(async function () {
33 this.timeout(60000) 26 this.timeout(60000)
34 27
35 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
36 29
37 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
38 await doubleFollow(servers[0], servers[1]) 31 await doubleFollow(servers[0], servers[1])
39 32
40 await waitJobs(servers) 33 await waitJobs(servers)
41 34
42 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) 35 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } })
43 videoUUID = res.body.video.uuid 36 videoUUID = uuid
44 37
45 await waitJobs(servers) 38 await waitJobs(servers)
46 }) 39 })
47 40
48 it('Should list the captions and return an empty list', async function () { 41 it('Should list the captions and return an empty list', async function () {
49 for (const server of servers) { 42 for (const server of servers) {
50 const res = await listVideoCaptions(server.url, videoUUID) 43 const body = await server.captions.list({ videoId: videoUUID })
51 expect(res.body.total).to.equal(0) 44 expect(body.total).to.equal(0)
52 expect(res.body.data).to.have.lengthOf(0) 45 expect(body.data).to.have.lengthOf(0)
53 } 46 }
54 }) 47 })
55 48
56 it('Should create two new captions', async function () { 49 it('Should create two new captions', async function () {
57 this.timeout(30000) 50 this.timeout(30000)
58 51
59 await createVideoCaption({ 52 await servers[0].captions.add({
60 url: servers[0].url,
61 accessToken: servers[0].accessToken,
62 language: 'ar', 53 language: 'ar',
63 videoId: videoUUID, 54 videoId: videoUUID,
64 fixture: 'subtitle-good1.vtt' 55 fixture: 'subtitle-good1.vtt'
65 }) 56 })
66 57
67 await createVideoCaption({ 58 await servers[0].captions.add({
68 url: servers[0].url,
69 accessToken: servers[0].accessToken,
70 language: 'zh', 59 language: 'zh',
71 videoId: videoUUID, 60 videoId: videoUUID,
72 fixture: 'subtitle-good2.vtt', 61 fixture: 'subtitle-good2.vtt',
@@ -78,17 +67,17 @@ describe('Test video captions', function () {
78 67
79 it('Should list these uploaded captions', async function () { 68 it('Should list these uploaded captions', async function () {
80 for (const server of servers) { 69 for (const server of servers) {
81 const res = await listVideoCaptions(server.url, videoUUID) 70 const body = await server.captions.list({ videoId: videoUUID })
82 expect(res.body.total).to.equal(2) 71 expect(body.total).to.equal(2)
83 expect(res.body.data).to.have.lengthOf(2) 72 expect(body.data).to.have.lengthOf(2)
84 73
85 const caption1: VideoCaption = res.body.data[0] 74 const caption1 = body.data[0]
86 expect(caption1.language.id).to.equal('ar') 75 expect(caption1.language.id).to.equal('ar')
87 expect(caption1.language.label).to.equal('Arabic') 76 expect(caption1.language.label).to.equal('Arabic')
88 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 77 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
89 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') 78 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
90 79
91 const caption2: VideoCaption = res.body.data[1] 80 const caption2 = body.data[1]
92 expect(caption2.language.id).to.equal('zh') 81 expect(caption2.language.id).to.equal('zh')
93 expect(caption2.language.label).to.equal('Chinese') 82 expect(caption2.language.label).to.equal('Chinese')
94 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) 83 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
@@ -99,9 +88,7 @@ describe('Test video captions', function () {
99 it('Should replace an existing caption', async function () { 88 it('Should replace an existing caption', async function () {
100 this.timeout(30000) 89 this.timeout(30000)
101 90
102 await createVideoCaption({ 91 await servers[0].captions.add({
103 url: servers[0].url,
104 accessToken: servers[0].accessToken,
105 language: 'ar', 92 language: 'ar',
106 videoId: videoUUID, 93 videoId: videoUUID,
107 fixture: 'subtitle-good2.vtt' 94 fixture: 'subtitle-good2.vtt'
@@ -112,11 +99,11 @@ describe('Test video captions', function () {
112 99
113 it('Should have this caption updated', async function () { 100 it('Should have this caption updated', async function () {
114 for (const server of servers) { 101 for (const server of servers) {
115 const res = await listVideoCaptions(server.url, videoUUID) 102 const body = await server.captions.list({ videoId: videoUUID })
116 expect(res.body.total).to.equal(2) 103 expect(body.total).to.equal(2)
117 expect(res.body.data).to.have.lengthOf(2) 104 expect(body.data).to.have.lengthOf(2)
118 105
119 const caption1: VideoCaption = res.body.data[0] 106 const caption1 = body.data[0]
120 expect(caption1.language.id).to.equal('ar') 107 expect(caption1.language.id).to.equal('ar')
121 expect(caption1.language.label).to.equal('Arabic') 108 expect(caption1.language.label).to.equal('Arabic')
122 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 109 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -127,9 +114,7 @@ describe('Test video captions', function () {
127 it('Should replace an existing caption with a srt file and convert it', async function () { 114 it('Should replace an existing caption with a srt file and convert it', async function () {
128 this.timeout(30000) 115 this.timeout(30000)
129 116
130 await createVideoCaption({ 117 await servers[0].captions.add({
131 url: servers[0].url,
132 accessToken: servers[0].accessToken,
133 language: 'ar', 118 language: 'ar',
134 videoId: videoUUID, 119 videoId: videoUUID,
135 fixture: 'subtitle-good.srt' 120 fixture: 'subtitle-good.srt'
@@ -143,11 +128,11 @@ describe('Test video captions', function () {
143 128
144 it('Should have this caption updated and converted', async function () { 129 it('Should have this caption updated and converted', async function () {
145 for (const server of servers) { 130 for (const server of servers) {
146 const res = await listVideoCaptions(server.url, videoUUID) 131 const body = await server.captions.list({ videoId: videoUUID })
147 expect(res.body.total).to.equal(2) 132 expect(body.total).to.equal(2)
148 expect(res.body.data).to.have.lengthOf(2) 133 expect(body.data).to.have.lengthOf(2)
149 134
150 const caption1: VideoCaption = res.body.data[0] 135 const caption1 = body.data[0]
151 expect(caption1.language.id).to.equal('ar') 136 expect(caption1.language.id).to.equal('ar')
152 expect(caption1.language.label).to.equal('Arabic') 137 expect(caption1.language.label).to.equal('Arabic')
153 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 138 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -172,18 +157,18 @@ describe('Test video captions', function () {
172 it('Should remove one caption', async function () { 157 it('Should remove one caption', async function () {
173 this.timeout(30000) 158 this.timeout(30000)
174 159
175 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') 160 await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' })
176 161
177 await waitJobs(servers) 162 await waitJobs(servers)
178 }) 163 })
179 164
180 it('Should only list the caption that was not deleted', async function () { 165 it('Should only list the caption that was not deleted', async function () {
181 for (const server of servers) { 166 for (const server of servers) {
182 const res = await listVideoCaptions(server.url, videoUUID) 167 const body = await server.captions.list({ videoId: videoUUID })
183 expect(res.body.total).to.equal(1) 168 expect(body.total).to.equal(1)
184 expect(res.body.data).to.have.lengthOf(1) 169 expect(body.data).to.have.lengthOf(1)
185 170
186 const caption: VideoCaption = res.body.data[0] 171 const caption = body.data[0]
187 172
188 expect(caption.language.id).to.equal('zh') 173 expect(caption.language.id).to.equal('zh')
189 expect(caption.language.label).to.equal('Chinese') 174 expect(caption.language.label).to.equal('Chinese')
@@ -193,9 +178,12 @@ describe('Test video captions', function () {
193 }) 178 })
194 179
195 it('Should remove the video, and thus all video captions', async function () { 180 it('Should remove the video, and thus all video captions', async function () {
196 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 181 const video = await servers[0].videos.get({ id: videoUUID })
182 const { data: captions } = await servers[0].captions.list({ videoId: videoUUID })
183
184 await servers[0].videos.remove({ id: videoUUID })
197 185
198 await checkVideoFilesWereRemoved(videoUUID, 1) 186 await checkVideoFilesWereRemoved({ server: servers[0], video, captions })
199 }) 187 })
200 188
201 after(async function () { 189 after(async function () {