]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/single-pod.js
Server: make a basic "quick and dirty update" for videos
[github/Chocobozzz/PeerTube.git] / server / tests / api / single-pod.js
index 57146900de47cb6994fe85709518c855f2bc29c7..40c33686f6c207c7e6372e53ac4a6add2307ed19 100644 (file)
@@ -83,6 +83,7 @@ describe('Test a single pod', function () {
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
       expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+      expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
       videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
         if (err) throw err
@@ -117,6 +118,7 @@ describe('Test a single pod', function () {
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
       expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+      expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
       videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
         if (err) throw err
@@ -127,6 +129,17 @@ describe('Test a single pod', function () {
     })
   })
 
+  it('Should have the views updated', function (done) {
+    videosUtils.getVideo(server.url, videoId, function (err, res) {
+      if (err) throw err
+
+      const video = res.body
+      expect(video.views).to.equal(1)
+
+      done()
+    })
+  })
+
   it('Should search the video by name by default', function (done) {
     videosUtils.searchVideo(server.url, 'my', function (err, res) {
       if (err) throw err
@@ -143,6 +156,7 @@ describe('Test a single pod', function () {
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
       expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+      expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
       videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
         if (err) throw err
@@ -170,6 +184,7 @@ describe('Test a single pod', function () {
   //     expect(video.isLocal).to.be.true
   //     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
   //     expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+  //     expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
   //     videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
   //       if (err) throw err
@@ -196,6 +211,7 @@ describe('Test a single pod', function () {
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
       expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+      expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
       videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
         if (err) throw err
@@ -246,12 +262,12 @@ describe('Test a single pod', function () {
     videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
       if (err) throw err
 
-      fs.readdir(pathUtils.join(__dirname, '../../../test1/videos/'), function (err, files) {
+      fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) {
         if (err) throw err
 
         expect(files.length).to.equal(0)
 
-        fs.readdir(pathUtils.join(__dirname, '../../../test1/thumbnails/'), function (err, files) {
+        fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) {
           if (err) throw err
 
           expect(files.length).to.equal(0)
@@ -333,69 +349,69 @@ describe('Test a single pod', function () {
   })
 
   it('Should list only the two first videos', function (done) {
-    videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) {
+    videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
       expect(res.body.total).to.equal(6)
       expect(videos.length).to.equal(2)
-      expect(videos[0].name === videosListBase[0].name)
-      expect(videos[1].name === videosListBase[1].name)
+      expect(videos[0].name).to.equal(videosListBase[0].name)
+      expect(videos[1].name).to.equal(videosListBase[1].name)
 
       done()
     })
   })
 
   it('Should list only the next three videos', function (done) {
-    videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) {
+    videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
       expect(res.body.total).to.equal(6)
       expect(videos.length).to.equal(3)
-      expect(videos[0].name === videosListBase[2].name)
-      expect(videos[1].name === videosListBase[3].name)
-      expect(videos[2].name === videosListBase[4].name)
+      expect(videos[0].name).to.equal(videosListBase[2].name)
+      expect(videos[1].name).to.equal(videosListBase[3].name)
+      expect(videos[2].name).to.equal(videosListBase[4].name)
 
       done()
     })
   })
 
   it('Should list the last video', function (done) {
-    videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) {
+    videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
       expect(res.body.total).to.equal(6)
       expect(videos.length).to.equal(1)
-      expect(videos[0].name === videosListBase[5].name)
+      expect(videos[0].name).to.equal(videosListBase[5].name)
 
       done()
     })
   })
 
   it('Should search the first video', function (done) {
-    videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
+    videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
       expect(res.body.total).to.equal(4)
       expect(videos.length).to.equal(1)
-      expect(videos[0].name === 'video_short.webm name')
+      expect(videos[0].name).to.equal('video_short1.webm name')
 
       done()
     })
   })
 
   it('Should search the last two videos', function (done) {
-    videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
+    videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
       expect(res.body.total).to.equal(4)
       expect(videos.length).to.equal(2)
-      expect(videos[0].name === 'video_short2.webm name')
-      expect(videos[1].name === 'video_short3.webm name')
+      expect(videos[0].name).to.equal('video_short3.webm name')
+      expect(videos[1].name).to.equal('video_short.webm name')
 
       done()
     })
@@ -471,12 +487,12 @@ describe('Test a single pod', function () {
       const videos = res.body.data
       expect(res.body.total).to.equal(6)
       expect(videos.length).to.equal(6)
-      expect(videos[5].name === 'video_short.mp4 name')
-      expect(videos[4].name === 'video_short.ogv name')
-      expect(videos[3].name === 'video_short.webm name')
-      expect(videos[2].name === 'video_short1.webm name')
-      expect(videos[1].name === 'video_short2.webm name')
-      expect(videos[0].name === 'video_short3.webm name')
+      expect(videos[0].name).to.equal('video_short.webm name')
+      expect(videos[1].name).to.equal('video_short.ogv name')
+      expect(videos[2].name).to.equal('video_short.mp4 name')
+      expect(videos[3].name).to.equal('video_short3.webm name')
+      expect(videos[4].name).to.equal('video_short2.webm name')
+      expect(videos[5].name).to.equal('video_short1.webm name')
 
       done()
     })
@@ -490,12 +506,12 @@ describe('Test a single pod', function () {
       expect(res.body.total).to.equal(4)
       expect(videos.length).to.equal(4)
 
-      expect(videos[0].name === 'video_short.webm name')
-      expect(videos[1].name === 'video_short1.webm name')
-      expect(videos[2].name === 'video_short2.webm name')
-      expect(videos[3].name === 'video_short3.webm name')
+      expect(videos[0].name).to.equal('video_short1.webm name')
+      expect(videos[1].name).to.equal('video_short2.webm name')
+      expect(videos[2].name).to.equal('video_short3.webm name')
+      expect(videos[3].name).to.equal('video_short.webm name')
 
-      videoId = videos[3].id
+      videoId = videos[2].id
 
       done()
     })
@@ -510,6 +526,8 @@ describe('Test a single pod', function () {
   })
 
   it('Should have the video updated', function (done) {
+    this.timeout(60000)
+
     videosUtils.getVideo(server.url, videoId, function (err, res) {
       if (err) throw err
 
@@ -522,8 +540,20 @@ describe('Test a single pod', function () {
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
       expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+      expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
-      done()
+      videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
+        if (err) throw err
+        expect(test).to.equal(true)
+
+        webtorrent.add(video.magnetUri, function (torrent) {
+          expect(torrent.files).to.exist
+          expect(torrent.files.length).to.equal(1)
+          expect(torrent.files[0].path).to.exist.and.to.not.equal('')
+
+          done()
+        })
+      })
     })
   })
 
@@ -545,6 +575,7 @@ describe('Test a single pod', function () {
         expect(video.isLocal).to.be.true
         expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
         expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+        expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
         done()
       })
@@ -569,6 +600,7 @@ describe('Test a single pod', function () {
         expect(video.isLocal).to.be.true
         expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
         expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
+        expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
 
         done()
       })