]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/friendsBasic.js
Server: delete user with the id and not the username
[github/Chocobozzz/PeerTube.git] / server / tests / api / friendsBasic.js
index c9e3bc9adad06a74cbe7be70af5a2a7e5271de46..2a6883acb3c894f592dfc744abfbef445459940b 100644 (file)
@@ -1,15 +1,22 @@
 'use strict'
 
-const async = require('async')
 const chai = require('chai')
+const each = require('async/each')
 const expect = chai.expect
-const request = require('supertest')
+const series = require('async/series')
 
-const utils = require('./utils')
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
 
 describe('Test basic friends', function () {
   let servers = []
 
+  function makeFriends (podNumber, callback) {
+    const server = servers[podNumber - 1]
+    return podsUtils.makeFriends(server.url, server.accessToken, callback)
+  }
+
   function testMadeFriends (servers, serverToTest, callback) {
     const friends = []
     for (let i = 0; i < servers.length; i++) {
@@ -17,13 +24,14 @@ describe('Test basic friends', function () {
       friends.push(servers[i].url)
     }
 
-    utils.getFriendsList(serverToTest.url, function (err, res) {
+    podsUtils.getFriendsList(serverToTest.url, function (err, res) {
       if (err) throw err
 
       const result = res.body
-      const resultUrls = [ result[0].url, result[1].url ]
       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 errorString = 'Friends url do not correspond for ' + serverToTest.url
@@ -37,15 +45,23 @@ describe('Test basic friends', function () {
 
   before(function (done) {
     this.timeout(20000)
-    utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
+    serversUtils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
       servers = serversRun
-      done()
+
+      each(servers, function (server, callbackEach) {
+        loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
+          if (err) return callbackEach(err)
+
+          server.accessToken = accessToken
+          callbackEach()
+        })
+      }, done)
     })
   })
 
   it('Should not have friends', function (done) {
-    async.each(servers, function (server, callback) {
-      utils.getFriendsList(server.url, function (err, res) {
+    each(servers, function (server, callback) {
+      podsUtils.getFriendsList(server.url, function (err, res) {
         if (err) throw err
 
         const result = res.body
@@ -59,16 +75,10 @@ describe('Test basic friends', function () {
   it('Should make friends', function (done) {
     this.timeout(10000)
 
-    const path = '/api/v1/pods/makefriends'
-
-    async.series([
+    series([
       // The second pod make friend with the third
       function (next) {
-        request(servers[1].url)
-          .get(path)
-          .set('Accept', 'application/json')
-          .expect(204)
-          .end(next)
+        makeFriends(2, next)
       },
       // Wait for the request between pods
       function (next) {
@@ -76,7 +86,7 @@ describe('Test basic friends', function () {
       },
       // The second pod should have the third as a friend
       function (next) {
-        utils.getFriendsList(servers[1].url, function (err, res) {
+        podsUtils.getFriendsList(servers[1].url, function (err, res) {
           if (err) throw err
 
           const result = res.body
@@ -89,7 +99,7 @@ describe('Test basic friends', function () {
       },
       // Same here, the third pod should have the second pod as a friend
       function (next) {
-        utils.getFriendsList(servers[2].url, function (err, res) {
+        podsUtils.getFriendsList(servers[2].url, function (err, res) {
           if (err) throw err
 
           const result = res.body
@@ -102,11 +112,7 @@ describe('Test basic friends', function () {
       },
       // Finally the first pod make friend with the second pod
       function (next) {
-        request(servers[0].url)
-          .get(path)
-          .set('Accept', 'application/json')
-          .expect(204)
-          .end(next)
+        makeFriends(1, next)
       },
       // Wait for the request between pods
       function (next) {
@@ -116,25 +122,27 @@ describe('Test basic friends', function () {
     // Now each pod should be friend with the other ones
     function (err) {
       if (err) throw err
-      async.each(servers, function (server, callback) {
+      each(servers, function (server, callback) {
         testMadeFriends(servers, server, callback)
       }, done)
     })
   })
 
   it('Should not be allowed to make friend again', function (done) {
-    utils.makeFriends(servers[1].url, 409, done)
+    const server = servers[1]
+    podsUtils.makeFriends(server.url, server.accessToken, 409, done)
   })
 
   it('Should quit friends of pod 2', function (done) {
-    async.series([
+    series([
       // Pod 1 quit friends
       function (next) {
-        utils.quitFriends(servers[1].url, next)
+        const server = servers[1]
+        podsUtils.quitFriends(server.url, server.accessToken, next)
       },
       // Pod 1 should not have friends anymore
       function (next) {
-        utils.getFriendsList(servers[1].url, function (err, res) {
+        podsUtils.getFriendsList(servers[1].url, function (err, res) {
           if (err) throw err
 
           const result = res.body
@@ -146,8 +154,8 @@ describe('Test basic friends', function () {
       },
       // Other pods shouldn't have pod 1 too
       function (next) {
-        async.each([ servers[0].url, servers[2].url ], function (url, callback) {
-          utils.getFriendsList(url, function (err, res) {
+        each([ servers[0].url, servers[2].url ], function (url, callback) {
+          podsUtils.getFriendsList(url, function (err, res) {
             if (err) throw err
 
             const result = res.body
@@ -162,8 +170,9 @@ describe('Test basic friends', function () {
   })
 
   it('Should allow pod 2 to make friend again', function (done) {
-    utils.makeFriends(servers[1].url, function () {
-      async.each(servers, function (server, callback) {
+    const server = servers[1]
+    podsUtils.makeFriends(server.url, server.accessToken, function () {
+      each(servers, function (server, callback) {
         testMadeFriends(servers, server, callback)
       }, done)
     })
@@ -175,7 +184,7 @@ describe('Test basic friends', function () {
     })
 
     if (this.ok) {
-      utils.flushTests(done)
+      serversUtils.flushTests(done)
     } else {
       done()
     }