From commits-return-33474-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Wed Jun 27 20:11:26 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 59F1B18066B for ; Wed, 27 Jun 2018 20:11:26 +0200 (CEST) Received: (qmail 40607 invoked by uid 500); 27 Jun 2018 18:11:25 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 40598 invoked by uid 99); 27 Jun 2018 18:11:25 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jun 2018 18:11:25 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B30ED82980; Wed, 27 Jun 2018 18:11:24 +0000 (UTC) Date: Wed, 27 Jun 2018 18:11:24 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb-fauxton] branch master updated: Fix - Create replication fails when db doesn't exist (#1095) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <153012308459.4591.12807103986982360765@gitbox.apache.org> From: amaranhao@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb-fauxton X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 8a3e520e17e2e79ee6015861f2592fadcb944558 X-Git-Newrev: d1ba78a80489b388856bb18bcda76674eae8d19c X-Git-Rev: d1ba78a80489b388856bb18bcda76674eae8d19c X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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);