couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amaran...@apache.org
Subject [couchdb-fauxton] branch master updated: Fix - Create replication fails when db doesn't exist (#1095)
Date Wed, 27 Jun 2018 18:11:24 GMT
This is an automated email from the ASF dual-hosted git repository.

amaranhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new d1ba78a  Fix - Create replication fails when db doesn't exist (#1095)
d1ba78a is described below

commit d1ba78a80489b388856bb18bcda76674eae8d19c
Author: Antonio Maranhao <30349380+Antonio-Maranhao@users.noreply.github.com>
AuthorDate: Wed Jun 27 14:11:22 2018 -0400

    Fix - Create replication fails when db doesn't exist (#1095)
---
 app/addons/replication/__tests__/actions.test.js | 37 +++++++++++++++++++-----
 app/addons/replication/actions.js                |  9 +++---
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/app/addons/replication/__tests__/actions.test.js b/app/addons/replication/__tests__/actions.test.js
index 36646a7..0e5f3b6 100644
--- a/app/addons/replication/__tests__/actions.test.js
+++ b/app/addons/replication/__tests__/actions.test.js
@@ -35,7 +35,7 @@ describe("Replication Actions", () => {
   describe('replicate', () => {
     afterEach(fetchMock.restore);
 
-    it('creates a new database if it does not exist', (done) => {
+    it('creates a new database if it does not exist', () => {
       const dispatch = () => {};
       fetchMock.postOnce('./_replicator', {
         status: 404,
@@ -59,7 +59,7 @@ describe("Replication Actions", () => {
         }
       });
 
-      replicate ({
+      return replicate ({
         localSource: "animaldb",
         localTarget: "boom123",
         password: "testerpass",
@@ -70,13 +70,34 @@ describe("Replication Actions", () => {
         replicationTarget: "REPLICATION_TARGET_NEW_LOCAL_DATABASE",
         replicationType: "",
         username: "tester"
-      })(dispatch);
+      })(dispatch).then(() => {
+        assert.lengthOf(finalPost.calls('./_replicator'), 3);
+      });
+    });
+
+    it('does not try to create new database if it already exist', () => {
+      const dispatch = () => {};
+      const mockPost = fetchMock.postOnce('./_replicator', {
+        status: 200,
+        body: {
+          ok: true
+        }
+      });
 
-      //this is not pretty, and might cause some false errors. But its tricky to tell when
this test has completed
-      setTimeout(() => {
-        assert.ok(finalPost.called('./_replicator'));
-        done();
-      }, 100);
+      return replicate ({
+        localSource: "animaldb",
+        localTarget: "boom123",
+        password: "testerpass",
+        remoteSource: "",
+        remoteTarget: "",
+        replicationDocName: "",
+        replicationSource: "REPLICATION_SOURCE_LOCAL",
+        replicationTarget: "REPLICATION_TARGET_NEW_LOCAL_DATABASE",
+        replicationType: "",
+        username: "tester"
+      })(dispatch).then(() => {
+        assert.lengthOf(mockPost.calls('./_replicator'), 1);
+      });
     });
   });
 
diff --git a/app/addons/replication/actions.js b/app/addons/replication/actions.js
index a1d2d3d..724a041 100644
--- a/app/addons/replication/actions.js
+++ b/app/addons/replication/actions.js
@@ -71,7 +71,8 @@ export const replicate = (params) => dispatch => {
     });
   };
 
-  promise
+  // Return promise for testing
+  return promise
     .then(json => {
       if (!json.ok) {
         throw json;
@@ -85,11 +86,11 @@ export const replicate = (params) => dispatch => {
       });
 
       dispatch(getReplicationActivity());
-    })
-    .catch(json => {
+      FauxtonAPI.navigate('#/replication');
+    }).catch(json => {
       if (json.error && json.error === "not_found") {
         return createReplicatorDB().then(() => {
-          return replicate(params);
+          return replicate(params)(dispatch);
         }).catch(handleError);
       }
       handleError(json);


Mime
View raw message