From 627899bbd4e7ac87c5d4c3eb14f8fe00dbb259a8 Mon Sep 17 00:00:00 2001 From: stveep Date: Mon, 20 Mar 2017 19:35:11 +0000 Subject: [PATCH] spec for source attributes to pass for saved card --- .../darkswarm/services/checkout.js.coffee | 2 +- .../unit/darkswarm/services/checkout_spec.js.coffee | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/checkout.js.coffee b/app/assets/javascripts/darkswarm/services/checkout.js.coffee index 3c1ebcf773..94c871a482 100644 --- a/app/assets/javascripts/darkswarm/services/checkout.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout.js.coffee @@ -63,7 +63,7 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeJ if @secrets.selected_card angular.extend munged_order.payments_attributes[0], { source_attributes: - id: @secrets.selected_card + credit_card_id: @secrets.selected_card type: 'Spree::CreditCard' } else diff --git a/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee index 67a93f44d1..cb0d99f8b2 100644 --- a/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/checkout_spec.js.coffee @@ -131,7 +131,6 @@ describe 'Checkout service', -> Checkout.purchase() expect(StripeJS.requestToken).not.toHaveBeenCalled() - describe "data preprocessing", -> beforeEach -> Checkout.order.payment_method_id = 99 @@ -198,3 +197,15 @@ describe 'Checkout service', -> expect(source_attributes.last_digits).toBe "1234" expect(source_attributes.year).toBe "2099" expect(source_attributes.month).toBe "10" + + describe "when a saved card from Stripe is used", -> + beforeEach -> + Checkout.order.payment_method_id = 666 + + it "passes the card ID in source attributes if a saved card is selected", -> + Checkout.secrets.selected_card = 1 + source_attributes = Checkout.preprocess().payments_attributes[0].source_attributes + expect(source_attributes).toBeDefined() + expect(source_attributes.credit_card_id).toBe 1 + expect(source_attributes.type).toBe "Spree::CreditCard" + expect(source_attributes.year).toBeUndefined()