Skip to content

Commit

Permalink
New feature: refunds go to original funding source.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steveklabnik committed Dec 28, 2013
1 parent 27ed2d1 commit a9d699e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
9 changes: 0 additions & 9 deletions features/debits.feature
Expand Up @@ -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
6 changes: 6 additions & 0 deletions features/refunds.feature
Expand Up @@ -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
12 changes: 6 additions & 6 deletions features/step_definitions/customers.rb
Expand Up @@ -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',
Expand All @@ -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",
Expand All @@ -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


Expand Down
7 changes: 7 additions & 0 deletions features/step_definitions/debits.rb
Expand Up @@ -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
1 change: 1 addition & 0 deletions features/step_definitions/http_steps.rb
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions features/step_definitions/refund.rb
Expand Up @@ -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

This comment has been minimized.

Copy link
@mjallday

mjallday Dec 29, 2013

Contributor

creating the refund will make a new card

?

i'm not sure i grok that comment.

This comment has been minimized.

Copy link
@steveklabnik

steveklabnik Dec 30, 2013

Author Contributor

Currently, the steps are implemented in such a way that calling the step in the next line makes a new card, which clobbers @card_id. Yay global mutable state!

I want something to make this stuff better, but the perfect is the enemy of the good, so I'm just sucking it up right this moment.

step 'I have created a refund for a debit'
end

Then(/^the refund should go to the original card$/) do
@client.get(@debit_url)

This comment has been minimized.

Copy link
@mjallday

mjallday Dec 29, 2013

Contributor

are you supposed to be checking the refund went to the original card (as opposed to the debit)

This comment has been minimized.

Copy link
@steveklabnik

steveklabnik Dec 30, 2013

Author Contributor

You fetch the debit, and then assert on the body of the debit, see 3 lines down where it checks for the original card id.

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

0 comments on commit a9d699e

Please sign in to comment.