Server: add tests for video blacklists
authorChocobozzz <florian.bigard@gmail.com>
Mon, 1 May 2017 17:04:29 +0000 (19:04 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 1 May 2017 17:04:29 +0000 (19:04 +0200)
server/tests/api/check-params/index.js
server/tests/api/check-params/video-abuses.js
server/tests/api/check-params/video-blacklists.js [new file with mode: 0644]
server/tests/api/index.js
server/tests/api/video-abuse.js
server/tests/api/video-blacklist.js [new file with mode: 0644]
server/tests/utils/video-abuses.js
server/tests/utils/video-blacklists.js [new file with mode: 0644]

index d0824f08a7926c892feb7e3612b83de25f4b7226..527ab65a9a8c37d3cfbccbcbb23e45c8a311a035 100644 (file)
@@ -7,3 +7,4 @@ require('./users')
 require('./requests')
 require('./videos')
 require('./video-abuses')
+require('./video-blacklists')
index 6dc5a70905a07544096ef31ed4dab7d8f09fd3d2..8c520aab4a13c8b0473f976afa83cd05fe93b2a6 100644 (file)
@@ -129,7 +129,7 @@ describe('Test video abuses API validators', function () {
     const basePath = '/api/v1/videos/'
 
     it('Should fail with nothing', function (done) {
-      const path = basePath + server.video + '/abuse'
+      const path = basePath + server.video.id + '/abuse'
       const data = {}
       requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
     })
@@ -142,7 +142,7 @@ describe('Test video abuses API validators', function () {
 
     it('Should fail with a non authenticated user', function (done) {
       const data = {}
-      const path = basePath + server.video + '/abuse'
+      const path = basePath + server.video.id + '/abuse'
       requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
     })
 
@@ -150,7 +150,7 @@ describe('Test video abuses API validators', function () {
       const data = {
         reason: 'h'
       }
-      const path = basePath + server.video + '/abuse'
+      const path = basePath + server.video.id + '/abuse'
       requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
     })
 
@@ -161,7 +161,7 @@ describe('Test video abuses API validators', function () {
                 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
                 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
       }
-      const path = basePath + server.video + '/abuse'
+      const path = basePath + server.video.id + '/abuse'
       requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
     })
   })
diff --git a/server/tests/api/check-params/video-blacklists.js b/server/tests/api/check-params/video-blacklists.js
new file mode 100644 (file)
index 0000000..a39ab0c
--- /dev/null
@@ -0,0 +1,123 @@
+/* eslint-disable no-unused-expressions */
+
+'use strict'
+
+const series = require('async/series')
+
+const loginUtils = require('../../utils/login')
+const requestsUtils = require('../../utils/requests')
+const serversUtils = require('../../utils/servers')
+const usersUtils = require('../../utils/users')
+const videosUtils = require('../../utils/videos')
+
+describe('Test video blacklists API validators', function () {
+  let server = null
+  let userAccessToken = null
+
+  // ---------------------------------------------------------------
+
+  before(function (done) {
+    this.timeout(20000)
+
+    series([
+      function (next) {
+        serversUtils.flushTests(next)
+      },
+      function (next) {
+        serversUtils.runServer(1, function (server1) {
+          server = server1
+
+          next()
+        })
+      },
+      function (next) {
+        loginUtils.loginAndGetAccessToken(server, function (err, token) {
+          if (err) throw err
+          server.accessToken = token
+
+          next()
+        })
+      },
+      function (next) {
+        const username = 'user1'
+        const password = 'my super password'
+
+        usersUtils.createUser(server.url, server.accessToken, username, password, next)
+      },
+      function (next) {
+        const user = {
+          username: 'user1',
+          password: 'my super password'
+        }
+
+        loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
+          if (err) throw err
+
+          userAccessToken = accessToken
+
+          next()
+        })
+      },
+      // Upload a video
+      function (next) {
+        const videoAttributes = {}
+        videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
+      },
+      function (next) {
+        videosUtils.getVideosList(server.url, function (err, res) {
+          if (err) throw err
+
+          const videos = res.body.data
+          server.video = videos[0]
+
+          next()
+        })
+      }
+    ], done)
+  })
+
+  describe('When adding a video in blacklist', function () {
+    const basePath = '/api/v1/videos/'
+
+    it('Should fail with nothing', function (done) {
+      const path = basePath + server.video + '/blacklist'
+      const data = {}
+      requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
+    })
+
+    it('Should fail with a wrong video', function (done) {
+      const wrongPath = '/api/v1/videos/blabla/blacklist'
+      const data = {}
+      requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
+    })
+
+    it('Should fail with a non authenticated user', function (done) {
+      const data = {}
+      const path = basePath + server.video + '/blacklist'
+      requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
+    })
+
+    it('Should fail with a non admin user', function (done) {
+      const data = {}
+      const path = basePath + server.video + '/blacklist'
+      requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403)
+    })
+
+    it('Should fail with a local video', function (done) {
+      const data = {}
+      const path = basePath + server.video.id + '/blacklist'
+      requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 403)
+    })
+  })
+
+  after(function (done) {
+    process.kill(-server.app.pid)
+
+    // Keep the logs if the test failed
+    if (this.ok) {
+      serversUtils.flushTests(done)
+    } else {
+      done()
+    }
+  })
+})
index fcd12617ef55f46e4a5cd44f3794520fcec2313e..7ae18f674a6c2a161b267c93980dda9b89d9631b 100644 (file)
@@ -6,6 +6,8 @@ require('./check-params')
 require('./friends-basic')
 require('./users')
 require('./single-pod')
+require('./video-abuse')
+require('./video-blacklist')
 require('./multiple-pods')
 require('./requests')
 require('./friends-advanced')
