houdini/spec/lib/query/billing_plans_spec.rb
Bradley M. Kuhn 6772312ea7 Relicense all .rb files under new project license.
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

with some specific files to be licensed under the one of two licenses:
   CC0-1.0
   LGPL-3.0-or-later

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

54 lines
1.7 KiB
Ruby

# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'
describe BillingPlans do
let(:percentage) {0.34}
let(:billing_plan) do
force_create(:billing_plan, :percentage_fee => percentage)
end
let(:nonprofit) do
force_create(:nonprofit)
end
describe '.get_percentage_fee' do
describe 'param validation' do
it 'rejects non-integers' do
expect { BillingPlans.get_percentage_fee('not an integer') }.to (raise_error {|error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, [{key: :nonprofit_id, name: :is_integer}])
})
end
it 'rejects invalid nonprofits' do
expect { BillingPlans.get_percentage_fee(55555) }.to (raise_error {|error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, [{key: :nonprofit_id}])
})
end
end
it 'returns 0 when no billing_subscription' do
result = BillingPlans.get_percentage_fee(nonprofit.id)
expect(result).to eq 0
end
# TODO not sure this is what we actually want?
it 'returns 0 when billing plan is invalid' do
bs = force_create(:billing_subscription, :billing_plan => nil, :nonprofit => nonprofit)
result = BillingPlans.get_percentage_fee(nonprofit.id)
expect(result).to eq(0)
end
it 'returns percentage when billing subscription exists' do
bs = force_create(:billing_subscription, :billing_plan => billing_plan, :nonprofit => nonprofit)
result = BillingPlans.get_percentage_fee(nonprofit.id)
expect(result).to eq (0.34)
end
end
end