Fix - Create replication fails when db doesn't exist (#1095)

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('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 @@
         }
       });
 
-      replicate ({
+      return replicate ({
         localSource: "animaldb",
         localTarget: "boom123",
         password: "testerpass",
@@ -70,13 +70,34 @@
         replicationTarget: "REPLICATION_TARGET_NEW_LOCAL_DATABASE",
         replicationType: "",
         username: "tester"
-      })(dispatch);
+      })(dispatch).then(() => {
+        assert.lengthOf(finalPost.calls('./_replicator'), 3);
+      });
+    });
 
-      //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);
+    it('does not try to create new database if it already exist', () => {
+      const dispatch = () => {};
+      const mockPost = fetchMock.postOnce('./_replicator', {
+        status: 200,
+        body: {
+          ok: true
+        }
+      });
+
+      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 @@
     });
   };
 
-  promise
+  // Return promise for testing
+  return promise
     .then(json => {
       if (!json.ok) {
         throw json;
@@ -85,11 +86,11 @@
       });
 
       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);