jam-cloud/web/spec/controllers/api_recurly_spec.rb

119 lines
3.6 KiB
Ruby

require 'spec_helper'
require 'recurly_client'
#require 'recurly/account'
describe ApiRecurlyController, :type=>:controller do
render_views
# let(:user) { FactoryGirl.create(:user) }
# let(:jamtrack) { FactoryGirl.create(:jam_track) }
before(:each) do
@user = FactoryGirl.create(:user)
#@jamtrack = FactoryGirl.create(:jam_track)
@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'
@billing_info[:vat_number] = ''
controller.current_user = @user
end
after(:each) do
if (@user.recurly_code)
@account = Recurly::Account.find(@user.recurly_code)
if @account.present?
@account.destroy
end
end
end
it "should send correct error" do
@billing_info[:number]='121'
post :create_account, {:format => 'json', :billing_info=>@billing_info}
response.status.should == 404
body = JSON.parse(response.body)
body['errors'].should have(1).items
body['errors']['number'].should_not be_nil
end
it "should create account" do
post :create_account, {:format => 'json'}
response.should be_success
end
it "should retrieve account" do
post :create_account, {:format => 'json'}
response.should be_success
get :get_account
body = JSON.parse(response.body)
response.should be_success
body['email'].should eq(@user.email)
end
it "should update account" do
post :create_account
response.should be_success
body = JSON.parse(response.body)
body['first_name'].should eq("Person")
@user.update_attribute(:first_name, "Thing")
controller.current_user = @user
put :update_account
body = JSON.parse(response.body)
body['first_name'].should eq("Thing")
get :get_account, { :format => 'json'}
response.should be_success
body = JSON.parse(response.body)
body['first_name'].should eq("Thing")
end
# Note: We don't have any subscriptions yet:
it "should get subscription" do
pending "We don't have any subscriptions yet -- uncomment in routes"
get :get_subscription, { :format => 'json'}
response.should be_success
body = JSON.parse(response.body)
end
it "should update billing info" do
# $enable_tracing = false
# $trace_out = open('trace.txt', 'w')
# set_trace_func proc { |event, file, line, id, binding, classname|
# if $enable_tracing && event == 'call' && !file.start_with?("/Users/tangledpath/.ddrvm/")
# $trace_out.puts "#{file}:#{line} #{classname}##{id}"
# end
# }
# $enable_tracing = true
post :create_account
response.should be_success
body = JSON.parse(response.body)
body['first_name'].should eq("Person")
@billing_info[:state] = "NE"
put :update_billing_info, {:format => 'json', :billing_info=>@billing_info}
response.should be_success
body = JSON.parse(response.body)
get :billing_info
response.should be_success
body = JSON.parse(response.body)
end
end # spec