From 22a079c2148ffce24dc50dd42706055d840e5cad Mon Sep 17 00:00:00 2001 From: Kyungmin Kim Date: Wed, 23 Apr 2014 17:25:30 -0700 Subject: [PATCH 1/3] Test refunding to pending debits --- test/integration/debits.js | 30 ++++++++++++++++++++++++++++++ test/lib/utils.js | 16 ++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/test/integration/debits.js b/test/integration/debits.js index c8d2d504a..326ba070c 100644 --- a/test/integration/debits.js +++ b/test/integration/debits.js @@ -13,7 +13,22 @@ module('Debits', { Testing.DEBIT_ID = debit.get('id'); Testing.DEBIT_URI = debit.get('uri'); Testing.DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.DEBIT_ID; + }).then(function(){ + Testing._createPendingBankAccount().then(function(bankAccount) { + return Balanced.Debit.create({ + uri: bankAccount.get('debits_uri'), + appears_on_statement_as: 'Pixie Dust', + amount: 100000, + description: 'Cocaine' + }).save(); + }).then(function(debit) { + Testing.PENDING_DEBIT_ID = debit.get('id'); + Testing.PENDING_DEBIT_URI = debit.get('uri'); + Testing.PENDING_DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.PENDING_DEBIT_ID; + console.log(debit.get('status')); + }); }); + }); }, teardown: function() {} @@ -41,6 +56,21 @@ test('can refund debit', function(assert) { }); }); +test('can refund a pending debit', function(assert) { + var spy = sinon.spy(Balanced.Adapter, "create"); + + visit(Testing.PENDING_DEBIT_ROUTE) + .click(".refund-debit-button") + .fillIn('#refund-debit .modal-body input[name="dollar_amount"]', "10") + .click('#refund-debit .modal-footer button[name="modal-submit"]') + .then(function() { + assert.ok(spy.calledOnce); + assert.ok(spy.calledWith(Balanced.Refund)); + assert.equal(spy.getCall(0).args[2].debit_uri, Testing.PENDING_DEBIT_URI); + assert.equal(spy.getCall(0).args[2].amount, '1000'); + }); +}); + test('can edit debit', function(assert) { var spy = sinon.spy(Balanced.Adapter, "update"); diff --git a/test/lib/utils.js b/test/lib/utils.js index 5e17e23ff..eb3d4b48c 100644 --- a/test/lib/utils.js +++ b/test/lib/utils.js @@ -184,6 +184,22 @@ var Testing = { }); }, + _createPendingBankAccount: function() { + var self = this; + return Balanced.BankAccount.create({ + uri: '/customers/' + self.CUSTOMER_ID + '/bank_accounts', + name: 'Test Account', + account_number: '9900000001', + routing_number: '321174851', + type: 'checking' + }).save().then(function(bankAccount) { + self.BANK_ACCOUNT_ID = bankAccount.get('id'); + self.BANK_ACCOUNT_ROUTE = self.MARKETPLACE_ROUTE + + '/bank_accounts/' + self.BANK_ACCOUNT_ID; + return bankAccount; + }); + }, + _createReversal: function() { var self = this; From 88fdec7fac6e366b42598b1a5da92b2377baaf4c Mon Sep 17 00:00:00 2001 From: Kyungmin Kim Date: Wed, 23 Apr 2014 17:55:04 -0700 Subject: [PATCH 2/3] Update pending debit test --- test/integration/debits.js | 33 +++++++++------------------------ test/lib/utils.js | 16 ---------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/test/integration/debits.js b/test/integration/debits.js index 326ba070c..e8e9e03b7 100644 --- a/test/integration/debits.js +++ b/test/integration/debits.js @@ -13,22 +13,7 @@ module('Debits', { Testing.DEBIT_ID = debit.get('id'); Testing.DEBIT_URI = debit.get('uri'); Testing.DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.DEBIT_ID; - }).then(function(){ - Testing._createPendingBankAccount().then(function(bankAccount) { - return Balanced.Debit.create({ - uri: bankAccount.get('debits_uri'), - appears_on_statement_as: 'Pixie Dust', - amount: 100000, - description: 'Cocaine' - }).save(); - }).then(function(debit) { - Testing.PENDING_DEBIT_ID = debit.get('id'); - Testing.PENDING_DEBIT_URI = debit.get('uri'); - Testing.PENDING_DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.PENDING_DEBIT_ID; - console.log(debit.get('status')); - }); }); - }); }, teardown: function() {} @@ -59,16 +44,16 @@ test('can refund debit', function(assert) { test('can refund a pending debit', function(assert) { var spy = sinon.spy(Balanced.Adapter, "create"); - visit(Testing.PENDING_DEBIT_ROUTE) - .click(".refund-debit-button") - .fillIn('#refund-debit .modal-body input[name="dollar_amount"]', "10") - .click('#refund-debit .modal-footer button[name="modal-submit"]') - .then(function() { - assert.ok(spy.calledOnce); - assert.ok(spy.calledWith(Balanced.Refund)); - assert.equal(spy.getCall(0).args[2].debit_uri, Testing.PENDING_DEBIT_URI); - assert.equal(spy.getCall(0).args[2].amount, '1000'); + visit(Testing.DEBIT_ROUTE).then(function() { + var model = Balanced.__container__.lookup('controller:debits'); + model.set('status', 'pending'); + stop(); + Ember.run.next(function() { + start(); + assert.equal(model.get('status'), 'pending'); + assert.equal($('#refund-debit').is(':visible'), true); }); + }); }); test('can edit debit', function(assert) { diff --git a/test/lib/utils.js b/test/lib/utils.js index eb3d4b48c..5e17e23ff 100644 --- a/test/lib/utils.js +++ b/test/lib/utils.js @@ -184,22 +184,6 @@ var Testing = { }); }, - _createPendingBankAccount: function() { - var self = this; - return Balanced.BankAccount.create({ - uri: '/customers/' + self.CUSTOMER_ID + '/bank_accounts', - name: 'Test Account', - account_number: '9900000001', - routing_number: '321174851', - type: 'checking' - }).save().then(function(bankAccount) { - self.BANK_ACCOUNT_ID = bankAccount.get('id'); - self.BANK_ACCOUNT_ROUTE = self.MARKETPLACE_ROUTE + - '/bank_accounts/' + self.BANK_ACCOUNT_ID; - return bankAccount; - }); - }, - _createReversal: function() { var self = this; From b2b1bc7f7083d083381166210a32def1492d2e17 Mon Sep 17 00:00:00 2001 From: Kyungmin Kim Date: Wed, 23 Apr 2014 18:53:48 -0700 Subject: [PATCH 3/3] Revert back to the original test and add status assertion --- test/integration/debits.js | 29 +++++++++++++++++++++-------- test/lib/utils.js | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/test/integration/debits.js b/test/integration/debits.js index e8e9e03b7..91480deac 100644 --- a/test/integration/debits.js +++ b/test/integration/debits.js @@ -14,6 +14,19 @@ module('Debits', { Testing.DEBIT_URI = debit.get('uri'); Testing.DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.DEBIT_ID; }); + Testing._createPendingBankAccount().then(function(bankAccount) { + return Balanced.Debit.create({ + uri: bankAccount.get('debits_uri'), + appears_on_statement_as: 'Pixie Dust', + amount: 100000, + description: 'Cocaine' + }).save(); + }).then(function(debit) { + Testing.PENDING_DEBIT = debit; + Testing.PENDING_DEBIT_ID = debit.get('id'); + Testing.PENDING_DEBIT_URI = debit.get('uri'); + Testing.PENDING_DEBIT_ROUTE = '/marketplaces/' + Testing.MARKETPLACE_ID + '/debits/' + Testing.PENDING_DEBIT_ID; + }); }); }, teardown: function() {} @@ -44,16 +57,16 @@ test('can refund debit', function(assert) { test('can refund a pending debit', function(assert) { var spy = sinon.spy(Balanced.Adapter, "create"); - visit(Testing.DEBIT_ROUTE).then(function() { - var model = Balanced.__container__.lookup('controller:debits'); - model.set('status', 'pending'); - stop(); - Ember.run.next(function() { - start(); - assert.equal(model.get('status'), 'pending'); + visit(Testing.PENDING_DEBIT_ROUTE) + .click(".refund-debit-button") + .fillIn('#refund-debit .modal-body input[name="dollar_amount"]', "10") + .click('#refund-debit .modal-footer button[name="modal-submit"]') + .then(function() { + assert.ok(spy.calledOnce); + assert.ok(spy.calledWith(Balanced.Refund)); + assert.equal(Testing.PENDING_DEBIT.get('status'), 'pending'); assert.equal($('#refund-debit').is(':visible'), true); }); - }); }); test('can edit debit', function(assert) { diff --git a/test/lib/utils.js b/test/lib/utils.js index 5e17e23ff..bae8e9c9c 100644 --- a/test/lib/utils.js +++ b/test/lib/utils.js @@ -6,6 +6,7 @@ var Testing = { MARKETPLACE_ID: null, CARD_ID: null, BANK_ACCOUNT_ID: null, + PENDING_BANK_ACCOUNT_ID: null, CREDIT_ID: null, CUSTOMER_ID: null, DEBIT_ID: null, @@ -16,6 +17,7 @@ var Testing = { ACTIVITY_ROUTE: null, ADD_CUSTOMER_ROUTE: null, BANK_ACCOUNT_ROUTE: null, + PENDING_BANK_ACCOUNT_ROUTE: null, CARD_ROUTE: null, CREDIT_ROUTE: null, CUSTOMER_ROUTE: null, @@ -184,6 +186,22 @@ var Testing = { }); }, + _createPendingBankAccount: function() { + var self = this; + return Balanced.BankAccount.create({ + uri: '/customers/' + self.CUSTOMER_ID + '/bank_accounts', + name: 'Test Account', + account_number: '9900000001', + routing_number: '321174851', + type: 'checking' + }).save().then(function(bankAccount) { + self.PENDING_BANK_ACCOUNT_ID = bankAccount.get('id'); + self.PENDING_BANK_ACCOUNT_ROUTE = self.MARKETPLACE_ROUTE + + '/bank_accounts/' + self.PENDING_BANK_ACCOUNT_ID; + return bankAccount; + }); + }, + _createReversal: function() { var self = this;