Permalink
Browse files

Added full tests for Company, Contacts & Projects API calls

  • Loading branch information...
1 parent 711f7f5 commit 7dce837c2568aedcfdc46f2b18484add881e58ea @aaronrussell committed Oct 22, 2009
View
@@ -17,6 +17,24 @@ def self.authenticate
end
end
+ # Company.invoice_timeline
+ # Company.tax_timeline
+
+ class Company
+ def self.invoice_timeline
+ InvoiceTimeline.find :all, :from => '/company/invoice_timeline.xml'
+ end
+ def self.tax_timeline
+ TaxTimeline.find :all, :from => '/company/tax_timeline.xml'
+ end
+ end
+ class InvoiceTimeline < Base
+ self.prefix = '/company/'
+ end
+ class TaxTimeline < Base
+ self.prefix = '/company/'
+ end
+
# Find contacts
#
# Contact.find :all # find all contacts
@@ -45,6 +63,7 @@ def self.authenticate
#
class Contact < Base
+
end
# Find projects
@@ -175,16 +194,19 @@ def self.find(*args)
end
-# class ActiveResource::Connection
-# def http
-# http = Net::HTTP.new(@site.host, @site.port)
-# http.use_ssl = @site.is_a?(URI::HTTPS)
-# http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
-# http.read_timeout = @timeout if @timeout
-# #Here's the addition that allows you to see the output
-# http.set_debug_output $stderr
-# return http
-# end
-# end
+ ####################################################################################
+
+
+ class ActiveResource::Connection
+ def http
+ http = Net::HTTP.new(@site.host, @site.port)
+ http.use_ssl = @site.is_a?(URI::HTTPS)
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
+ http.read_timeout = @timeout if @timeout
+ #Here's the addition that allows you to see the output
+ http.set_debug_output $stderr
+ return http
+ end
+ end
end
View
@@ -0,0 +1,33 @@
+require 'test_helper'
+
+class CompanyTest < Test::Unit::TestCase
+
+ fake_it_all
+
+ context "Invoice timeline" do
+ setup do
+ @inv_timeline = Company.invoice_timeline
+ end
+ should "return an array" do
+ assert @inv_timeline.is_a? Array
+ end
+ should "return invoice timeline items" do
+ assert_equal 12, @inv_timeline.size
+ assert @inv_timeline.first.is_a? InvoiceTimeline
+ end
+ end
+
+ context "Tax timeline" do
+ setup do
+ @tax_timeline = Company.tax_timeline
+ end
+ should "return an array" do
+ assert @tax_timeline.is_a? Array
+ end
+ should "return projects" do
+ assert_equal 3, @tax_timeline.size
+ assert @tax_timeline.first.is_a? TaxTimeline
+ end
+ end
+
+end
View
@@ -0,0 +1,62 @@
+require 'test_helper'
+
+class ContactTest < Test::Unit::TestCase
+
+ fake_it_all
+
+ context "Contact class" do
+ should "has correct collection path" do
+ assert_equal '/contacts.xml', Contact.collection_path
+ end
+ should "has correct element path" do
+ assert_equal '/contacts/first.xml', Contact.element_path(:first)
+ assert_equal '/contacts/1.xml', Contact.element_path(1)
+ end
+ end
+
+ context "Contacts" do
+ setup do
+ @contacts = Contact.find :all
+ end
+ should "return an array" do
+ assert @contacts.is_a? Array
+ end
+ should "return Contacts" do
+ assert_equal 16, @contacts.size
+ assert @contacts.first.is_a? Contact
+ end
+ end
+
+ context "Contact" do
+ setup do
+ @contact = Contact.find 27309
+ end
+ should "return a Contact" do
+ assert @contact.is_a? Contact
+ end
+ should "update and save" do
+ @contact.last_name = 'Roberts'
+ assert @contact.save
+ end
+ should "be destroyed" do
+ assert @contact.destroy
+ end
+ end
+
+ #TODO - Add test for invalid resource
+ # Need support from fakeweb in order to achieve this
+
+ context "New Contact" do
+ setup do
+ params = {
+ :first_name => 'Fred',
+ :last_name => 'Bloggs'
+ }
+ @new_contact = Contact.new params
+ end
+ should "validate and save" do
+ assert @new_contact.save_with_validation
+ end
+ end
+
+end
View
@@ -2,36 +2,66 @@
class ProjectTest < Test::Unit::TestCase
- def setup
- fake_it_all
- @projects = Project.find :all
- @project = Project.find 17820
- end
+ fake_it_all
context "Project class" do
should "have correct collection path" do
- assert_equal Project.collection_path, '/projects.xml'
+ assert_equal '/projects.xml', Project.collection_path
end
should "have correct element path" do
- assert_equal Project.element_path(:first), '/projects/first.xml'
- assert_equal Project.element_path(1), '/projects/1.xml'
+ assert_equal '/projects/first.xml', Project.element_path(:first)
+ assert_equal '/projects/1.xml', Project.element_path(1)
end
end
context "Projects" do
+ setup do
+ @projects = Project.find :all
+ end
should "return an array" do
assert @projects.is_a? Array
end
should "return projects" do
assert_equal 5, @projects.size
assert @projects.first.is_a? Project
- end
+ end
end
context "Project" do
+ setup do
+ @project = Project.find 17820
+ end
should "return a Project" do
assert @project.is_a? Project
end
+ should "update and save" do
+ @project.name = 'Rebranding project'
+ assert @project.save
+ end
+ should "be destroyed" do
+ assert @project.destroy
+ end
end
+
+ #TODO - Add test for invalid resource
+ # Need support from fakeweb in order to achieve this
+
+ context "New Project" do
+ setup do
+ params = {
+ :contact_id => 27309,
+ :name => 'Webdesign project',
+ :payment_terms_in_days => 30,
+ :billing_basis => 7.5,
+ :budget_units => 'Hours',
+ :status => 'Active'
+ }
+ @project = Project.new params
+ end
+ should "validate and save" do
+ assert @project.save_with_validation
+ end
+ end
+
end
@@ -0,0 +1,91 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<invoice-timeline-items type="array">
+ <invoice_timeline_item>
+ <reference>INV0024</reference>
+ <summary>Payment: INV0024: &#163;155.00 received</summary>
+ <description>Spectrum Healthcare</description>
+ <dated_on>2009-07%dT00:00Z</dated_on>
+ <amount>155.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0025</reference>
+ <summary>Payment: INV0025: &#163;2,420.00 received</summary>
+ <description>The Good Folk</description>
+ <dated_on>2009-07%dT00:00Z</dated_on>
+ <amount>2420.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0026</reference>
+ <summary>Payment: INV0026: &#163;1,000.00 received</summary>
+ <description>Spectrum Healthcare</description>
+ <dated_on>2009-08%dT00:00Z</dated_on>
+ <amount>1000.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0027</reference>
+ <summary>Payment: INV0027: &#163;2,275.00 received</summary>
+ <description>Economic and Social Research Council</description>
+ <dated_on>2009-08%dT00:00Z</dated_on>
+ <amount>2275.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0028</reference>
+ <summary>Payment: INV0028: &#163;80.00 received</summary>
+ <description>The Good Folk</description>
+ <dated_on>2009-08%dT00:00Z</dated_on>
+ <amount>80.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0029</reference>
+ <summary>Payment: INV0029: &#163;1,012.50 received</summary>
+ <description>Spectrum Healthcare</description>
+ <dated_on>2009-09%dT00:00Z</dated_on>
+ <amount>1012.5</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0031</reference>
+ <summary>Payment: INV0031: &#163;70.00 received</summary>
+ <description>Economic and Social Research Council</description>
+ <dated_on>2009-09%dT00:00Z</dated_on>
+ <amount>70.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0032</reference>
+ <summary>Payment: INV0032: &#163;1,920.00 received</summary>
+ <description>icomplete</description>
+ <dated_on>2009-09%dT00:00Z</dated_on>
+ <amount>1920.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0033</reference>
+ <summary>Payment: INV0033: &#163;3,000.00 received</summary>
+ <description>Inbox Digital: Shop Direct NDR Webapp</description>
+ <dated_on>2009-10%dT00:00Z</dated_on>
+ <amount>3000.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0030</reference>
+ <summary>Due: INV0030: &#163;50.00</summary>
+ <description>Oxfordshire PTC</description>
+ <dated_on>2009-09%dT00:00Z</dated_on>
+ <amount>50.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0034</reference>
+ <summary>Due: INV0034: &#163;670.00</summary>
+ <description>The Good Folk</description>
+ <dated_on>2009-10%dT00:00Z</dated_on>
+ <amount>670.0</amount>
+ </invoice_timeline_item>
+ <invoice_timeline_item>
+ <reference>INV0035</reference>
+ <summary>Due: INV0035: &#163;500.00</summary>
+ <description>ClubBuzz: ClubBuzz application design and development</description>
+ <dated_on>2009-10%dT00:00Z</dated_on>
+ <amount>500.0</amount>
+ </invoice_timeline_item>
+</invoice-timeline-items>
@@ -0,0 +1,28 @@
+HTTP/1.1 200 OK
+Status: 200
+Content-Type: application/xml; charset=utf-8
+
+<?xml version="1.0" encoding="UTF-8"?>
+<timeline-items type="array">
+ <timeline_item>
+ <description>Corporation Tax, year ending 05 Apr 07*</description>
+ <nature>Submission Due</nature>
+ <dated_on>Sat Apr 05 00:00:00 UTC 2008</dated_on>
+ <amount_due></amount_due>
+ <is_personal>false</is_personal>
+ </timeline_item>
+ <timeline_item>
+ <description>Corporation Tax, year ending 05 Apr 08*</description>
+ <nature>Payment Due</nature>
+ <dated_on>Tue Jan 06 00:00:00 UTC 2009</dated_on>
+ <amount_due>190.14</amount_due>
+ <is_personal>false</is_personal>
+ </timeline_item>
+ <timeline_item>
+ <description>Corporation Tax, year ending 05 Apr 08*</description>
+ <nature>Submission Due</nature>
+ <dated_on>Sun Apr 05 00:00:00 UTC 2009</dated_on>
+ <amount_due></amount_due>
+ <is_personal>false</is_personal>
+ </timeline_item>
+</timeline-items>
Oops, something went wrong. Retry.

0 comments on commit 7dce837

Please sign in to comment.