mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-02 00:00:35 -04:00
Adding tests for Subscription.
This commit is contained in:
parent
4d5f45a222
commit
ee42d9c583
@ -10,6 +10,5 @@ module Stripe
|
||||
def self.retrieve(id, api_key=nil)
|
||||
raise NotImplementedError.new("Subscriptions cannot be retrieved without a customer ID. Retrieve a subscription using customer.subscriptions.retrieve('subscription_id')")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
57
test/stripe/subscription_test.rb
Normal file
57
test/stripe/subscription_test.rb
Normal file
@ -0,0 +1,57 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class SubscriptionTest < Test::Unit::TestCase
|
||||
should "subscriptions should be listable" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
|
||||
customer = Stripe::Customer.retrieve('test_customer')
|
||||
|
||||
assert customer.subscriptions.first.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be refreshable" do
|
||||
@mock.expects(:get).twice.returns(test_response(test_customer), test_response(test_subscription(:id => 'refreshed_subscription')))
|
||||
|
||||
customer = Stripe::Customer.retrieve('test_customer')
|
||||
subscription = customer.subscriptions.first
|
||||
subscription.refresh
|
||||
|
||||
assert_equal subscription.id, 'refreshed_subscription'
|
||||
end
|
||||
|
||||
should "subscriptions should be deletable" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
@mock.expects(:delete).once.returns(test_response(test_subscription({:deleted => true})))
|
||||
|
||||
customer = Stripe::Customer.retrieve('test_customer')
|
||||
subscription = customer.subscriptions.first
|
||||
subscription.delete
|
||||
|
||||
assert subscription.deleted
|
||||
end
|
||||
|
||||
should "subscriptions should be updateable" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
@mock.expects(:post).once.returns(test_response(test_subscription({:status => 'active'})))
|
||||
|
||||
customer = Stripe::Customer.retrieve('test_customer')
|
||||
subscription = customer.subscriptions.first
|
||||
assert_equal subscription.status, 'trialing'
|
||||
|
||||
subscription.status = 'active'
|
||||
subscription.save
|
||||
|
||||
assert_equal subscription.status, 'active'
|
||||
end
|
||||
|
||||
should "create should return a new subscription" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
@mock.expects(:post).once.returns(test_response(test_subscription(:id => 'test_new_subscription')))
|
||||
|
||||
customer = Stripe::Customer.retrieve('test_customer')
|
||||
subscription = customer.subscriptions.create(:plan => 'silver')
|
||||
assert_equal subscription.id, 'test_new_subscription'
|
||||
end
|
||||
end
|
||||
end
|
@ -94,17 +94,19 @@ def test_application_fee_array
|
||||
end
|
||||
|
||||
def test_customer(params={})
|
||||
id = params[:id] || 'c_test_customer'
|
||||
{
|
||||
:subscription_history => [],
|
||||
:bills => [],
|
||||
:charges => [],
|
||||
:livemode => false,
|
||||
:object => "customer",
|
||||
:id => "c_test_customer",
|
||||
:id => id,
|
||||
:default_card => "cc_test_card",
|
||||
:created => 1304114758,
|
||||
:cards => test_card_array('c_test_customer'),
|
||||
:metadata => {}
|
||||
:cards => test_card_array(id),
|
||||
:metadata => {},
|
||||
:subscriptions => test_subscription_array(id)
|
||||
}.merge(params)
|
||||
end
|
||||
|
||||
@ -180,7 +182,8 @@ def test_coupon(params={})
|
||||
end
|
||||
|
||||
#FIXME nested overrides would be better than hardcoding plan_id
|
||||
def test_subscription(plan_id="gold")
|
||||
def test_subscription(params = {})
|
||||
plan_id = params.delete(:plan_id) || 'gold'
|
||||
{
|
||||
:current_period_end => 1308681468,
|
||||
:status => "trialing",
|
||||
@ -196,7 +199,16 @@ def test_subscription(plan_id="gold")
|
||||
:object => "subscription",
|
||||
:trial_start => 1308595038,
|
||||
:trial_end => 1308681468,
|
||||
:customer => "c_test_customer"
|
||||
:customer => "c_test_customer",
|
||||
:id => 's_test_subscription'
|
||||
}.merge(params)
|
||||
end
|
||||
|
||||
def test_subscription_array(customer_id)
|
||||
{
|
||||
:data => [test_subscription, test_subscription, test_subscription],
|
||||
:object => 'list',
|
||||
:url => '/v1/customers/' + customer_id + '/subscriptions'
|
||||
}
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user