Skip to content

Commit

Permalink
Use fake service for Fastbill tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Mar 12, 2016
1 parent 843d666 commit 64d721d
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 73 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ gem 'exception_notification'
# ---------- API ----------

# Gem for connecting to FastBill Automatic
gem 'fastbill-automatic', git: 'git://github.com/reputami/fastbill-automatic.git', tag: 'v0.0.3'
gem 'fastbill-automatic', git: 'git://github.com/marcaltmann/fastbill-automatic.git'

gem 'savon' # interacing with other SOAP apis:
gem 'rubyntlm' # https://github.com/savonrb/savon/issues/593
Expand Down Expand Up @@ -155,6 +155,8 @@ group :test do
gem 'colorize'
gem 'fakeredis'
gem 'fakeweb', '~> 1.3'
gem 'webmock'
gem 'rack-contrib'
end

group :development, :test do
Expand Down
22 changes: 14 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ GIT
rails
railties

GIT
remote: git://github.com/marcaltmann/fastbill-automatic.git
revision: 26ce93677d694b4fff7d71a0d2fb664ebc0827f9
specs:
fastbill-automatic (0.0.3)
json

GIT
remote: git://github.com/nadarei/nkss-rails.git
revision: 8f5e27e98115daad591ac871a50a7c5ffa966d3e
Expand All @@ -32,14 +39,6 @@ GIT
sass (~> 3.0)
terminal-table (~> 1.4)

GIT
remote: git://github.com/reputami/fastbill-automatic.git
revision: cb93c161ea9ae27c0485aca381ea90d0f7d04225
tag: v0.0.3
specs:
fastbill-automatic (0.0.3)
json

