Add tests for thumbnails
authorChocobozzz <florian.bigard@gmail.com>
Tue, 10 May 2016 19:55:59 +0000 (21:55 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 10 May 2016 19:56:16 +0000 (21:56 +0200)
server/tests/api/fixtures/video_short.mp4.jpg [new file with mode: 0644]
server/tests/api/fixtures/video_short.ogv.jpg [new file with mode: 0644]
server/tests/api/fixtures/video_short.webm.jpg [new file with mode: 0644]
server/tests/api/fixtures/video_short1.webm.jpg [new file with mode: 0644]
server/tests/api/fixtures/video_short2.webm.jpg [new file with mode: 0644]
server/tests/api/fixtures/video_short3.webm.jpg [new file with mode: 0644]
server/tests/api/multiplePods.js
server/tests/api/singlePod.js
server/tests/api/utils.js

diff --git a/server/tests/api/fixtures/video_short.mp4.jpg b/server/tests/api/fixtures/video_short.mp4.jpg
new file mode 100644 (file)
index 0000000..48790ff
Binary files /dev/null and b/server/tests/api/fixtures/video_short.mp4.jpg differ
diff --git a/server/tests/api/fixtures/video_short.ogv.jpg b/server/tests/api/fixtures/video_short.ogv.jpg
new file mode 100644 (file)
index 0000000..c4c1d00
Binary files /dev/null and b/server/tests/api/fixtures/video_short.ogv.jpg differ
diff --git a/server/tests/api/fixtures/video_short.webm.jpg b/server/tests/api/fixtures/video_short.webm.jpg
new file mode 100644 (file)
index 0000000..b0dffd0
Binary files /dev/null and b/server/tests/api/fixtures/video_short.webm.jpg differ
diff --git a/server/tests/api/fixtures/video_short1.webm.jpg b/server/tests/api/fixtures/video_short1.webm.jpg
new file mode 100644 (file)
index 0000000..2db2197
Binary files /dev/null and b/server/tests/api/fixtures/video_short1.webm.jpg differ
diff --git a/server/tests/api/fixtures/video_short2.webm.jpg b/server/tests/api/fixtures/video_short2.webm.jpg
new file mode 100644 (file)
index 0000000..ed5952e
Binary files /dev/null and b/server/tests/api/fixtures/video_short2.webm.jpg differ
diff --git a/server/tests/api/fixtures/video_short3.webm.jpg b/server/tests/api/fixtures/video_short3.webm.jpg
new file mode 100644 (file)
index 0000000..b7c41cc
Binary files /dev/null and b/server/tests/api/fixtures/video_short3.webm.jpg differ
index 4a4532a0fc4cd04739bb0be738f4306da16d0df9..c19f120ef0b8feca110626294521675322947474 100644 (file)
@@ -110,7 +110,12 @@ describe('Test multiple pods', function () {
                 expect(video.magnetUri).to.equal.magnetUri
               }
 
-              callback()
+              utils.testImage(server.url, 'video_short1.webm', video.thumbnail_path, function (err, test) {
+                if (err) throw err
+                expect(test).to.equal(true)
+
+                callback()
+              })
             })
           }, done)
         }
@@ -160,7 +165,12 @@ describe('Test multiple pods', function () {
                 expect(video.magnetUri).to.equal.magnetUri
               }
 
-              callback()
+              utils.testImage(server.url, 'video_short2.webm', video.thumbnail_path, function (err, test) {
+                if (err) throw err
+                expect(test).to.equal(true)
+
+                callback()
+              })
             })
           }, done)
         }
@@ -231,7 +241,17 @@ describe('Test multiple pods', function () {
                 expect(video2.magnetUri).to.equal.magnetUri
               }
 
-              callback()
+              utils.testImage(server.url, 'video_short3.webm', video1.thumbnail_path, function (err, test) {
+                if (err) throw err
+                expect(test).to.equal(true)
+
+                utils.testImage(server.url, 'video_short.webm', video2.thumbnail_path, function (err, test) {
+                  if (err) throw err
+                  expect(test).to.equal(true)
+
+                  callback()
+                })
+              })
             })
           }, done)
         }
index e2999530eab334b5f5918ccc404ea5502467ac23..9a9af0901676a8884a4af63680a79fed5a6fef78 100644 (file)
@@ -76,14 +76,19 @@ describe('Test a single pod', function () {
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
 
-      video_id = video.id
+      utils.testImage(server.url, 'video_short.webm', video.thumbnail_path, 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('')
+        video_id = video.id
 
-        done()
+        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()
+        })
       })
     })
   })
@@ -103,12 +108,17 @@ describe('Test a single pod', function () {
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.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('')
+      utils.testImage(server.url, 'video_short.webm', video.thumbnail_path, function (err, test) {
+        if (err) throw err
+        expect(test).to.equal(true)
 
-        done()
+        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()
+        })
       })
     })
   })
@@ -127,7 +137,12 @@ describe('Test a single pod', function () {
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
 
-      done()
+      utils.testImage(server.url, 'video_short.webm', video.thumbnail_path, function (err, test) {
+        if (err) throw err
+        expect(test).to.equal(true)
+
+        done()
+      })
     })
   })
 
@@ -197,6 +212,24 @@ describe('Test a single pod', function () {
     })
   })
 
+  it('Should have the correct thumbnails', function (done) {
+    utils.getVideosList(server.url, function (err, res) {
+      const videos = res.body
+
+      async.each(videos, function (video, callback_each) {
+        if (err) throw err
+        const video_name = video.name.replace(' name', '')
+
+        utils.testImage(server.url, video_name, video.thumbnail_path, function (err, test) {
+          if (err) throw err
+
+          expect(test).to.equal(true)
+          callback_each()
+        })
+      }, done)
+    })
+  })
+
   after(function (done) {
     process.kill(-server.app.pid)
     process.kill(-webtorrent.app.pid)
index c1a01ef372252ca22e069bc672079f48f47268d6..3d3169fde50ee742e9b7ab185cfbd47c504d0f5e 100644 (file)
@@ -3,6 +3,7 @@
 const child_process = require('child_process')
 const exec = child_process.exec
 const fork = child_process.fork
+const fs = require('fs')
 const pathUtils = require('path')
 const request = require('supertest')
 
@@ -19,6 +20,7 @@ const testUtils = {
   flushAndRunMultipleServers: flushAndRunMultipleServers,
   runServer: runServer,
   searchVideo: searchVideo,
+  testImage: testImage,
   uploadVideo: uploadVideo
 }
 
@@ -252,6 +254,21 @@ function searchVideo (url, search, end) {
     .end(end)
 }
 
+function testImage (url, video_name, image_path, callback) {
+  request(url)
+    .get(image_path)
+    .expect(200)
+    .end(function (err, res) {
+      if (err) return callback(err)
+
+      fs.readFile(pathUtils.join(__dirname, 'fixtures', video_name + '.jpg'), function (err, data) {
+        if (err) return callback(err)
+
+        callback(null, data.equals(res.body))
+      })
+    })
+}
+
 function uploadVideo (url, access_token, name, description, fixture, special_status, end) {
   if (!end) {
     end = special_status