From a9d699e4a0710922cdcdfc624033a632852f7a93 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sat, 28 Dec 2013 00:02:41 +0000 Subject: [PATCH] New feature: refunds go to original funding source. I made the last scenario mis-understanding the way that the YAML scenarios worked. Often, they have duplicate stuff with new names just to make sure that things work. That means I don't need to translate them 1-1, I have to figure out which thing is actually important and just do that. --- features/debits.feature | 9 ------- features/refunds.feature | 6 +++++ features/step_definitions/customers.rb | 12 +++++----- features/step_definitions/debits.rb | 7 ++++++ features/step_definitions/http_steps.rb | 1 + features/step_definitions/refund.rb | 32 +++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/features/debits.feature b/features/debits.feature index 26016e6..370b1e7 100644 --- a/features/debits.feature +++ b/features/debits.feature @@ -17,12 +17,3 @@ Feature: Debit cards """ Then I should get a 201 Created status code And the response is valid according to the "debits" schema - - Scenario: Create a debit - Given I have created a customer - When I make a POST request to the link "customers.debits" with the body: - """ - { "amount": 1234 } - """ - Then I should get a 201 Created status code - And the response is valid according to the "debits" schema diff --git a/features/refunds.feature b/features/refunds.feature index 9e77ad9..b95b6ba 100644 --- a/features/refunds.feature +++ b/features/refunds.feature @@ -7,3 +7,9 @@ Feature: Refunds When I make a POST request to the link "debits.refunds" Then I should get a 201 Created status code And the response is valid according to the "refunds" schema + + Scenario: Refund after changed source + Given I have created a debit + When I change the default funding source + And I create a refund + Then the refund should go to the original card diff --git a/features/step_definitions/customers.rb b/features/step_definitions/customers.rb index e2d20cc..e46bf67 100644 --- a/features/step_definitions/customers.rb +++ b/features/step_definitions/customers.rb @@ -3,7 +3,7 @@ @customer_id = @client['id'] @client.add_hydrate :customer_id, @customer_id - customer_url = @client['customers']['href'] + @customer_url = @client['customers']['href'] # tokenize a card for them @client.post('/cards', @@ -19,8 +19,8 @@ } ) card_url = @client['cards']['href'] - card_id = @client['cards']['id'] - @client.patch(card_url, + @card_id = @client['cards']['id'] + @client.patch(card_url, [{ op: "replace", path: "/cards/0/links/customer", @@ -29,18 +29,18 @@ ) # associate their card so that they have a funding source - @client.patch(customer_url, + @client.patch(@customer_url, [{ op: "replace", path: "/customers/0/links/source", - value: card_id + value: @card_id }] ) ## TODO: fix hax # Right now, we rely on last_body in places becuase the client is mutable # this is bad and we should stop it. - @client.get(customer_url) + @client.get(@customer_url) end diff --git a/features/step_definitions/debits.rb b/features/step_definitions/debits.rb index 706f8cb..7ea80f8 100644 --- a/features/step_definitions/debits.rb +++ b/features/step_definitions/debits.rb @@ -21,3 +21,10 @@ Given(/^I have more than one debit$/) do 2.times { step 'I have debited a card' } end + +Given(/^I have created a debit$/) do + step 'I have created a customer' + step 'I make a POST request to the link "customers.debits" with the body:', '{ "amount": 1234 }' + step 'I should get a 201 Created status code' + step 'the response is valid according to the "debits" schema' +end diff --git a/features/step_definitions/http_steps.rb b/features/step_definitions/http_steps.rb index bcb1c03..2504de2 100644 --- a/features/step_definitions/http_steps.rb +++ b/features/step_definitions/http_steps.rb @@ -25,6 +25,7 @@ def env body = @client.post(@client.hydrater(@client.last_body["links"][keys]), JSON.parse(body), env) @credit_id = @client['credits']['id'] rescue nil @cards_id = @client['cards']['id'] rescue nil + @debit_url = @client['debits']['href'] rescue nil body end diff --git a/features/step_definitions/refund.rb b/features/step_definitions/refund.rb index ff11d79..f59325a 100644 --- a/features/step_definitions/refund.rb +++ b/features/step_definitions/refund.rb @@ -4,3 +4,35 @@ @refund_id = @client['refunds']['id'] @client.add_hydrate :refund_id, @refund_id end + +When(/^I change the default funding source$/) do + @client.post('/cards', + { + number: "4111 1111 1111 1111", + expiration_month: 12, + expiration_year: 2016, + } + ) + @other_card_id = @client['cards']['id'] + + @client.patch(@customer_url, + [{ + op: "replace", + path: "/customers/0/links/source", + value: @other_card_id + }] + ) +end + +When(/^I create a refund$/) do + @original_card_id = @card_id # creating the refund will make a new card + step 'I have created a refund for a debit' +end + +Then(/^the refund should go to the original card$/) do + @client.get(@debit_url) + step "I should get a 200 OK status code" + step 'the response is valid according to the "debits" schema' + step "the fields on these debits match:", %Q/{ "links": { "source": "#{@original_card_id}" } }/ +end +