index 7db067585ef374eb8cb1cc83b395ee64f29665e8..1f64ec861ff3a9ce217daec0b56dfd93202b44f4 100644 (file)
@@ -38,7 +38,7 @@ describe('Test video abuses', function () {
           })
         }, next)
       },
-      // Pod 1 make friends too
+      // Pod 1 makes friend with pod 2
       function (next) {
         const server = servers[0]
         podsUtils.makeFriends(server.url, server.accessToken, next)
diff --git a/server/tests/api/video-blacklist.js b/server/tests/api/video-blacklist.js
new file mode 100644 (file)
index 0000000..c95fc17
--- /dev/null
@@ -0,0 +1,138 @@
+/* eslint-disable no-unused-expressions */
+
+'use strict'
+
+const chai = require('chai')
+const each = require('async/each')
+const expect = chai.expect
+const series = require('async/series')
+
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
+const videosUtils = require('../utils/videos')
+const videoBlacklistsUtils = require('../utils/video-blacklists')
+
+describe('Test video blacklists', function () {
+  let servers = []
+
+  before(function (done) {
+    this.timeout(30000)
+
+    series([
+      // Run servers
+      function (next) {
+        serversUtils.flushAndRunMultipleServers(2, function (serversRun) {
+          servers = serversRun
+          next()
+        })
+      },
+      // Get the access tokens
+      function (next) {
+        each(servers, function (server, callbackEach) {
+          loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
+            if (err) return callbackEach(err)
+
+            server.accessToken = accessToken
+            callbackEach()
+          })
+        }, next)
+      },
+      // Pod 1 makes friend with pod 2
+      function (next) {
+        const server = servers[0]
+        podsUtils.makeFriends(server.url, server.accessToken, next)
+      },
+      // Upload a video on pod 2
+      function (next) {
+        const videoAttributes = {
+          name: 'my super name for pod 2',
+          description: 'my super description for pod 2'
+        }
+        videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
+      },
+      // Wait videos propagation
+      function (next) {
+        setTimeout(next, 11000)
+      },
+      function (next) {
+        videosUtils.getVideosList(servers[0].url, function (err, res) {
+          if (err) throw err
+
+          const videos = res.body.data
+
+          expect(videos.length).to.equal(1)
+
+          servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' })
+
+          next()
+        })
+      }
+    ], done)
+  })
+
+  it('Should blacklist a remote video on pod 1', function (done) {
+    videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done)
+  })
+
+  it('Should not have the video blacklisted in videos list on pod 1', function (done) {
+    videosUtils.getVideosList(servers[0].url, function (err, res) {
+      if (err) throw err
+
+      expect(res.body.total).to.equal(0)
+      expect(res.body.data).to.be.an('array')
+      expect(res.body.data.length).to.equal(0)
+
+      done()
+    })
+  })
+
+  it('Should not have the video blacklisted in videos search on pod 1', function (done) {
+    videosUtils.searchVideo(servers[0].url, 'name', function (err, res) {
+      if (err) throw err
+
+      expect(res.body.total).to.equal(0)
+      expect(res.body.data).to.be.an('array')
+      expect(res.body.data.length).to.equal(0)
+
+      done()
+    })
+  })
+
+  it('Should have the blacklisted video in videos list on pod 2', function (done) {
+    videosUtils.getVideosList(servers[1].url, function (err, res) {
+      if (err) throw err
+
+      expect(res.body.total).to.equal(1)
+      expect(res.body.data).to.be.an('array')
+      expect(res.body.data.length).to.equal(1)
+
+      done()
+    })
+  })
+
+  it('Should have the video blacklisted in videos search on pod 2', function (done) {
+    videosUtils.searchVideo(servers[1].url, 'name', function (err, res) {
+      if (err) throw err
+
+      expect(res.body.total).to.equal(1)
+      expect(res.body.data).to.be.an('array')
+      expect(res.body.data.length).to.equal(1)
+
+      done()
+    })
+  })
+
+  after(function (done) {
+    servers.forEach(function (server) {
+      process.kill(-server.app.pid)
+    })
+
+    // Keep the logs if the test failed
+    if (this.ok) {
+      serversUtils.flushTests(done)
+    } else {
+      done()
+    }
+  })
+})
index 596c824b321c097d44e0d7acba28037616797b44..c4dd879902d3dd95afb72ac74979e93c339453a7 100644 (file)
@@ -2,7 +2,7 @@
 
 const request = require('supertest')
 
-const videosUtils = {
+const videosAbuseUtils = {
   getVideoAbusesList,
   getVideoAbusesListPagination,
   getVideoAbusesListSort,
@@ -70,4 +70,4 @@ function getVideoAbusesListSort (url, token, sort, end) {
 
 // ---------------------------------------------------------------------------
 
-module.exports = videosUtils
+module.exports = videosAbuseUtils
diff --git a/server/tests/utils/video-blacklists.js b/server/tests/utils/video-blacklists.js
new file mode 100644 (file)
index 0000000..0a58dd6
--- /dev/null
@@ -0,0 +1,29 @@
+'use strict'
+
+const request = require('supertest')
+
+const videosBlacklistsUtils = {
+  addVideoToBlacklist
+}
+
+// ---------------------- Export functions --------------------
+
+function addVideoToBlacklist (url, token, videoId, specialStatus, end) {
+  if (!end) {
+    end = specialStatus
+    specialStatus = 204
+  }
+
+  const path = '/api/v1/videos/' + videoId + '/blacklist'
+
+  request(url)
+    .post(path)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + token)
+    .expect(specialStatus)
+    .end(end)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = videosBlacklistsUtils