Skip to content

Commit

Permalink
Add Status to Tax Rates
Browse files Browse the repository at this point in the history
Updated the fixture to use the example provided in https://developer.xero.com/documentation/api/tax-rates
  • Loading branch information
steveh committed Jul 12, 2017
1 parent fc55955 commit a690f76
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 39 deletions.
1 change: 1 addition & 0 deletions lib/xero_gateway/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class TaxRate < BaseRecord
attributes({
"Name" => :string,
"TaxType" => :string,
"Status" => :string,
"CanApplyToAssets" => :boolean,
"CanApplyToEquity" => :boolean,
"CanApplyToExpenses" => :boolean,
Expand Down
16 changes: 8 additions & 8 deletions test/integration/get_tax_rates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

class GetTaxRatesTest < Test::Unit::TestCase
include TestHelper

def setup
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)

if STUB_XERO_CALLS
@gateway.xero_url = "DUMMY_URL"
@gateway.stubs(:http_get).with {|client, url, params| url =~ /TaxRates$/ }.returns(get_file_as_string("tax_rates.xml"))

@gateway.stubs(:http_get).with {|client, url, params| url =~ /TaxRates$/ }.returns(get_file_as_string("tax_rates.xml"))
end
end

def test_get_tax_rates
result = @gateway.get_tax_rates
assert result.success?
assert !result.response_xml.nil?

assert result.tax_rates.size > 0
assert_equal XeroGateway::TaxRate, result.tax_rates.first.class
assert_equal "GST on Expenses", result.tax_rates.first.name
assert_equal "15% GST on Expenses", result.tax_rates.first.name
end
end
end
61 changes: 37 additions & 24 deletions test/stub_responses/tax_rates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,61 @@
<DateTimeUTC>2009-10-04T03:29:54.6788414Z</DateTimeUTC>
<TaxRates>
<TaxRate>
<Name>GST on Expenses</Name>
<TaxType>INPUT</TaxType>
<Name>15% GST on Expenses</Name>
<TaxType>INPUT2</TaxType>
<CanApplyToAssets>true</CanApplyToAssets>
<CanApplyToEquity>true</CanApplyToEquity>
<CanApplyToExpenses>true</CanApplyToExpenses>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>false</CanApplyToRevenue>
<DisplayTaxRate>12.5000</DisplayTaxRate>
<EffectiveRate>12.5000</EffectiveRate>
<DisplayTaxRate>15.0000</DisplayTaxRate>
<EffectiveRate>15.0000</EffectiveRate>
<Status>ACTIVE</Status>
<TaxComponents>
<TaxComponent>
<Name>GST</Name>
<Rate>15.0000</Rate>
<IsCompound>false</IsCompound>
</TaxComponent>
</TaxComponents>
</TaxRate>
<TaxRate>
<Name>GST on Income</Name>
<TaxType>OUTPUT</TaxType>
<Name>15% GST on Income</Name>
<TaxType>OUTPUT2</TaxType>
<CanApplyToAssets>true</CanApplyToAssets>
<CanApplyToEquity>true</CanApplyToEquity>
<CanApplyToExpenses>false</CanApplyToExpenses>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>true</CanApplyToRevenue>
<DisplayTaxRate>12.5000</DisplayTaxRate>
<EffectiveRate>12.5000</EffectiveRate>
<DisplayTaxRate>15.0000</DisplayTaxRate>
<EffectiveRate>15.0000</EffectiveRate>
<Status>ACTIVE</Status>
<TaxComponents>
<TaxComponent>
<Name>GST</Name>
<Rate>15.0000</Rate>
<IsCompound>false</IsCompound>
</TaxComponent>
</TaxComponents>
</TaxRate>
<TaxRate>
<Name>No GST</Name>
<TaxType>NONE</TaxType>
<CanApplyToAssets>true</CanApplyToAssets>
<CanApplyToEquity>true</CanApplyToEquity>
<CanApplyToExpenses>true</CanApplyToExpenses>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>true</CanApplyToRevenue>
<DisplayTaxRate>0.0000</DisplayTaxRate>
<EffectiveRate>0.0000</EffectiveRate>
</TaxRate>
<TaxRate>
<Name>Zero Rated</Name>
<TaxType>ZERORATED</TaxType>
<Name>GST on Imports</Name>
<TaxType>GSTONIMPORTS</TaxType>
<CanApplyToAssets>false</CanApplyToAssets>
<CanApplyToEquity>false</CanApplyToEquity>
<CanApplyToExpenses>false</CanApplyToExpenses>
<CanApplyToLiabilities>false</CanApplyToLiabilities>
<CanApplyToRevenue>true</CanApplyToRevenue>
<CanApplyToLiabilities>true</CanApplyToLiabilities>
<CanApplyToRevenue>false</CanApplyToRevenue>
<DisplayTaxRate>0.0000</DisplayTaxRate>
<EffectiveRate>0.0000</EffectiveRate>
<Status>ACTIVE</Status>
<TaxComponents>
<TaxComponent>
<Name>GST</Name>
<Rate>0.0000</Rate>
<IsCompound>false</IsCompound>
</TaxComponent>
</TaxComponents>
</TaxRate>
</TaxRates>
</Response>
</Response>
15 changes: 8 additions & 7 deletions test/unit/tax_rate_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require File.join(File.dirname(__FILE__), '../test_helper.rb')

class TaxRateTest < Test::Unit::TestCase

# Tests that a tax rate can be converted into XML that Xero can understand, and then converted back to a tax rate
def test_build_and_parse_xml
tax_rate = create_test_tax_rate

# Generate the XML message
tax_rate_as_xml = tax_rate.to_xml

Expand All @@ -14,18 +14,19 @@ def test_build_and_parse_xml

# Build a new account from the XML
result_tax_rate = XeroGateway::TaxRate.from_xml(tax_rate_element)

# Check the account details
assert_equal tax_rate, result_tax_rate
end


private

def create_test_tax_rate
XeroGateway::TaxRate.new.tap do |tax_rate|
tax_rate.name = "GST on Expenses"
tax_rate.tax_type = "INPUT"
tax_rate.status = "ACTIVE"
tax_rate.can_apply_to_assets = true
tax_rate.can_apply_to_equity = true
tax_rate.can_apply_to_expenses = true
Expand All @@ -35,4 +36,4 @@ def create_test_tax_rate
tax_rate.effective_rate = 12.500
end
end
end
end

0 comments on commit a690f76

Please sign in to comment.