aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-08 11:49:38 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commita2470c9f4bfc7f49f4b94de935bacdd53fd54f29 (patch)
treecb6b6b33d1a404fe31547c004241a7eb9743b64e /server/tests/api/videos
parente3d15a6a9aed97a004d9dac1b7a6499d794e080a (diff)
downloadPeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.gz
PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.zst
PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.zip
Introduce captions command
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/video-captions.ts77
-rw-r--r--server/tests/api/videos/video-imports.ts33
2 files changed, 48 insertions, 62 deletions
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 14ecedfa6..83ee809b8 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -1,25 +1,20 @@
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 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 removeVideo, 10 removeVideo,
11 ServerInfo,
12 setAccessTokensToServers,
13 testCaptionFile,
11 uploadVideo, 14 uploadVideo,
12 wait 15 wait,
13} from '../../../../shared/extra-utils' 16 waitJobs
14import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' 17} 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 18
24const expect = chai.expect 19const expect = chai.expect
25 20
@@ -47,26 +42,22 @@ describe('Test video captions', function () {
47 42
48 it('Should list the captions and return an empty list', async function () { 43 it('Should list the captions and return an empty list', async function () {
49 for (const server of servers) { 44 for (const server of servers) {
50 const res = await listVideoCaptions(server.url, videoUUID) 45 const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
51 expect(res.body.total).to.equal(0) 46 expect(body.total).to.equal(0)
52 expect(res.body.data).to.have.lengthOf(0) 47 expect(body.data).to.have.lengthOf(0)
53 } 48 }
54 }) 49 })
55 50
56 it('Should create two new captions', async function () { 51 it('Should create two new captions', async function () {
57 this.timeout(30000) 52 this.timeout(30000)
58 53
59 await createVideoCaption({ 54 await servers[0].captionsCommand.createVideoCaption({
60 url: servers[0].url,
61 accessToken: servers[0].accessToken,
62 language: 'ar', 55 language: 'ar',
63 videoId: videoUUID, 56 videoId: videoUUID,
64 fixture: 'subtitle-good1.vtt' 57 fixture: 'subtitle-good1.vtt'
65 }) 58 })
66 59
67 await createVideoCaption({ 60 await servers[0].captionsCommand.createVideoCaption({
68 url: servers[0].url,
69 accessToken: servers[0].accessToken,
70 language: 'zh', 61 language: 'zh',
71 videoId: videoUUID, 62 videoId: videoUUID,
72 fixture: 'subtitle-good2.vtt', 63 fixture: 'subtitle-good2.vtt',
@@ -78,17 +69,17 @@ describe('Test video captions', function () {
78 69
79 it('Should list these uploaded captions', async function () { 70 it('Should list these uploaded captions', async function () {
80 for (const server of servers) { 71 for (const server of servers) {
81 const res = await listVideoCaptions(server.url, videoUUID) 72 const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
82 expect(res.body.total).to.equal(2) 73 expect(body.total).to.equal(2)
83 expect(res.body.data).to.have.lengthOf(2) 74 expect(body.data).to.have.lengthOf(2)
84 75
85 const caption1: VideoCaption = res.body.data[0] 76 const caption1 = body.data[0]
86 expect(caption1.language.id).to.equal('ar') 77 expect(caption1.language.id).to.equal('ar')
87 expect(caption1.language.label).to.equal('Arabic') 78 expect(caption1.language.label).to.equal('Arabic')
88 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 79 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
89 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') 80 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
90 81
91 const caption2: VideoCaption = res.body.data[1] 82 const caption2 = body.data[1]
92 expect(caption2.language.id).to.equal('zh') 83 expect(caption2.language.id).to.equal('zh')
93 expect(caption2.language.label).to.equal('Chinese') 84 expect(caption2.language.label).to.equal('Chinese')
94 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) 85 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
@@ -99,9 +90,7 @@ describe('Test video captions', function () {
99 it('Should replace an existing caption', async function () { 90 it('Should replace an existing caption', async function () {
100 this.timeout(30000) 91 this.timeout(30000)
101 92
102 await createVideoCaption({ 93 await servers[0].captionsCommand.createVideoCaption({
103 url: servers[0].url,
104 accessToken: servers[0].accessToken,
105 language: 'ar', 94 language: 'ar',
106 videoId: videoUUID, 95 videoId: videoUUID,
107 fixture: 'subtitle-good2.vtt' 96 fixture: 'subtitle-good2.vtt'
@@ -112,11 +101,11 @@ describe('Test video captions', function () {
112 101
113 it('Should have this caption updated', async function () { 102 it('Should have this caption updated', async function () {
114 for (const server of servers) { 103 for (const server of servers) {
115 const res = await listVideoCaptions(server.url, videoUUID) 104 const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
116 expect(res.body.total).to.equal(2) 105 expect(body.total).to.equal(2)
117 expect(res.body.data).to.have.lengthOf(2) 106 expect(body.data).to.have.lengthOf(2)
118 107
119 const caption1: VideoCaption = res.body.data[0] 108 const caption1 = body.data[0]
120 expect(caption1.language.id).to.equal('ar') 109 expect(caption1.language.id).to.equal('ar')
121 expect(caption1.language.label).to.equal('Arabic') 110 expect(caption1.language.label).to.equal('Arabic')
122 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 111 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -127,9 +116,7 @@ describe('Test video captions', function () {
127 it('Should replace an existing caption with a srt file and convert it', async function () { 116 it('Should replace an existing caption with a srt file and convert it', async function () {
128 this.timeout(30000) 117 this.timeout(30000)
129 118
130 await createVideoCaption({ 119 await servers[0].captionsCommand.createVideoCaption({
131 url: servers[0].url,
132 accessToken: servers[0].accessToken,
133 language: 'ar', 120 language: 'ar',
134 videoId: videoUUID, 121 videoId: videoUUID,
135 fixture: 'subtitle-good.srt' 122 fixture: 'subtitle-good.srt'
@@ -143,11 +130,11 @@ describe('Test video captions', function () {
143 130
144 it('Should have this caption updated and converted', async function () { 131 it('Should have this caption updated and converted', async function () {
145 for (const server of servers) { 132 for (const server of servers) {
146 const res = await listVideoCaptions(server.url, videoUUID) 133 const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
147 expect(res.body.total).to.equal(2) 134 expect(body.total).to.equal(2)
148 expect(res.body.data).to.have.lengthOf(2) 135 expect(body.data).to.have.lengthOf(2)
149 136
150 const caption1: VideoCaption = res.body.data[0] 137 const caption1 = body.data[0]
151 expect(caption1.language.id).to.equal('ar') 138 expect(caption1.language.id).to.equal('ar')
152 expect(caption1.language.label).to.equal('Arabic') 139 expect(caption1.language.label).to.equal('Arabic')
153 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) 140 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
@@ -172,18 +159,18 @@ describe('Test video captions', function () {
172 it('Should remove one caption', async function () { 159 it('Should remove one caption', async function () {
173 this.timeout(30000) 160 this.timeout(30000)
174 161
175 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') 162 await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' })
176 163
177 await waitJobs(servers) 164 await waitJobs(servers)
178 }) 165 })
179 166
180 it('Should only list the caption that was not deleted', async function () { 167 it('Should only list the caption that was not deleted', async function () {
181 for (const server of servers) { 168 for (const server of servers) {
182 const res = await listVideoCaptions(server.url, videoUUID) 169 const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
183 expect(res.body.total).to.equal(1) 170 expect(body.total).to.equal(1)
184 expect(res.body.data).to.have.lengthOf(1) 171 expect(body.data).to.have.lengthOf(1)
185 172
186 const caption: VideoCaption = res.body.data[0] 173 const caption = body.data[0]
187 174
188 expect(caption.language.id).to.equal('zh') 175 expect(caption.language.id).to.equal('zh')
189 expect(caption.language.label).to.equal('Chinese') 176 expect(caption.language.label).to.equal('Chinese')
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index a4a9132b4..14aed604f 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -11,7 +11,6 @@ import {
11 getVideo, 11 getVideo,
12 getVideosList, 12 getVideosList,
13 immutableAssign, 13 immutableAssign,
14 listVideoCaptions,
15 ServerInfo, 14 ServerInfo,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 testCaptionFile 16 testCaptionFile
@@ -25,7 +24,7 @@ import {
25 getYoutubeVideoUrl, 24 getYoutubeVideoUrl,
26 importVideo 25 importVideo
27} from '../../../../shared/extra-utils/videos/video-imports' 26} from '../../../../shared/extra-utils/videos/video-imports'
28import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' 27import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
29 28
30const expect = chai.expect 29const expect = chai.expect
31 30
@@ -36,8 +35,8 @@ describe('Test video imports', function () {
36 35
37 if (areHttpImportTestsDisabled()) return 36 if (areHttpImportTestsDisabled()) return
38 37
39 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { 38 async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) {
40 const resHttp = await getVideo(url, idHttp) 39 const resHttp = await getVideo(server.url, idHttp)
41 const videoHttp: VideoDetails = resHttp.body 40 const videoHttp: VideoDetails = resHttp.body
42 41
43 expect(videoHttp.name).to.equal('small video - youtube') 42 expect(videoHttp.name).to.equal('small video - youtube')
@@ -55,9 +54,9 @@ describe('Test video imports', function () {
55 expect(originallyPublishedAt.getMonth()).to.equal(0) 54 expect(originallyPublishedAt.getMonth()).to.equal(0)
56 expect(originallyPublishedAt.getFullYear()).to.equal(2019) 55 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
57 56
58 const resMagnet = await getVideo(url, idMagnet) 57 const resMagnet = await getVideo(server.url, idMagnet)
59 const videoMagnet: VideoDetails = resMagnet.body 58 const videoMagnet: VideoDetails = resMagnet.body
60 const resTorrent = await getVideo(url, idTorrent) 59 const resTorrent = await getVideo(server.url, idTorrent)
61 const videoTorrent: VideoDetails = resTorrent.body 60 const videoTorrent: VideoDetails = resTorrent.body
62 61
63 for (const video of [ videoMagnet, videoTorrent ]) { 62 for (const video of [ videoMagnet, videoTorrent ]) {
@@ -73,12 +72,12 @@ describe('Test video imports', function () {
73 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') 72 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
74 expect(videoMagnet.name).to.contain('super peertube2 video') 73 expect(videoMagnet.name).to.contain('super peertube2 video')
75 74
76 const resCaptions = await listVideoCaptions(url, idHttp) 75 const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp })
77 expect(resCaptions.body.total).to.equal(2) 76 expect(bodyCaptions.total).to.equal(2)
78 } 77 }
79 78
80 async function checkVideoServer2 (url: string, id: number | string) { 79 async function checkVideoServer2 (server: ServerInfo, id: number | string) {
81 const res = await getVideo(url, id) 80 const res = await getVideo(server.url, id)
82 const video: VideoDetails = res.body 81 const video: VideoDetails = res.body
83 82
84 expect(video.name).to.equal('my super name') 83 expect(video.name).to.equal('my super name')
@@ -91,8 +90,8 @@ describe('Test video imports', function () {
91 90
92 expect(video.files).to.have.lengthOf(1) 91 expect(video.files).to.have.lengthOf(1)
93 92
94 const resCaptions = await listVideoCaptions(url, id) 93 const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id })
95 expect(resCaptions.body.total).to.equal(2) 94 expect(bodyCaptions.total).to.equal(2)
96 } 95 }
97 96
98 before(async function () { 97 before(async function () {
@@ -135,8 +134,8 @@ describe('Test video imports', function () {
135 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) 134 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
136 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) 135 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
137 136
138 const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) 137 const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id })
139 const videoCaptions: VideoCaption[] = resCaptions.body.data 138 const videoCaptions = bodyCaptions.data
140 expect(videoCaptions).to.have.lengthOf(2) 139 expect(videoCaptions).to.have.lengthOf(2)
141 140
142 const enCaption = videoCaptions.find(caption => caption.language.id === 'en') 141 const enCaption = videoCaptions.find(caption => caption.language.id === 'en')
@@ -241,7 +240,7 @@ Ajouter un sous-titre est vraiment facile`)
241 expect(res.body.data).to.have.lengthOf(3) 240 expect(res.body.data).to.have.lengthOf(3)
242 241
243 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data 242 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
244 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 243 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
245 } 244 }
246 }) 245 })
247 246
@@ -273,10 +272,10 @@ Ajouter un sous-titre est vraiment facile`)
273 expect(res.body.total).to.equal(4) 272 expect(res.body.total).to.equal(4)
274 expect(res.body.data).to.have.lengthOf(4) 273 expect(res.body.data).to.have.lengthOf(4)
275 274
276 await checkVideoServer2(server.url, res.body.data[0].uuid) 275 await checkVideoServer2(server, res.body.data[0].uuid)
277 276
278 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data 277 const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data
279 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) 278 await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
280 } 279 }
281 }) 280 })
282 281