-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathtax_rate_test.rb
More file actions
131 lines (117 loc) · 4.11 KB
/
Copy pathtax_rate_test.rb
File metadata and controls
131 lines (117 loc) · 4.11 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require 'unit_test_helper'
class TaxRateTest < Test::Unit::TestCase
include TestHelper
def setup
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end
should "have a primary key value of :name" do
assert_equal :name, Xeroizer::Record::TaxRate.primary_key_name
end
should "build and save a tax rate with components via PUT" do
@client.expects(:http_post).with { |client, url, body, extra_params|
url == "https://api.xero.com/api.xro/2.0/TaxRates" &&
body == expected_tax_rate_create_body
}.returns(tax_rate_create_successful_response)
tax_rate = @client.TaxRate.build(name: 'Test Tax Rate')
tax_rate.add_tax_component(name: 'Tax Component', rate: '10.0')
tax_rate.save
assert_equal "Test Tax Rate", tax_rate.name
assert_equal "ACTIVE", tax_rate.status
assert tax_rate.tax_type.present?
assert_equal 1, tax_rate.tax_components.size
tax_component = tax_rate.tax_components.first
assert_equal "Tax Component", tax_component.name
assert_equal "10.0", tax_component.rate.to_s
end
should "allow reading of the ReportTaxType" do
@client.expects(:http_get).with { |client, url, extra_params|
url == "https://api.xero.com/api.xro/2.0/TaxRates"
}.returns(tax_rate_get_response)
rates = @client.TaxRate.all
assert_equal "OUTPUT", rates.first.report_tax_type
end
should "allow GET with a filter on ReportTaxType" do
expected_url = "https://api.xero.com/api.xro/2.0/TaxRates"
expected_params = {:where => 'ReportTaxType=="OUTPUT"'}
@client.expects(:http_get).with { |client, url, extra_params|
url == expected_url && extra_params == expected_params
}.returns(tax_rate_get_response)
@client.TaxRate.all(where: {report_tax_type: 'OUTPUT'})
end
def expected_tax_rate_create_body
<<-EOS
<TaxRate>
<Name>Test Tax Rate</Name>
<TaxComponents>
<TaxComponent>
<Name>Tax Component</Name>
<Rate>10.0</Rate>
</TaxComponent>
</TaxComponents>
</TaxRate>
EOS
end
def tax_rate_create_successful_response
<<-EOS
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>d1ec84aa-189f-4e08-b78f-ad62cf4935f4</Id>
<Status>OK</Status>
<ProviderName>Xero API Previewer</ProviderName>
<DateTimeUTC>2014-07-02T19:26:53.3217153Z</DateTimeUTC>
<TaxRates>
<TaxRate>
<Name>Test Tax Rate</Name>
<TaxType>TAX018</TaxType>
<CanApplyToAssets>true</CanApplyToAssets>
<CanApplyToEquity>true</CanApplyToEquity>
<CanApplyToExpenses>true</CanApplyToExpenses>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>true</CanApplyToRevenue>
<DisplayTaxRate>10.0000</DisplayTaxRate>
<EffectiveRate>10.0000</EffectiveRate>
<Status>ACTIVE</Status>
<TaxComponents>
<TaxComponent>
<Name>Tax Component</Name>
<Rate>10.0000</Rate>
<IsCompound>false</IsCompound>
</TaxComponent>
</TaxComponents>
</TaxRate>
</TaxRates>
</Response>
EOS
end
def tax_rate_get_response
<<-EOS
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>53715e8f-f080-4cd8-a077-1100c0512d44</Id>
<Status>OK</Status>
<ProviderName>Xero API Previewer</ProviderName>
<DateTimeUTC>2014-10-28T15:39:58.5477531Z</DateTimeUTC>
<TaxRates>
<TaxRate>
<Name>Tax on Sales</Name>
<TaxType>OUTPUT</TaxType>
<ReportTaxType>OUTPUT</ReportTaxType>
<CanApplyToAssets>true</CanApplyToAssets>
<CanApplyToEquity>true</CanApplyToEquity>
<CanApplyToExpenses>true</CanApplyToExpenses>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>true</CanApplyToRevenue>
<DisplayTaxRate>9.2500</DisplayTaxRate>
<EffectiveRate>9.2500</EffectiveRate>
<Status>ACTIVE</Status>
<TaxComponents>
<TaxComponent>
<Name>Sales Tax</Name>
<Rate>9.2500</Rate>
<IsCompound>false</IsCompound>
</TaxComponent>
</TaxComponents>
</TaxRate>
</TaxRates>
</Response>
EOS
end
end