freeagent_api 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/README.rdoc +194 -22
- data/Rakefile +4 -5
- data/VERSION +1 -1
- data/freeagent_api.gemspec +46 -17
- data/lib/freeagent_api.rb +78 -135
- data/test/authentication_test.rb +13 -0
- data/test/company_test.rb +33 -0
- data/test/contact_test.rb +62 -0
- data/test/invoice_item_test.rb +66 -0
- data/test/invoice_test.rb +70 -0
- data/test/project_test.rb +106 -0
- data/test/stubs/company/invoice_timeline +91 -0
- data/test/stubs/company/tax_timeline +28 -0
- data/test/stubs/contacts/find_all +391 -0
- data/test/stubs/contacts/find_single +29 -0
- data/test/stubs/http/200 +3 -0
- data/test/stubs/http/201 +4 -0
- data/test/stubs/invoice_items/find_all +40 -0
- data/test/stubs/invoice_items/find_single +15 -0
- data/test/stubs/invoices/find_all +239 -0
- data/test/stubs/invoices/find_single +57 -0
- data/test/stubs/projects/find_all +92 -0
- data/test/stubs/projects/find_single +22 -0
- data/test/stubs/projects/invoices +92 -0
- data/test/stubs/projects/timeslips +223 -0
- data/test/stubs/tasks/find_all +42 -0
- data/test/stubs/tasks/find_single +10 -0
- data/test/stubs/timeslips/find_all +52 -0
- data/test/stubs/timeslips/find_single +14 -0
- data/test/task_test.rb +60 -0
- data/test/test_helper.rb +83 -0
- data/test/timeslip_test.rb +62 -0
- metadata +41 -19
- data/test/freeagent_api_test.rb +0 -7
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ContactTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fake_it_all
|
6
|
+
|
7
|
+
context "Contact class" do
|
8
|
+
should "has correct collection path" do
|
9
|
+
assert_equal '/contacts.xml', Contact.collection_path
|
10
|
+
end
|
11
|
+
should "has correct element path" do
|
12
|
+
assert_equal '/contacts/first.xml', Contact.element_path(:first)
|
13
|
+
assert_equal '/contacts/1.xml', Contact.element_path(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Contacts" do
|
18
|
+
setup do
|
19
|
+
@contacts = Contact.find :all
|
20
|
+
end
|
21
|
+
should "return an array" do
|
22
|
+
assert @contacts.is_a? Array
|
23
|
+
end
|
24
|
+
should "return Contacts" do
|
25
|
+
assert_equal 16, @contacts.size
|
26
|
+
assert @contacts.first.is_a? Contact
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Contact" do
|
31
|
+
setup do
|
32
|
+
@contact = Contact.find 27309
|
33
|
+
end
|
34
|
+
should "return a Contact" do
|
35
|
+
assert @contact.is_a? Contact
|
36
|
+
end
|
37
|
+
should "update and save" do
|
38
|
+
@contact.last_name = 'Roberts'
|
39
|
+
assert @contact.save
|
40
|
+
end
|
41
|
+
should "be destroyed" do
|
42
|
+
assert @contact.destroy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#TODO - Add test for invalid resource
|
47
|
+
# Need support from fakeweb in order to achieve this
|
48
|
+
|
49
|
+
context "New Contact" do
|
50
|
+
setup do
|
51
|
+
params = {
|
52
|
+
:first_name => 'Fred',
|
53
|
+
:last_name => 'Bloggs'
|
54
|
+
}
|
55
|
+
@contact = Contact.new params
|
56
|
+
end
|
57
|
+
should "validate and save" do
|
58
|
+
assert @contact.save_with_validation
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InvoiceItemTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fake_it_all
|
6
|
+
|
7
|
+
context "InvoiceItem class" do
|
8
|
+
should "has correct collection path" do
|
9
|
+
assert_equal '/invoices/1000/invoice_items.xml', InvoiceItem.collection_path(:invoice_id => 1000)
|
10
|
+
end
|
11
|
+
should "has correct element path" do
|
12
|
+
assert_equal '/invoices/1000/invoice_items/first.xml', InvoiceItem.element_path(:first, :invoice_id => 1000)
|
13
|
+
assert_equal '/invoices/1000/invoice_items/1.xml', InvoiceItem.element_path(1, :invoice_id => 1000)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Invoice Items" do
|
18
|
+
setup do
|
19
|
+
@invoice_items = InvoiceItem.find :all, :params => {:invoice_id => 73867}
|
20
|
+
end
|
21
|
+
should "return an array" do
|
22
|
+
assert @invoice_items.is_a? Array
|
23
|
+
end
|
24
|
+
should "return Invoices" do
|
25
|
+
assert_equal 3, @invoice_items.size
|
26
|
+
assert @invoice_items.first.is_a? InvoiceItem
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Invoice Item" do
|
31
|
+
setup do
|
32
|
+
@invoice_item = InvoiceItem.find 169399, :params => {:invoice_id => 73867}
|
33
|
+
end
|
34
|
+
should "return a Invoice Item" do
|
35
|
+
assert @invoice_item.is_a? InvoiceItem
|
36
|
+
end
|
37
|
+
should "update and save" do
|
38
|
+
@invoice_item.description = 'Create wireframe templates'
|
39
|
+
assert @invoice_item.save
|
40
|
+
end
|
41
|
+
should "be destroyed" do
|
42
|
+
assert @invoice_item.destroy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#TODO - Add test for invalid resource
|
47
|
+
# Need support from fakeweb in order to achieve this
|
48
|
+
|
49
|
+
context "New Invoice Item" do
|
50
|
+
setup do
|
51
|
+
params = {
|
52
|
+
:item_type => 'Hours',
|
53
|
+
:description => 'Create wireframe templates',
|
54
|
+
:quantity => '12',
|
55
|
+
:price => '50',
|
56
|
+
:sales_tax_rate => '15',
|
57
|
+
:invoice_id => '73867'
|
58
|
+
}
|
59
|
+
@invoice_item = InvoiceItem.new params
|
60
|
+
end
|
61
|
+
should "validate and save" do
|
62
|
+
assert @invoice_item.save_with_validation
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InvoiceTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fake_it_all
|
6
|
+
|
7
|
+
context "Invoice class" do
|
8
|
+
should "has correct collection path" do
|
9
|
+
assert_equal '/invoices.xml', Invoice.collection_path
|
10
|
+
end
|
11
|
+
should "has correct element path" do
|
12
|
+
assert_equal '/invoices/first.xml', Invoice.element_path(:first)
|
13
|
+
assert_equal '/invoices/1.xml', Invoice.element_path(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Invoices" do
|
18
|
+
setup do
|
19
|
+
@invoices = Invoice.find :all
|
20
|
+
end
|
21
|
+
should "return an array" do
|
22
|
+
assert @invoices.is_a? Array
|
23
|
+
end
|
24
|
+
should "return Invoices" do
|
25
|
+
assert_equal 7, @invoices.size
|
26
|
+
assert @invoices.first.is_a? Invoice
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Invoice" do
|
31
|
+
setup do
|
32
|
+
@invoice = Invoice.find 73867
|
33
|
+
end
|
34
|
+
should "return a Invoice" do
|
35
|
+
assert @invoice.is_a? Invoice
|
36
|
+
end
|
37
|
+
should "update and save" do
|
38
|
+
@invoice.last_name = 'Roberts'
|
39
|
+
assert @invoice.save
|
40
|
+
end
|
41
|
+
should "be destroyed" do
|
42
|
+
assert @invoice.destroy
|
43
|
+
end
|
44
|
+
should "change status" do
|
45
|
+
assert @invoice.mark_as_draft
|
46
|
+
assert @invoice.mark_as_sent
|
47
|
+
assert @invoice.mark_as_cancelled
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#TODO - Add test for invalid resource
|
52
|
+
# Need support from fakeweb in order to achieve this
|
53
|
+
|
54
|
+
context "New Invoice" do
|
55
|
+
setup do
|
56
|
+
params = {
|
57
|
+
:contact_id => '29899',
|
58
|
+
:project_id => '21445',
|
59
|
+
:dated_on => '2009-10-26T00:00:00Z',
|
60
|
+
:reference => 'INV100',
|
61
|
+
:status => 'Draft'
|
62
|
+
}
|
63
|
+
@invoice = Invoice.new params
|
64
|
+
end
|
65
|
+
should "validate and save" do
|
66
|
+
assert @invoice.save_with_validation
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ProjectTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fake_it_all
|
6
|
+
|
7
|
+
context "Project class" do
|
8
|
+
should "have correct collection path" do
|
9
|
+
assert_equal '/projects.xml', Project.collection_path
|
10
|
+
end
|
11
|
+
should "have correct element path" do
|
12
|
+
assert_equal '/projects/first.xml', Project.element_path(:first)
|
13
|
+
assert_equal '/projects/1.xml', Project.element_path(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Projects" do
|
18
|
+
setup do
|
19
|
+
@projects = Project.find :all
|
20
|
+
end
|
21
|
+
should "return an array" do
|
22
|
+
assert @projects.is_a? Array
|
23
|
+
end
|
24
|
+
should "return projects" do
|
25
|
+
assert_equal 5, @projects.size
|
26
|
+
assert @projects.first.is_a? Project
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "Project" do
|
31
|
+
setup do
|
32
|
+
@project = Project.find 17820
|
33
|
+
end
|
34
|
+
should "return a Project" do
|
35
|
+
assert @project.is_a? Project
|
36
|
+
end
|
37
|
+
should "update and save" do
|
38
|
+
@project.name = 'Rebranding project'
|
39
|
+
assert @project.save
|
40
|
+
end
|
41
|
+
should "be destroyed" do
|
42
|
+
assert @project.destroy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#TODO - Add test for invalid resource
|
47
|
+
# Need support from fakeweb in order to achieve this
|
48
|
+
|
49
|
+
context "New Project" do
|
50
|
+
setup do
|
51
|
+
params = {
|
52
|
+
:contact_id => 27309,
|
53
|
+
:name => 'Webdesign project',
|
54
|
+
:payment_terms_in_days => 30,
|
55
|
+
:billing_basis => 7.5,
|
56
|
+
:budget_units => 'Hours',
|
57
|
+
:status => 'Active'
|
58
|
+
}
|
59
|
+
@project = Project.new params
|
60
|
+
end
|
61
|
+
should "validate and save" do
|
62
|
+
assert @project.save_with_validation
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "Nested Invoices" do
|
67
|
+
setup do
|
68
|
+
@project = Project.find 17820
|
69
|
+
@invoices = @project.invoices
|
70
|
+
@invoice = @invoices.first
|
71
|
+
end
|
72
|
+
should "be Invoices" do
|
73
|
+
assert @invoices.is_a? Array
|
74
|
+
assert_equal 1, @invoices.size
|
75
|
+
assert @invoices.first.is_a? Invoice
|
76
|
+
end
|
77
|
+
should "be updateable" do
|
78
|
+
@invoice.comments = "This is a test comment"
|
79
|
+
assert @invoice.save
|
80
|
+
end
|
81
|
+
should "be deletable" do
|
82
|
+
assert @invoice.destroy
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "Nested Timeslips" do
|
87
|
+
setup do
|
88
|
+
@project = Project.find 17820
|
89
|
+
@timeslips = @project.timeslips
|
90
|
+
@timeslip = @timeslips.first
|
91
|
+
end
|
92
|
+
should "be Timeslips" do
|
93
|
+
assert @timeslips.is_a? Array
|
94
|
+
assert_equal 24, @timeslips.size
|
95
|
+
assert @timeslips.first.is_a? Timeslip
|
96
|
+
end
|
97
|
+
should "be updateable" do
|
98
|
+
@timeslip.hours = '1'
|
99
|
+
assert @timeslip.save
|
100
|
+
end
|
101
|
+
should "be deletable" do
|
102
|
+
assert @timeslip.destroy
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Status: 200
|
3
|
+
Content-Type: application/xml; charset=utf-8
|
4
|
+
|
5
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
6
|
+
<invoice-timeline-items type="array">
|
7
|
+
<invoice_timeline_item>
|
8
|
+
<reference>INV0024</reference>
|
9
|
+
<summary>Payment: INV0024: £155.00 received</summary>
|
10
|
+
<description>Spectrum Healthcare</description>
|
11
|
+
<dated_on>2009-07%dT00:00Z</dated_on>
|
12
|
+
<amount>155.0</amount>
|
13
|
+
</invoice_timeline_item>
|
14
|
+
<invoice_timeline_item>
|
15
|
+
<reference>INV0025</reference>
|
16
|
+
<summary>Payment: INV0025: £2,420.00 received</summary>
|
17
|
+
<description>The Good Folk</description>
|
18
|
+
<dated_on>2009-07%dT00:00Z</dated_on>
|
19
|
+
<amount>2420.0</amount>
|
20
|
+
</invoice_timeline_item>
|
21
|
+
<invoice_timeline_item>
|
22
|
+
<reference>INV0026</reference>
|
23
|
+
<summary>Payment: INV0026: £1,000.00 received</summary>
|
24
|
+
<description>Spectrum Healthcare</description>
|
25
|
+
<dated_on>2009-08%dT00:00Z</dated_on>
|
26
|
+
<amount>1000.0</amount>
|
27
|
+
</invoice_timeline_item>
|
28
|
+
<invoice_timeline_item>
|
29
|
+
<reference>INV0027</reference>
|
30
|
+
<summary>Payment: INV0027: £2,275.00 received</summary>
|
31
|
+
<description>Economic and Social Research Council</description>
|
32
|
+
<dated_on>2009-08%dT00:00Z</dated_on>
|
33
|
+
<amount>2275.0</amount>
|
34
|
+
</invoice_timeline_item>
|
35
|
+
<invoice_timeline_item>
|
36
|
+
<reference>INV0028</reference>
|
37
|
+
<summary>Payment: INV0028: £80.00 received</summary>
|
38
|
+
<description>The Good Folk</description>
|
39
|
+
<dated_on>2009-08%dT00:00Z</dated_on>
|
40
|
+
<amount>80.0</amount>
|
41
|
+
</invoice_timeline_item>
|
42
|
+
<invoice_timeline_item>
|
43
|
+
<reference>INV0029</reference>
|
44
|
+
<summary>Payment: INV0029: £1,012.50 received</summary>
|
45
|
+
<description>Spectrum Healthcare</description>
|
46
|
+
<dated_on>2009-09%dT00:00Z</dated_on>
|
47
|
+
<amount>1012.5</amount>
|
48
|
+
</invoice_timeline_item>
|
49
|
+
<invoice_timeline_item>
|
50
|
+
<reference>INV0031</reference>
|
51
|
+
<summary>Payment: INV0031: £70.00 received</summary>
|
52
|
+
<description>Economic and Social Research Council</description>
|
53
|
+
<dated_on>2009-09%dT00:00Z</dated_on>
|
54
|
+
<amount>70.0</amount>
|
55
|
+
</invoice_timeline_item>
|
56
|
+
<invoice_timeline_item>
|
57
|
+
<reference>INV0032</reference>
|
58
|
+
<summary>Payment: INV0032: £1,920.00 received</summary>
|
59
|
+
<description>icomplete</description>
|
60
|
+
<dated_on>2009-09%dT00:00Z</dated_on>
|
61
|
+
<amount>1920.0</amount>
|
62
|
+
</invoice_timeline_item>
|
63
|
+
<invoice_timeline_item>
|
64
|
+
<reference>INV0033</reference>
|
65
|
+
<summary>Payment: INV0033: £3,000.00 received</summary>
|
66
|
+
<description>Inbox Digital: Shop Direct NDR Webapp</description>
|
67
|
+
<dated_on>2009-10%dT00:00Z</dated_on>
|
68
|
+
<amount>3000.0</amount>
|
69
|
+
</invoice_timeline_item>
|
70
|
+
<invoice_timeline_item>
|
71
|
+
<reference>INV0030</reference>
|
72
|
+
<summary>Due: INV0030: £50.00</summary>
|
73
|
+
<description>Oxfordshire PTC</description>
|
74
|
+
<dated_on>2009-09%dT00:00Z</dated_on>
|
75
|
+
<amount>50.0</amount>
|
76
|
+
</invoice_timeline_item>
|
77
|
+
<invoice_timeline_item>
|
78
|
+
<reference>INV0034</reference>
|
79
|
+
<summary>Due: INV0034: £670.00</summary>
|
80
|
+
<description>The Good Folk</description>
|
81
|
+
<dated_on>2009-10%dT00:00Z</dated_on>
|
82
|
+
<amount>670.0</amount>
|
83
|
+
</invoice_timeline_item>
|
84
|
+
<invoice_timeline_item>
|
85
|
+
<reference>INV0035</reference>
|
86
|
+
<summary>Due: INV0035: £500.00</summary>
|
87
|
+
<description>ClubBuzz: ClubBuzz application design and development</description>
|
88
|
+
<dated_on>2009-10%dT00:00Z</dated_on>
|
89
|
+
<amount>500.0</amount>
|
90
|
+
</invoice_timeline_item>
|
91
|
+
</invoice-timeline-items>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Status: 200
|
3
|
+
Content-Type: application/xml; charset=utf-8
|
4
|
+
|
5
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
6
|
+
<timeline-items type="array">
|
7
|
+
<timeline_item>
|
8
|
+
<description>Corporation Tax, year ending 05 Apr 07*</description>
|
9
|
+
<nature>Submission Due</nature>
|
10
|
+
<dated_on>Sat Apr 05 00:00:00 UTC 2008</dated_on>
|
11
|
+
<amount_due></amount_due>
|
12
|
+
<is_personal>false</is_personal>
|
13
|
+
</timeline_item>
|
14
|
+
<timeline_item>
|
15
|
+
<description>Corporation Tax, year ending 05 Apr 08*</description>
|
16
|
+
<nature>Payment Due</nature>
|
17
|
+
<dated_on>Tue Jan 06 00:00:00 UTC 2009</dated_on>
|
18
|
+
<amount_due>190.14</amount_due>
|
19
|
+
<is_personal>false</is_personal>
|
20
|
+
</timeline_item>
|
21
|
+
<timeline_item>
|
22
|
+
<description>Corporation Tax, year ending 05 Apr 08*</description>
|
23
|
+
<nature>Submission Due</nature>
|
24
|
+
<dated_on>Sun Apr 05 00:00:00 UTC 2009</dated_on>
|
25
|
+
<amount_due></amount_due>
|
26
|
+
<is_personal>false</is_personal>
|
27
|
+
</timeline_item>
|
28
|
+
</timeline-items>
|