Antonio-Maranhao closed pull request #1095: Fix - Create replication fails when 
db doesn't exist
URL: https://github.com/apache/couchdb-fauxton/pull/1095
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/replication/__tests__/actions.test.js 
b/app/addons/replication/__tests__/actions.test.js
index 929a2c77b..b8ccf124d 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 08e073333..a2ba1e9e0 100644
--- a/app/addons/replication/actions.js
+++ b/app/addons/replication/actions.js
@@ -69,7 +69,8 @@ export const replicate = (params) => dispatch => {
     });
   };
 
-  promise
+  // Return promise for testing
+  return promise
     .then(json => {
       if (!json.ok) {
         throw json;
@@ -83,11 +84,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);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to