Skip to content

Commit

Permalink
Complete fake Fastbill service
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Mar 6, 2016
1 parent 65d823d commit b11aeb6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
14 changes: 6 additions & 8 deletions test/objects/fastbill_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

describe 'when seller is an NGO' do
it 'should not contact Fastbill' do
Fastbill::Automatic::Base.expects(:perform).never
User.any_instance.stubs(:ngo).returns(:true)
api = FastbillAPI.new db_business_transaction
seller.ngo = true
seller.save
api.fastbill_chain
assert_not_requested :post, 'https://my_email:my_fastbill_api_key@automatic.fastbill.com'\
'/api/1.0/api.php'
end
end

Expand All @@ -35,12 +37,8 @@
api.expects(:fastbill_create_customer).never
api.expects(:fastbill_create_subscription).never
api.fastbill_chain
end
end

describe 'test stubbing' do
it 'test' do
Net::HTTP.get('automatic.fastbill.com', '/')
assert_requested :post, 'https://my_email:my_fastbill_api_key@automatic.fastbill.com'\
'/api/1.0/api.php', times: 2
end
end

Expand Down
12 changes: 7 additions & 5 deletions test/support/fake_services/fake_fastbill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ class FakeFastbill < Sinatra::Base

case service
when 'customer.create'
json_response 200, 'customer_create_response.json'
json_response 'customer_create_response.json'
when 'subscription.create'
json_response 200, 'subscription_create_response.json'
json_response 'subscription_create_response.json'
when 'subscription.setusagedata'
json_response 'subscription_set_usage_data_response.json'
else
json_response 200, 'standard_response.json'
json_response 'standard_response.json'
end
end

private

def json_response(response_code, file_name)
def json_response(file_name)
content_type :json
status response_code
status 200
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"REQUEST":{
"SERVICE":"subscription.setusagedata",
"DATA":{
"SUBSCRIPTION_ID":639548,
"ARTICLE_NUMBER":11,
"QUANTITY":1,
"UNIT_PRICE":0.34,
"DESCRIPTION":"1 Book 23 (Faires Prozent)",
"USAGE_DATE":"2016-03-06 18:41:36"
}
},
"RESPONSE":{
"STATUS":"success",
"USAGEDATA_ID":2164690
}
}

0 comments on commit b11aeb6

Please sign in to comment.