2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe CalculateSuggestedAmounts do
|
|
|
|
describe '.calculate' do
|
|
|
|
it 'param validation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { CalculateSuggestedAmounts.calculate(nil) }.to(raise_error do |error|
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
2019-07-30 21:29:24 +00:00
|
|
|
expect_validation_errors(error, [{ key: :amount, name: :required }, { key: :amount, name: :is_a }, { key: :amount, name: :min }, { key: :amount, name: :max }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { CalculateSuggestedAmounts.calculate('fffff') }.to(raise_error do |error|
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
2019-07-30 21:29:24 +00:00
|
|
|
expect_validation_errors(error, [{ key: :amount, name: :is_a }, { key: :amount, name: :min }, { key: :amount, name: :max }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '1 gives you 2-4' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(100)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([200, 300, 400])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '1.25 gives you 1, 2-4' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(125)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([100, 200, 300, 400])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '2 gives you 1, 3-5' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(200)
|
|
|
|
expect(result).to eq([100, 300, 400, 500])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '9 gives you 8, 10, 15,20' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(900)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([800, 1000, 1500, 2000])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '9.5 gives you 9, 10, 15,20' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(950)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([900, 1000, 1500, 2000])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '10 gives you 9, 15, 20, 25' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(1000)
|
|
|
|
expect(result).to eq([900, 1500, 2000, 2500])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '11 gives you 10, 15, 20, 25' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(1100)
|
|
|
|
expect(result).to eq([1000, 1500, 2000, 2500])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '35 gives you 30, 40, 45, 50' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(3500)
|
|
|
|
expect(result).to eq([3000, 4000, 4500, 5000])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '40 gives you 35, 45, 50, 75' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(4000)
|
|
|
|
expect(result).to eq([3500, 4500, 5000, 7500])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '43 gives you 40, 45, 50, 75' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(4300)
|
|
|
|
expect(result).to eq([4000, 4500, 5000, 7500])
|
|
|
|
end
|
|
|
|
|
|
|
|
it '47 gives you 45, 50, 75, 100' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(4700)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([4500, 5000, 7500, 10_000])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '47 gives you 45, 50, 75, 100' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(4700)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([4500, 5000, 7500, 10_000])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '50 gives you 45, 75, 100, 125' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(5000)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([4500, 7500, 10_000, 12_500])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '65 gives you 50, 75, 100, 125' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(6500)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([5000, 7500, 10_000, 12_500])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '75 gives you 50, 100, 125, 150' do
|
|
|
|
result = CalculateSuggestedAmounts.calculate(7500)
|
2019-07-30 21:29:24 +00:00
|
|
|
expect(result).to eq([5000, 10_000, 12_500, 15_000])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '999925 gives you 999900, 999950, 999975' do
|
2019-07-30 21:29:24 +00:00
|
|
|
result = CalculateSuggestedAmounts.calculate(99_992_500)
|
|
|
|
expect(result).to eq([99_990_000, 99_995_000, 99_997_500])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it '999950 gives you 999925, 999975' do
|
2019-07-30 21:29:24 +00:00
|
|
|
result = CalculateSuggestedAmounts.calculate(99_995_000)
|
|
|
|
expect(result).to eq([99_992_500, 99_997_500])
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|