spec/mousetrap/customer_spec.rb in cameroncox-mousetrap-0.5.3.10 vs spec/mousetrap/customer_spec.rb in cameroncox-mousetrap-0.6.1
- old
+ new
@@ -1,10 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Mousetrap::Customer do
include Fixtures
-
+
def customer_attributes_for_api(customer)
{
:firstName => customer.first_name,
:lastName => customer.last_name,
:email => customer.email,
@@ -16,10 +16,14 @@
:ccLastName => customer.subscription.billing_last_name,
:ccNumber => customer.subscription.credit_card_number,
:ccExpMonth => customer.subscription.credit_card_expiration_month,
:ccExpYear => customer.subscription.credit_card_expiration_year,
:ccZip => customer.subscription.billing_zip_code,
+ :ccCountry => customer.subscription.billing_country,
+ :ccAddress => customer.subscription.billing_address,
+ :ccCity => customer.subscription.billing_city,
+ :ccState => customer.subscription.billing_state
}
}
end
describe "when having multiple subscriptions" do
@@ -263,22 +267,22 @@
@customer.stub :attributes_for_api_with_subscription => 'some_attributes'
end
it "posts a new customer" do
@customer.class.should_receive(:post_resource).with('customers', 'new', 'some_attributes').and_return({:id => 'some_id'})
- @customer.class.stub :build_resource_from
+ @customer.class.stub :build_resource_from => stub(:id => 'some_id')
@customer.send :create
end
it "raises error if CheddarGetter reports one" do
@customer.class.stub :post_resource => {'error' => 'some error message'}
expect { @customer.send(:create) }.to raise_error('some error message')
end
it "builds a customer from the CheddarGetter return values" do
@customer.class.stub :post_resource => 'some response'
- @customer.class.should_receive(:build_resource_from).with('some response').and_return(:id => 'some_id')
+ @customer.class.should_receive(:build_resource_from).with('some response').and_return(stub(:id => 'some_id'))
@customer.send :create
end
it "grabs the id from CheddarGetter and assigns it locally" do
@customer.class.stub :post_resource => {}
@@ -317,24 +321,61 @@
expect { customer.send(:update) }.to raise_error('some error message')
end
end
end
end
+
+ describe '#add_custom_charge' do
+ context "when there's a subscription instance" do
+ before :all do
+ @customer = Factory(:new_customer)
+ end
+
+ it "should not raise an error with CheddarGetter" do
+ @customer.class.should_receive(:put_resource).with('customers', 'add-charge', @customer.code, { :eachAmount => 45.00, :chargeCode => 'BOGUS', :quantity => 1, :description => nil }).and_return({ :id => 'some_id' })
+ @customer.add_custom_charge('BOGUS', 45.00, 1, nil)
+ end
+ end
+
+ context "with there is not a subscription" do
+ before :all do
+ @customer = Mousetrap::Customer.new
+ end
+
+ it "should raise an error with CheddarGetter" do
+ @customer.class.stub :put_resource => { 'error' => 'some error message' }
+ expect { @customer.add_custom_charge('BOGUS') }.to raise_error('some error message')
+ end
+ end
+ end
+
+ # describe '#update_tracked_item_quantity' do
+ # context "when there's a subscription instance" do
+ # before do
+ # @customer = Factory(:new_customer)
+ # end
+ #
+ # it "should not raise an error with CheddarGetter" do
+ # @customer.class.should_receive(:put_resource).with('customers', 'add-item-quantity', @customer.code, { :quantity => 1, :itemCode => 'BOGUS' }).and_return({ :id => 'some_id' })
+ # @customer.update_tracked_item_quantity('BOGUS', 1).should_not raise_error
+ # end
+ # end
+ # end
end
__END__
-customers:
- customer:
- company:
+customers:
+ customer:
+ company:
lastName: cgejerpkyw
code: krylmrreef@example.com
- subscriptions:
- subscription:
- plans:
- plan:
+ subscriptions:
+ subscription:
+ plans:
+ plan:
name: Test
setupChargeAmount: "42.00"
code: TEST
recurringChargeAmount: "13.00"
billingFrequencyQuantity: "1"
@@ -346,50 +387,50 @@
isActive: "1"
billingFrequencyUnit: months
description: This is my test plan. There are many like it, but this one is mine.
billingFrequencyPer: month
setupChargeCode: TEST_SETUP
- gatewayToken:
+ gatewayToken:
id: 7ccea6de-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
ccType: visa
ccLastFour: "1111"
ccExpirationDate: "2012-12-31T00:00:00+00:00"
- canceledDatetime:
- invoices:
- invoice:
+ canceledDatetime:
+ invoices:
+ invoice:
- number: "5"
- transactions:
- transaction:
+ transactions:
+ transaction:
response: approved
code: ""
amount: "42.00"
memo: This is a simulated transaction
id: 7ce53c78-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
transactedDatetime: "2009-10-14T20:08:14+00:00"
- parentId:
- charges:
- charge:
+ parentId:
+ charges:
+ charge:
code: TEST_SETUP
quantity: "1"
id: 7ce2cb6e-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
type: setup
eachAmount: "42.00"
- description:
- gatewayAccount:
+ description:
+ gatewayAccount:
id: ""
billingDatetime: "2009-10-14T20:08:14+00:00"
id: 7cd25072-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
type: setup
- number: "6"
billingDatetime: "2009-11-14T20:08:14+00:00"
id: 7cd4253c-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
type: subscription
- gatewayToken:
+ gatewayToken:
id: 7ccd6e5e-0a4d-102d-a92d-40402145ee8b
createdDatetime: "2009-10-14T20:08:14+00:00"
modifiedDatetime: "2009-10-14T20:08:14+00:00"
firstName: wqaqyhjdfg
email: krylmrreef@example.com