test/unit/models/invoice_test.rb in xeroizer-0.3.5 vs test/unit/models/invoice_test.rb in xeroizer-0.4.0

- old
+ new

@@ -1,16 +1,32 @@ -require File.join(File.dirname(__FILE__), '../../test_helper.rb') +require 'test_helper' class InvoiceTest < Test::Unit::TestCase include TestHelper def setup @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) mock_api('Invoices') @invoice = @client.Invoice.first end - + + def build_valid_authorised_invoice + @client.Invoice.build({ + :type => "ACCREC", + :contact => { :name => "ABC Limited" }, + :status => "AUTHORISED", + :date => Date.today, + :due_date => Date.today, + :line_items => [{ + :description => "Consulting services as agreed", + :quantity => 0.005, + :unit_amount => 1, + :account_code => 200 + }] + }) + end + context "invoice types" do should "have helpers to determine invoice type" do @invoice.type = 'ACCREC' assert_equal(true, @invoice.accounts_receivable?) @@ -43,11 +59,11 @@ assert_equal(invoice.attributes[:sub_total], invoice.sub_total) assert_equal(invoice.attributes[:total_tax], invoice.total_tax) assert_equal(invoice.attributes[:total], invoice.total) end end - + end context "invoice validations" do should "build an invalid invoice if there are no attributes" do @@ -63,24 +79,34 @@ invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" }, :status => "AUTHORISED" assert_equal(false, invoice.valid?) end should "build a valid AUTHORISED invoice with complete attributes" do - invoice = @client.Invoice.build({ - :type => "ACCREC", - :contact => { :name => "ABC Limited" }, - :status => "AUTHORISED", - :date => Date.today, - :due_date => Date.today, - :line_items => [{ - :description => "Consulting services as agreed", - :quantity => 5, - :unit_amount => 120, - :account_code => 200 - }] - }) + invoice = build_valid_authorised_invoice assert_equal(true, invoice.valid?) end end -end \ No newline at end of file + context "line items" do + + should "round line item amounts to two decimal places" do + invoice = build_valid_authorised_invoice + assert_equal(0.01, invoice.line_items.first.line_amount) + end + + end + + context "contact shortcuts" do + + should "have valid #contact_name and #contact_id without downloading full invoice" do + invoices = @client.Invoice.all + invoices.each do |invoice| + assert_not_equal("", invoice.contact_name) + assert_not_equal("", invoice.contact_id) + assert_equal(false, invoice.complete_record_downloaded?) + end + end + + end + +end