]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-captions.ts
Generate random uuid for video files
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-captions.ts
index 83ee809b88465c496150c904db47d466b9badc61..3bb0d131cba6db5d9a8d01e990a97a7701f3e6b0 100644 (file)
@@ -5,13 +5,11 @@ import * as chai from 'chai'
 import {
   checkVideoFilesWereRemoved,
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  removeVideo,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   testCaptionFile,
-  uploadVideo,
   wait,
   waitJobs
 } from '@shared/extra-utils'
@@ -21,28 +19,28 @@ const expect = chai.expect
 describe('Test video captions', function () {
   const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
 
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let videoUUID: string
 
   before(async function () {
     this.timeout(60000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     await setAccessTokensToServers(servers)
     await doubleFollow(servers[0], servers[1])
 
     await waitJobs(servers)
 
-    const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' })
-    videoUUID = res.body.video.uuid
+    const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } })
+    videoUUID = uuid
 
     await waitJobs(servers)
   })
 
   it('Should list the captions and return an empty list', async function () {
     for (const server of servers) {
-      const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
+      const body = await server.captions.list({ videoId: videoUUID })
       expect(body.total).to.equal(0)
       expect(body.data).to.have.lengthOf(0)
     }
@@ -51,13 +49,13 @@ describe('Test video captions', function () {
   it('Should create two new captions', async function () {
     this.timeout(30000)
 
-    await servers[0].captionsCommand.createVideoCaption({
+    await servers[0].captions.add({
       language: 'ar',
       videoId: videoUUID,
       fixture: 'subtitle-good1.vtt'
     })
 
-    await servers[0].captionsCommand.createVideoCaption({
+    await servers[0].captions.add({
       language: 'zh',
       videoId: videoUUID,
       fixture: 'subtitle-good2.vtt',
@@ -69,7 +67,7 @@ describe('Test video captions', function () {
 
   it('Should list these uploaded captions', async function () {
     for (const server of servers) {
-      const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
+      const body = await server.captions.list({ videoId: videoUUID })
       expect(body.total).to.equal(2)
       expect(body.data).to.have.lengthOf(2)
 
@@ -90,7 +88,7 @@ describe('Test video captions', function () {
   it('Should replace an existing caption', async function () {
     this.timeout(30000)
 
-    await servers[0].captionsCommand.createVideoCaption({
+    await servers[0].captions.add({
       language: 'ar',
       videoId: videoUUID,
       fixture: 'subtitle-good2.vtt'
@@ -101,7 +99,7 @@ describe('Test video captions', function () {
 
   it('Should have this caption updated', async function () {
     for (const server of servers) {
-      const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
+      const body = await server.captions.list({ videoId: videoUUID })
       expect(body.total).to.equal(2)
       expect(body.data).to.have.lengthOf(2)
 
@@ -116,7 +114,7 @@ describe('Test video captions', function () {
   it('Should replace an existing caption with a srt file and convert it', async function () {
     this.timeout(30000)
 
-    await servers[0].captionsCommand.createVideoCaption({
+    await servers[0].captions.add({
       language: 'ar',
       videoId: videoUUID,
       fixture: 'subtitle-good.srt'
@@ -130,7 +128,7 @@ describe('Test video captions', function () {
 
   it('Should have this caption updated and converted', async function () {
     for (const server of servers) {
-      const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
+      const body = await server.captions.list({ videoId: videoUUID })
       expect(body.total).to.equal(2)
       expect(body.data).to.have.lengthOf(2)
 
@@ -159,14 +157,14 @@ describe('Test video captions', function () {
   it('Should remove one caption', async function () {
     this.timeout(30000)
 
-    await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' })
+    await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' })
 
     await waitJobs(servers)
   })
 
   it('Should only list the caption that was not deleted', async function () {
     for (const server of servers) {
-      const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID })
+      const body = await server.captions.list({ videoId: videoUUID })
       expect(body.total).to.equal(1)
       expect(body.data).to.have.lengthOf(1)
 
@@ -180,9 +178,12 @@ describe('Test video captions', function () {
   })
 
   it('Should remove the video, and thus all video captions', async function () {
-    await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
+    const video = await servers[0].videos.get({ id: videoUUID })
+    const { data: captions } = await servers[0].captions.list({ videoId: videoUUID })
 
-    await checkVideoFilesWereRemoved(videoUUID, 1)
+    await servers[0].videos.remove({ id: videoUUID })
+
+    await checkVideoFilesWereRemoved({ server: servers[0], video, captions })
   })
 
   after(async function () {