jam-cloud/ruby/spec/jam_ruby/models/affiliate_payment_spec.rb

39 lines
1.8 KiB
Ruby

require 'spec_helper'
describe AffiliatePayment do
let(:partner) { FactoryGirl.create(:affiliate_partner) }
let(:user_partner) { FactoryGirl.create(:user, affiliate_partner: partner) }
it "succeeds with no data" do
results, nex = AffiliatePayment.index(user_partner, {})
results.length.should eq(0)
end
it "sorts month and quarters correctly" do
monthly1 = FactoryGirl.create(:affiliate_monthly_payment, affiliate_partner: partner, closed: true, due_amount_in_cents: 10, month: 1, year: 2015)
monthly2 = FactoryGirl.create(:affiliate_monthly_payment, affiliate_partner: partner, closed: true, due_amount_in_cents: 20, month: 2, year: 2015)
monthly3 = FactoryGirl.create(:affiliate_monthly_payment, affiliate_partner: partner, closed: true, due_amount_in_cents: 30, month: 3, year: 2015)
monthly4 = FactoryGirl.create(:affiliate_monthly_payment, affiliate_partner: partner, closed: true, due_amount_in_cents: 40, month: 4, year: 2015)
quarterly = FactoryGirl.create(:affiliate_quarterly_payment, affiliate_partner: partner, closed: true, paid:true, due_amount_in_cents: 50, quarter: 0, year: 2015)
results, nex = AffiliatePayment.index(user_partner, {})
results.length.should eq(5)
result1 = results[0]
result2 = results[1]
result3 = results[2]
result4 = results[3]
result5 = results[4]
result1.payment_type.should eq('monthly')
result1.due_amount_in_cents.should eq(10)
result2.payment_type.should eq('monthly')
result2.due_amount_in_cents.should eq(20)
result3.payment_type.should eq('monthly')
result3.due_amount_in_cents.should eq(30)
result4.payment_type.should eq('quarterly')
result4.due_amount_in_cents.should eq(50)
result5.payment_type.should eq('monthly')
result5.due_amount_in_cents.should eq(40)
end
end