Skip to content

Commit

Permalink
Remove deprecated apps types (#542)
Browse files Browse the repository at this point in the history
* tests are running successfully now

* removed deprecated private, public, partner apps and removed/upgrade oauth1 related tests

* version bump 3.0.0

* invoice change to fix issue #395

* resolves issue #442

* added gdpr request status for contacts to resolve #441

* fixed issue #448

* invoice requires date, added to test

* tests passing
  • Loading branch information
rjaus authored Sep 27, 2021
1 parent c31755d commit 1b805ef
Show file tree
Hide file tree
Showing 44 changed files with 101 additions and 607 deletions.
273 changes: 56 additions & 217 deletions README.md

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions lib/xeroizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,5 @@
require 'xeroizer/response'

require 'xeroizer/generic_application'
require 'xeroizer/public_application'
require 'xeroizer/private_application'
require 'xeroizer/partner_application'
require 'xeroizer/oauth2_application'
require 'xeroizer/payroll_application'
3 changes: 2 additions & 1 deletion lib/xeroizer/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Contact < Base
CONTACT_STATUS = {
'ACTIVE' => 'Active',
'DELETED' => 'Deleted',
'ARCHIVED' => 'Archived'
'ARCHIVED' => 'Archived',
'GDPRREQUEST' => 'GDPR Request'
} unless defined?(CONTACT_STATUS)

include Attachment::Extensions
Expand Down
3 changes: 2 additions & 1 deletion lib/xeroizer/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class Invoice < Base
has_many :credit_notes
has_many :prepayments

validates_presence_of :date, :due_date, :unless => :new_record?
validates_presence_of :date, :if => :new_record?
validates_presence_of :due_date, :if => :approved?
validates_inclusion_of :type, :in => INVOICE_TYPES
validates_inclusion_of :status, :in => INVOICE_STATUSES, :unless => :new_record?
validates_inclusion_of :line_amount_types, :in => LINE_AMOUNT_TYPES, :unless => :new_record?
Expand Down
2 changes: 1 addition & 1 deletion lib/xeroizer/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def line_amount(summary_only = false)
if quantity && unit_amount
total = coerce_numeric(quantity) * coerce_numeric(unit_amount)
if discount_rate.nonzero?
BigDecimal((total * ((100 - discount_rate) / 100)).to_s).round(2)
BigDecimal((total * ((100 - discount_rate.to_f) / 100)).to_s).round(2)
elsif discount_amount
BigDecimal((total - discount_amount).to_s).round(2)
else
Expand Down
1 change: 1 addition & 0 deletions lib/xeroizer/models/tax_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TaxComponent < Base
string :name
decimal :rate
boolean :is_compound
boolean :is_non_recoverable
end
end
end
52 changes: 0 additions & 52 deletions lib/xeroizer/partner_application.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/xeroizer/private_application.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/xeroizer/public_application.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/xeroizer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Xeroizer
VERSION = "3.0.0-beta".freeze
VERSION = "3.0.0".freeze
end
2 changes: 1 addition & 1 deletion test/acceptance/about_fetching_bank_transactions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AboutFetchingBankTransactions < Test::Unit::TestCase
it "has the limited set of attributes" do
keys = [:line_amount_types, :contact, :date, :status, :updated_date_utc,
:currency_code, :bank_transaction_id, :bank_account, :type, :reference,
:is_reconciled]
:is_reconciled, :has_attachments]
assert_equal(keys, @the_first_bank_transaction.attributes.keys)
end

Expand Down
24 changes: 1 addition & 23 deletions test/acceptance/acceptance_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
module AcceptanceTestHelpers
def self.oauth_client
config = load_config_from_file || load_config_from_env
Xeroizer::PrivateApplication.new(config.consumer_key, config.consumer_secret, config.key_file)
end

def self.oauth2_client
config = self.load_oauth2_config_from_env
Xeroizer::OAuth2Application.new(
Expand All @@ -14,22 +9,6 @@ def self.oauth2_client
)
end

def self.load_config_from_file
the_file_name = File.join(File.dirname(__FILE__), '..', '..', '.oauth')

return nil unless File.exist? the_file_name

Xeroizer::OAuthConfig.load IO.read the_file_name
end

def self.load_config_from_env
raise "No CONSUMER_KEY environment variable specified." unless ENV["CONSUMER_KEY"]
raise "No CONSUMER_SECRET environment variable specified." unless ENV["CONSUMER_SECRET"]
raise "No PRIVATE_KEY_PATH environment variable specified." unless ENV["PRIVATE_KEY_PATH"]
raise "The file <#{ENV["PRIVATE_KEY_PATH"]}> does not exist." unless File.exist?(ENV["PRIVATE_KEY_PATH"])
Xeroizer::OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["PRIVATE_KEY_PATH"]
end

