1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { doubleFollow, flushAndRunMultipleServers, uploadVideo } from '../../utils'
6 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7 import { waitJobs } from '../../utils/server/jobs'
8 import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions'
9 import { VideoCaption } from '../../../../shared/models/videos/video-caption.model'
11 const expect = chai.expect
13 describe('Test video captions', function () {
14 let servers: ServerInfo[]
17 before(async function () {
22 servers = await flushAndRunMultipleServers(2)
24 await setAccessTokensToServers(servers)
25 await doubleFollow(servers[0], servers[1])
27 await waitJobs(servers)
29 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name' })
30 videoUUID = res.body.video.uuid
32 await waitJobs(servers)
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)
43 it('Should create two new captions', async function () {
46 await createVideoCaption({
48 accessToken: servers[0].accessToken,
51 fixture: 'subtitle-good1.vtt'
54 await createVideoCaption({
56 accessToken: servers[0].accessToken,
59 fixture: 'subtitle-good2.vtt'
62 await waitJobs(servers)
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)
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.')
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.')
85 it('Should replace an existing caption', async function () {
88 await createVideoCaption({
90 accessToken: servers[0].accessToken,
93 fixture: 'subtitle-good2.vtt'
96 await waitJobs(servers)
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)
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.')
113 it('Should remove one caption', async function () {
116 await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar')
118 await waitJobs(servers)
121 it('Should only list the caption that was not deleted', async function () {
122 for (const server of servers) {
123 const res = await listVideoCaptions(server.url, videoUUID)
124 expect(res.body.total).to.equal(1)
125 expect(res.body.data).to.have.lengthOf(1)
127 const caption: VideoCaption = res.body.data[0]
129 expect(caption.language.id).to.equal('zh')
130 expect(caption.language.label).to.equal('Chinese')
131 expect(caption.captionPath).to.equal('/static/video-captions/' + videoUUID + '-zh.vtt')
132 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
136 after(async function () {
137 killallServers(servers)