]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/friends-basic.js
Begin user quota
[github/Chocobozzz/PeerTube.git] / server / tests / api / friends-basic.js
index f1393b5ec78dac8d71b4382660e1837a3ce74e58..5f1fdd255d728104db58d2fa433886baf20d2662 100644 (file)
@@ -1,3 +1,5 @@
+/* eslint-disable no-unused-expressions */
+
 'use strict'
 
 const chai = require('chai')
@@ -22,22 +24,22 @@ describe('Test basic friends', function () {
     const friends = []
     for (let i = 0; i < servers.length; i++) {
       if (servers[i].url === serverToTest.url) continue
-      friends.push(servers[i].url)
+      friends.push(servers[i].host)
     }
 
     podsUtils.getFriendsList(serverToTest.url, function (err, res) {
       if (err) throw err
 
-      const result = res.body
+      const result = res.body.data
       expect(result).to.be.an('array')
       expect(result.length).to.equal(2)
 
-      const resultUrls = [ result[0].url, result[1].url ]
-      expect(resultUrls[0]).to.not.equal(resultUrls[1])
+      const resultHosts = [ result[0].host, result[1].host ]
+      expect(resultHosts[0]).to.not.equal(resultHosts[1])
 
-      const errorString = 'Friends url do not correspond for ' + serverToTest.url
-      expect(friends).to.contain(resultUrls[0], errorString)
-      expect(friends).to.contain(resultUrls[1], errorString)
+      const errorString = 'Friends host do not correspond for ' + serverToTest.host
+      expect(friends).to.contain(resultHosts[0], errorString)
+      expect(friends).to.contain(resultHosts[1], errorString)
       callback()
     })
   }
@@ -45,7 +47,7 @@ describe('Test basic friends', function () {
   // ---------------------------------------------------------------
 
   before(function (done) {
-    this.timeout(20000)
+    this.timeout(120000)
     serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
       servers = serversRun
 
@@ -65,7 +67,7 @@ describe('Test basic friends', function () {
       podsUtils.getFriendsList(server.url, function (err, res) {
         if (err) throw err
 
-        const result = res.body
+        const result = res.body.data
         expect(result).to.be.an('array')
         expect(result.length).to.equal(0)
         callback()
@@ -74,7 +76,7 @@ describe('Test basic friends', function () {
   })
 
   it('Should make friends', function (done) {
-    this.timeout(40000)
+    this.timeout(120000)
 
     series([
       // The second pod make friend with the third
@@ -90,14 +92,15 @@ describe('Test basic friends', function () {
         podsUtils.getFriendsList(servers[1].url, function (err, res) {
           if (err) throw err
 
-          const result = res.body
+          const result = res.body.data
           expect(result).to.be.an('array')
           expect(result.length).to.equal(1)
 
           const pod = result[0]
-          expect(pod.url).to.equal(servers[2].url)
+          expect(pod.host).to.equal(servers[2].host)
+          expect(pod.email).to.equal('admin3@example.com')
           expect(pod.score).to.equal(20)
-          expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
+          expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
 
           next()
         })
@@ -107,14 +110,15 @@ describe('Test basic friends', function () {
         podsUtils.getFriendsList(servers[2].url, function (err, res) {
           if (err) throw err
 
-          const result = res.body
+          const result = res.body.data
           expect(result).to.be.an('array')
           expect(result.length).to.equal(1)
 
           const pod = result[0]
-          expect(pod.url).to.equal(servers[1].url)
+          expect(pod.host).to.equal(servers[1].host)
+          expect(pod.email).to.equal('admin2@example.com')
           expect(pod.score).to.equal(20)
-          expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
+          expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
 
           next()
         })
@@ -138,11 +142,14 @@ describe('Test basic friends', function () {
   })
 
   it('Should not be allowed to make friend again', function (done) {
+    this.timeout(10000)
     const server = servers[1]
     podsUtils.makeFriends(server.url, server.accessToken, 409, done)
   })
 
   it('Should quit friends of pod 2', function (done) {
+    this.timeout(10000)
+
     series([
       // Pod 1 quit friends
       function (next) {
@@ -154,7 +161,7 @@ describe('Test basic friends', function () {
         podsUtils.getFriendsList(servers[1].url, function (err, res) {
           if (err) throw err
 
-          const result = res.body
+          const result = res.body.data
           expect(result).to.be.an('array')
           expect(result.length).to.equal(0)
 
@@ -167,10 +174,10 @@ describe('Test basic friends', function () {
           podsUtils.getFriendsList(url, function (err, res) {
             if (err) throw err
 
-            const result = res.body
+            const result = res.body.data
             expect(result).to.be.an('array')
             expect(result.length).to.equal(1)
-            expect(result[0].url).not.to.be.equal(servers[1].url)
+            expect(result[0].host).not.to.be.equal(servers[1].host)
             callback()
           })
         }, next)
@@ -179,7 +186,7 @@ describe('Test basic friends', function () {
   })
 
   it('Should allow pod 2 to make friend again', function (done) {
-    this.timeout(20000)
+    this.timeout(120000)
 
     const server = servers[1]
     podsUtils.makeFriends(server.url, server.accessToken, function () {
@@ -191,6 +198,71 @@ describe('Test basic friends', function () {
     })
   })
 
+  it('Should allow pod 1 to quit only pod 2', function (done) {
+    series([
+      // Pod 1 quits pod 2
+      function (next) {
+        const server = servers[0]
+
+        // Get pod 2 id so we can query it
+        podsUtils.getFriendsList(server.url, function (err, res) {
+          if (err) throw err
+
+          const result = res.body.data
+          let pod = result.find((friend) => (friend.host === servers[1].host))
+
+          // Remove it from the friends list
+          podsUtils.quitOneFriend(server.url, server.accessToken, pod.id, next)
+        })
+      },
+
+      // Pod 1 should have only pod 3 in its friends list
+      function (next) {
+        podsUtils.getFriendsList(servers[0].url, function (err, res) {
+          if (err) throw err
+
+          const result = res.body.data
+          expect(result).to.be.an('array')
+          expect(result.length).to.equal(1)
+
+          const pod = result[0]
+          expect(pod.host).to.equal(servers[2].host)
+
+          next()
+        })
+      },
+
+      // Pod 2 should have only pod 3 in its friends list
+      function (next) {
+        podsUtils.getFriendsList(servers[1].url, function (err, res) {
+          if (err) throw err
+
+          const result = res.body.data
+          expect(result).to.be.an('array')
+          expect(result.length).to.equal(1)
+
+          const pod = result[0]
+          expect(pod.host).to.equal(servers[2].host)
+
+          next()
+        })
+      },
+
+      // Pod 3 should have both pods in its friends list
+      function (next) {
+        podsUtils.getFriendsList(servers[2].url, function (err, res) {
+          if (err) throw err
+
+          const result = res.body.data
+          expect(result).to.be.an('array')
+          expect(result.length).to.equal(2)
+
+          next()
+        })
+      }
+    ], done)
+  })
+
   after(function (done) {
     servers.forEach(function (server) {
       process.kill(-server.app.pid)