Skip to content

Commit

Permalink
progress on checking escrow on orders.
Browse files Browse the repository at this point in the history
Same delivery address issue
  • Loading branch information
steveklabnik committed Jan 7, 2014
1 parent 0536af7 commit a68ddd8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
10 changes: 6 additions & 4 deletions features/orders.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ Feature: Orders
Then I should get a 201 Created status code
And the response is valid according to the "orders" schema

@failing
@failing @gh-469
Scenario: Checking escrow of order after creating a debit
Given I have tokenized a customer card
Given I have created an order
And I have tokenized a customer card
And I make a POST request to the link "cards.debits" with the body:
"""
{
"order": "#{@orders_id}",
"order": "<%= @order_id %>",
"amount": 1234
}
"""

When I make a GET request to the link /orders/:order_id
When I make a GET request to /orders/:order_id
Then I should get a 200 OK status code
And the response is valid according to the "orders" schema
And the fields on this order match:
"""
{
"amount_escrowed": 1234
Expand Down
8 changes: 7 additions & 1 deletion features/step_definitions/http_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'erb'

When(/^I (\w+) to (\/\S*?)$/) do |verb, url|
@client.verb(verb, @client.hydrater(url))
@client.verb(verb, @client.hydrater(url), env)
@order_id = @client['orders']['id'] rescue nil
@client.add_hydrate(:order_id, @order_id) if @order_id
end

When(/^I (\w+) to (\/\S*?) with the body:$/) do |verb, url, body|
Expand All @@ -17,6 +21,7 @@ def env
"cards_id" => @card_id,
"debits_id" => @debit_id,
"customers_id" => @customer_id,
"orders_id" => @order_id,
}
end

Expand All @@ -27,6 +32,7 @@ def env
end

When(/^I make a (\w+) request to the link "(.*?)" with the body:$/) do |verb, keys, body|
body = ERB.new(body).result(binding)
body = @client.send(verb.downcase, @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
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Given(/^I have created an order$/) do
step 'I have created a customer'
step 'I make a POST request to /customers/:customer_id/orders'
end
23 changes: 15 additions & 8 deletions lib/balanced/tiny_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ def post(endpoint, body, env={})
}
}

url = expand_url(endpoint, env)

response = HTTParty.post(url, options)
@responses << response
response
end

def expand_url(endpoint, env)
require 'uri_template'
# I am so sorry
template = "#{@root_url}#{endpoint}".gsub(/{(.*?)}/) do
"{#{$1.gsub(".", "_")}}"
end
# TODO: does using . in uri variables make sense? http://tools.ietf.org/html/rfc6570#section-3.2.1
template = URITemplate.new(template)
url = template.expand(env)

response = HTTParty.post(url, options)
@responses << response
response
template.expand(env)
end

def put(endpoint, body, env={})
Expand Down Expand Up @@ -79,8 +83,8 @@ def patch(endpoint, body)
response
end

def get(endpoint)
verb 'GET', endpoint
def get(endpoint, body=nil, env={})
verb 'GET', endpoint, env
end

def delete(endpoint, body=nil, env={})
Expand All @@ -101,7 +105,10 @@ def verb(verb, url, env={})
password: '',
}
}
response = HTTParty.send(verb.downcase, "#{$root_url}#{url}", options)

url = expand_url(url, env)

response = HTTParty.send(verb.downcase, url, options)
@responses << response
response
end
Expand Down

0 comments on commit a68ddd8

Please sign in to comment.