128 lines
4.3 KiB
Ruby
128 lines
4.3 KiB
Ruby
require 'spec_helper'
|
|
require "jam_ruby/recurly_client"
|
|
describe RecurlyClient do
|
|
let(:jamtrack) { FactoryGirl.create(:jam_track) }
|
|
#let(:client) { RecurlyClient.new }
|
|
|
|
before :all do
|
|
@client = RecurlyClient.new
|
|
@jamtrack = FactoryGirl.create(:jam_track)
|
|
end
|
|
|
|
before(:each) do
|
|
@user = FactoryGirl.create(:user)
|
|
@billing_info = {}
|
|
@billing_info[:first_name] = @user.first_name
|
|
@billing_info[:last_name] = @user.last_name
|
|
@billing_info[:address1] = 'Test Address 1'
|
|
@billing_info[:address2] = 'Test Address 2'
|
|
@billing_info[:city] = @user.city
|
|
@billing_info[:state] = @user.state
|
|
@billing_info[:country] = @user.country
|
|
@billing_info[:zip] = '12345'
|
|
@billing_info[:number] = '4111-1111-1111-1111'
|
|
@billing_info[:month] = '08'
|
|
@billing_info[:year] = '2017'
|
|
@billing_info[:verification_value] = '111'
|
|
end
|
|
|
|
after(:each) do
|
|
if (@user.recurly_code)
|
|
account = Recurly::Account.find(@user.recurly_code)
|
|
if account.present?
|
|
account.destroy
|
|
end
|
|
end
|
|
end
|
|
|
|
it "can create account" do
|
|
account = @client.create_account(@user, @billing_info)
|
|
account.should_not be_nil
|
|
@user.recurly_code.should eq(account.account_code)
|
|
end
|
|
|
|
it "can create account with errors" do
|
|
@billing_info[:verification_value] = '1111'
|
|
expect {@client.create_account(@user, @billing_info)}.to raise_error(RecurlyClientError)
|
|
end
|
|
|
|
describe "with account" do
|
|
before :each do
|
|
@account = @client.find_or_create_account(@user, @billing_info)
|
|
end
|
|
|
|
it "can find account" do
|
|
@user.recurly_code.should_not be_nil
|
|
found = @client.get_account(@user)
|
|
found.should_not be_nil
|
|
found.first_name.should eq(@user.first_name)
|
|
found.last_name.should eq(@user.last_name)
|
|
found.email.should eq(@user.email)
|
|
end
|
|
|
|
it "can update account" do
|
|
@user.first_name = "Foobar"
|
|
@client.update_account(@user, @billing_info)
|
|
found = @client.get_account(@user)
|
|
found.first_name.should eq(@user.first_name)
|
|
end
|
|
|
|
it "can update billing" do
|
|
@billing_info['address1'] = "2112 Foobar Lane"
|
|
@client.update_billing_info(@user, @billing_info)
|
|
found = @client.get_account(@user)
|
|
found.billing_info.address1.should eq(@billing_info['address1'])
|
|
end
|
|
|
|
it "purchases jamtrack" do
|
|
end
|
|
end
|
|
|
|
it "can remove account" do
|
|
@client.find_or_create_account(@user, @billing_info)
|
|
@client.get_account(@user).should_not be_nil
|
|
@client.delete_account(@user)
|
|
found=@client.get_account(@user)
|
|
found.should_not be_nil
|
|
found.state.should eq('closed')
|
|
end
|
|
|
|
it "can place order" do
|
|
history_items = @client.payment_history(@user).length
|
|
@client.find_or_create_account(@user, @billing_info)
|
|
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
|
|
subs = @client.get_account(@user).subscriptions
|
|
subs.should_not be_nil
|
|
subs.should have(1).items
|
|
@user.jam_track_rights.should_not be_nil
|
|
@user.jam_track_rights.should have(1).items
|
|
@user.jam_track_rights.last.jam_track.id.should eq(@jamtrack.id)
|
|
@client.payment_history(@user).should have(history_items+1).items
|
|
end
|
|
|
|
it "can refund subscription" do
|
|
@client.find_or_create_account(@user, @billing_info)
|
|
|
|
# Place order:
|
|
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
|
|
active_subs=@client.get_account(@user).subscriptions.find_all{|t|t.state=='active'}
|
|
@jamtrack.reload
|
|
@jamtrack.jam_track_rights.should have(1).items
|
|
|
|
# Refund:
|
|
expect{@client.refund_user_subscription(@user, @jamtrack)}.not_to raise_error()
|
|
active_subs=@client.get_account(@user).subscriptions.find_all{|t|t.state=='active'}
|
|
active_subs.should have(0).items
|
|
|
|
@jamtrack.reload
|
|
@jamtrack.jam_track_rights.should have(0).items
|
|
end
|
|
|
|
it "detects error on double order" do
|
|
@client.find_or_create_account(@user, @billing_info)
|
|
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
|
|
expect{@client.place_order(@user, @jamtrack)}.to raise_error(RecurlyClientError)
|
|
end
|
|
end
|
|
|