GEM
remote: http://rubygems.org/
specs:
Expand Down Expand Up @@ -175,6 +174,8 @@ GEM
simplecov (>= 0.7)
term-ansicolor
thor
crack (0.4.2)
safe_yaml (~> 1.0.0)
crass (1.0.1)
css_parser (1.3.5)
addressable
Expand Down Expand Up @@ -662,6 +663,9 @@ GEM
httpi (~> 2.0)
mime-types (< 2.0.0)
nokogiri (>= 1.4.0)
webmock (1.21.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
wiselinks (1.2.1)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand Down Expand Up @@ -754,6 +758,7 @@ DEPENDENCIES
pundit
qtip2-jquery-rails (~> 2.1.107)
quiet_assets
rack-contrib
rack-mini-profiler
rack-rewrite
rails (~> 4.1.9)
Expand Down Expand Up @@ -792,6 +797,7 @@ DEPENDENCIES
tinymce-rails
tinymce-rails-langs
uglifier
webmock
wiselinks

BUNDLED WITH
Expand Down
1 change: 0 additions & 1 deletion test/controllers/payment_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# See the COPYRIGHT file for details.

require_relative '../test_helper'
include FastBillStubber

describe PaymentsController do
let(:lig) { FactoryGirl.create :line_item_group, :sold, :with_business_transactions, traits: [:paypal, :transport_type1] }
Expand Down
2 changes: 0 additions & 2 deletions test/controllers/refunds_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require_relative '../test_helper'

include FastBillStubber

describe RefundsController do
let(:seller) { FactoryGirl.create :user }
let(:line_item_group) { FactoryGirl.create :line_item_group, seller: seller }
Expand Down
6 changes: 6 additions & 0 deletions test/factories/business_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
discount_value_cents 0
quantity_bought 1

factory :business_transaction_from_ngo, traits: [:from_ngo]

trait :incomplete do
shipping_address nil
end
Expand Down Expand Up @@ -65,6 +67,10 @@
association :article, factory: [:article, :with_discount]
end

trait :from_ngo do
association :seller, factory: [:ngo, :paypal_data]
end

trait :pickup do
selected_transport :pickup
end
Expand Down
2 changes: 2 additions & 0 deletions test/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
admin true
end

factory :ngo, class: 'PrivateUser', traits: [:ngo]

factory :non_german_user do
country Faker::Address.country
end
Expand Down
2 changes: 1 addition & 1 deletion test/features/line_item_groups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Maybe merge this test file with refund_test.rb

require_relative '../test_helper'
include FastBillStubber

include Warden::Test::Helpers

feature 'Display line item group after transaction' do
Expand Down
1 change: 0 additions & 1 deletion test/features/rating_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require_relative '../test_helper'

include Warden::Test::Helpers
include FastBillStubber

feature 'User ratings' do
let(:buyer) { FactoryGirl.create :user }
Expand Down
1 change: 0 additions & 1 deletion test/features/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# See the COPYRIGHT file for details.

require_relative '../test_helper'
include FastBillStubber

include Warden::Test::Helpers

Expand Down
1 change: 0 additions & 1 deletion test/mailers/refund_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
describe RefundMailer do
include EmailSpec::Helpers
include EmailSpec::Matchers
include FastBillStubber

it '#refund_notification' do
refund = FactoryGirl.create :refund, reason: 'not_in_stock'
Expand Down
10 changes: 6 additions & 4 deletions test/objects/fastbill_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# See the COPYRIGHT file for details.

require_relative '../test_helper'
include FastBillStubber

describe FastbillAPI do
describe 'methods' do
let(:business_transaction) { BusinessTransaction.new }
let(:db_business_transaction) { FactoryGirl.create :business_transaction }
let(:db_bt_from_ngo) { FactoryGirl.create :business_transaction_from_ngo }
let(:seller) { db_business_transaction.seller }

describe '::fastbill_chain' do
Expand All @@ -19,10 +19,10 @@

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
api = FastbillAPI.new db_bt_from_ngo
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 @@ -36,6 +36,8 @@
api.expects(:fastbill_create_customer).never
api.expects(:fastbill_create_subscription).never
api.fastbill_chain
assert_requested :post, 'https://my_email:my_fastbill_api_key@automatic.fastbill.com'\
'/api/1.0/api.php', times: 2
end
end

Expand Down
1 change: 0 additions & 1 deletion test/policies/refund_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# See the COPYRIGHT file for details.

require_relative '../test_helper'
include FastBillStubber
include PunditMatcher

describe RefundPolicy do
Expand Down
35 changes: 35 additions & 0 deletions test/support/fake_services/fake_fastbill.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2012-2016, Fairmondo eG. This file is
# licensed under the GNU Affero General Public License version 3 or later.
# See the COPYRIGHT file for details.

require 'sinatra/base'
require 'rack/contrib'

class FakeFastbill < Sinatra::Base
use ::Rack::PostBodyContentTypeParser

use Rack::Auth::Basic do |username, password|
username == 'my_email' && password == 'my_fastbill_api_key'
end

post '/api/1.0/api.php' do
case params['service']
when 'customer.create'
json_response 'customer_create_response.json'
when 'subscription.create'
json_response 'subscription_create_response.json'
when 'subscription.setusagedata'
json_response 'subscription_set_usage_data_response.json'
else
json_response 'standard_response.json'
end
end

private

def json_response(file_name)
content_type :json
status 200
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
end
end
34 changes: 34 additions & 0 deletions test/support/fake_services/fixtures/customer_create_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"REQUEST":{
"SERVICE":"customer.create",
"DATA":{
"CUSTOMER_TYPE":"business",
"ORGANIZATION":"hettie4",
"SALUTATION":null,
"FIRST_NAME":"Erika",
"LAST_NAME":"Mustermann",
"ADDRESS":"Eldenaer Strau00dfe 17",
"ADDRESS_2":null,
"ZIPCODE":"10247",
"CITY":"Berlin",
"COUNTRY_CODE":"DE",
"LANGUAGE_CODE":"DE",
"EMAIL":"petra.leuschke@konopelskimarks.com",
"CURRENCY_CODE":"EUR",
"PAYMENT_TYPE":"1",
"SHOW_PAYMENT_NOTICE":"1",
"BANK_NAME":"Jacky Fay I",
"BANK_CODE":"31330910",
"BANK_ACCOUNT_NUMBER":"95517526",
"BANK_ACCOUNT_OWNER":"Eliane Roob",
"CUSTOMER_NUMBER":1
}
},
"RESPONSE":{
"STATUS":"success",
"CUSTOMER_ID":1185408,
"HASH":"aeaeebb07f47a1942e44d197cae78710",
"CHANGEDATA_URL":"https://automatic.fastbill.com/accountdata/527d3ca69ba41db0905687319f8eb6ef/aeaeebb07f47a1942e44d197cae78710",
"DASHBOARD_URL":"https://automatic.fastbill.com/dashboard/527d3ca69ba41db0905687319f8eb6ef/aeaeebb07f47a1942e44d197cae78710"
}
}
11 changes: 11 additions & 0 deletions test/support/fake_services/fixtures/standard_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"REQUEST":{
"SERVICE":"customer.create",
"DATA":{
"CUSTOMER_TYPE":"business"
}
},
"RESPONSE":{
"ERRORS":["Login Error: Wrong API KEY or user credentials."]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"REQUEST":{
"SERVICE":"subscription.create",
"DATA":{
"ARTICLE_NUMBER":10,
"CUSTOMER_ID":1185408
}
},
"RESPONSE":{
"STATUS":"success",
"SUBSCRIPTION_ID":639548,
"HASH":"c3e0d432d43e542765091e63858db6d9",
"INVOICE_ID":1033382,
"PAYPAL_URL":"https://automatic.fastbill.com/paypal/MtmL1mch4xaiTqDPDXmoMVeKSMzF2zUDh6OWgq4ZcT7w9-_AWmpi8HtOUgUKUpO1"
}
}
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
}
}
52 changes: 0 additions & 52 deletions test/support/modules/fastbill_api.rb

This file was deleted.

Loading

0 comments on commit 64d721d

Please sign in to comment.