-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_taxes_spec.rb
More file actions
71 lines (63 loc) · 2.07 KB
/
calculate_taxes_spec.rb
File metadata and controls
71 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
require_relative 'calculate_taxes'
require_relative 'line_item'
RSpec.describe ServiceFunctions::HandleErrors::OkError::CalculateTaxes, type: :service_function do
describe '.call' do
subject(:when_calculating_taxes) do
described_class.call(line_item_with_policy)
end
context 'given line item with policy' do
let(:line_item_with_policy) do
ServiceFunctions::HandleErrors::OkError::LineItemWithPolicy.new(
amount: 100,
line_item_key: 'salary',
tax_policy: 'TAXABLE'
)
end
it 'then should successfully calculate taxes and return CalculatedLineItem' do
expect(when_calculating_taxes)
.to(match([:ok, be_instance_of(ServiceFunctions::HandleErrors::OkError::CalculatedLineItem)]))
end
end
context 'given line item with unknown policy' do
let(:line_item_with_policy) do
ServiceFunctions::HandleErrors::OkError::LineItemWithPolicy.new(
amount: 100,
line_item_key: 'salary',
tax_policy: 'some-random-policy'
)
end
it 'then should return error with reason' do
expect(when_calculating_taxes).to(match([:error, be_instance_of(String)]))
end
end
[
nil,
123,
'Sooome',
'',
ServiceFunctions::HandleErrors::OkError::LineItemWithPolicy.new(
amount: nil,
line_item_key: 'salary',
tax_policy: 'TAXABLE'
),
ServiceFunctions::HandleErrors::OkError::LineItemWithPolicy.new(
amount: [],
line_item_key: 'salary',
tax_policy: 'EXEMPT'
),
ServiceFunctions::HandleErrors::OkError::LineItemWithPolicy.new(
amount: 'asdasdasd',
line_item_key: 'salary',
tax_policy: 'TAXABLE'
)
].each do |invalid_input|
context 'given invalid input' do
let(:line_item_with_policy) { invalid_input }
it 'then should return error with reason' do
expect(when_calculating_taxes).to(match([:error, be_instance_of(String)]))
end
end
end
end
end