def self.load_oauth2_config_from_env
raise "No XERO_CLIENT_ID environment variable specified." unless ENV["XERO_CLIENT_ID"]
raise "No XERO_CLIENT_SECRET environment variable specified." unless ENV["XERO_CLIENT_SECRET"]
Expand All @@ -47,8 +26,7 @@ module AcceptanceTest
class << self
def included(klass)
klass.class_eval do
def self.it_works_using_oauth1_and_oauth2(&block)
instance_exec(AcceptanceTestHelpers.oauth_client, 'oauth', &block)
def self.it_works_using_oauth2(&block)
instance_exec(AcceptanceTestHelpers.oauth2_client, 'oauth2', &block)
end

Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/bank_transfer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class BankTransfer < Test::Unit::TestCase
include AcceptanceTest

it_works_using_oauth1_and_oauth2 do |client, client_type|
it_works_using_oauth2 do |client, client_type|
can "create a bank for #{client_type}" do
all_accounts = client.Account.all
@from_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.first
Expand Down
6 changes: 4 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ module TestHelper
CONSUMER_SECRET = ENV["CONSUMER_SECRET"] || "fake_secret" unless defined?(CONSUMER_SECRET)
PRIVATE_KEY_PATH = ENV["PRIVATE_KEY_PATH"] || "fake_key" unless defined?(PRIVATE_KEY_PATH)

CLIENT_ID = ENV["CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID)
CLIENT_SECRET = ENV["CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET)
CLIENT_ID = ENV["XERO_CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID)
CLIENT_SECRET = ENV["XERO_CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET)
ACCESS_TOKEN = ENV["XERO_ACCESS_TOKEN"] || "fake_access_token" unless defined?(ACCESS_TOKEN)
TENANT_ID = ENV["XERO_TENANT_ID"] || "fake_tenant_id" unless defined?(TENANT_ID)

# Helper constant for checking regex
GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
Expand Down
15 changes: 0 additions & 15 deletions test/unit/generic_application_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ class GenericApplicationTest < Test::Unit::TestCase
end
end

context "oauth" do
setup do
client = Xeroizer::OAuth.new(CONSUMER_KEY, CONSUMER_SECRET, @options)
@application = Xeroizer::GenericApplication.new(client, @options)
end

should "pass default headers" do
assert_equal(@headers, @application.default_headers)
end

should "pass unitdp value" do
assert_equal(@unitdp, @application.unitdp)
end
end

context "oauth 2" do
setup do
client = Xeroizer::OAuth2.new(CLIENT_ID, CLIENT_SECRET, @options)
Expand Down
14 changes: 1 addition & 13 deletions test/unit/http_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@ class HttpTest < UnitTestCase
@uri = "https://api.xero.com/path"
end

context "default_headers" do
setup do
@headers = { "User-Agent" => "Xeroizer/2.15.5" }
@application = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :default_headers => @headers)
end

should "recognize default_headers" do
# Xeroizer::OAuth.any_instance.expects(:get).with("/test", has_entry(@headers)).returns(stub(:plain_body => "", :code => "200"))
# @application.http_get(@application.client, "http://example.com/test")
end
end

context "errors" do
setup do
@application = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@application = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID, access_token: ACCESS_TOKEN)
end

context "400" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AddressTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
@contact = @client.Contact.build
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ContactTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end

context "contact validators" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/credit_note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CreditNoteTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
mock_api("CreditNotes")
@credit_note = @client.CreditNote.first
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/employee_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class EmployeeTest < Test::Unit::TestCase
include Xeroizer::Record

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
@employee = @client.Employee.build

@employee.employee_id = 'GUID'
Expand Down
4 changes: 2 additions & 2 deletions test/unit/models/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class InvoiceTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
mock_api('Invoices')
@invoice = @client.Invoice.first
end
Expand Down Expand Up @@ -59,7 +59,7 @@ def build_valid_authorised_invoice
end

should "build a valid DRAFT invoice with minimal attributes" do
invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" }
invoice = @client.Invoice.build :type => "ACCREC", :date => Date.today, :contact => { :name => "ABC Limited" }
assert_equal(true, invoice.valid?)
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/journal_line_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class JournalLineTest < Test::Unit::TestCase
include Xeroizer::Record

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end

it "journal_line tracking specified correctly" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/journal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class JournalTest < Test::Unit::TestCase
include Xeroizer::Record

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)

@journal = @client.Journal.build
@journal.journal_id = "0d926df3-459f-4264-a3a3-49ac065eb0ed"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/line_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LineItemTest < Test::Unit::TestCase
include Xeroizer::Record

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end

it "line_item tracking specified correctly" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/manual_journal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ManualJournalTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
mock_api('ManualJournals')
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class OrganisationTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end

context "sales_tax_basis_validations" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/payment_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PaymentServiceTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
end

context "response parsing" do
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/phone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PhoneTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
@contact = @client.Contact.build

end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/prepayment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PrepaymentTest < Test::Unit::TestCase
include TestHelper

def setup
@client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
mock_api("Prepayments")
@prepayment = @client.Prepayment.first
end
Expand Down
Loading

0 comments on commit 1b805ef

Please sign in to comment.