invoiced 2.0.0 → 3.0.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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +37 -0
  3. data/.github/workflows/publish.yml +24 -0
  4. data/Gemfile +4 -4
  5. data/README.md +3 -3
  6. data/invoiced.gemspec +2 -2
  7. data/lib/invoiced/bank_account.rb +0 -1
  8. data/lib/invoiced/card.rb +0 -1
  9. data/lib/invoiced/custom_field.rb +10 -0
  10. data/lib/invoiced/customer_chasing_cadence.rb +10 -0
  11. data/lib/invoiced/email_template.rb +10 -0
  12. data/lib/invoiced/gl_account.rb +10 -0
  13. data/lib/invoiced/inbox.rb +7 -0
  14. data/lib/invoiced/invoice_chasing_cadence.rb +10 -0
  15. data/lib/invoiced/late_fee_schedule.rb +10 -0
  16. data/lib/invoiced/member.rb +10 -0
  17. data/lib/invoiced/merchant_account.rb +10 -0
  18. data/lib/invoiced/object.rb +5 -1
  19. data/lib/invoiced/payment_method.rb +8 -0
  20. data/lib/invoiced/pdf_template.rb +10 -0
  21. data/lib/invoiced/report.rb +7 -0
  22. data/lib/invoiced/role.rb +10 -0
  23. data/lib/invoiced/sign_up_page.rb +10 -0
  24. data/lib/invoiced/sms_template.rb +10 -0
  25. data/lib/invoiced/tax_rule.rb +10 -0
  26. data/lib/invoiced/theme.rb +10 -0
  27. data/lib/invoiced/version.rb +2 -2
  28. data/lib/invoiced/webhook.rb +10 -0
  29. data/lib/invoiced.rb +39 -2
  30. data/test/invoiced/charge_test.rb +8 -6
  31. data/test/invoiced/contact_test.rb +10 -86
  32. data/test/invoiced/coupon_test.rb +10 -83
  33. data/test/invoiced/credit_balance_adjustment_test.rb +17 -0
  34. data/test/invoiced/credit_note_test.rb +10 -83
  35. data/test/invoiced/custom_field_test.rb +17 -0
  36. data/test/invoiced/customer_chasing_cadence_test.rb +17 -0
  37. data/test/invoiced/customer_test.rb +10 -83
  38. data/test/invoiced/email_template_test.rb +17 -0
  39. data/test/invoiced/estimate_test.rb +10 -83
  40. data/test/invoiced/event_test.rb +6 -21
  41. data/test/invoiced/file_test.rb +8 -47
  42. data/test/invoiced/gl_account_test.rb +17 -0
  43. data/test/invoiced/inbox_test.rb +13 -0
  44. data/test/invoiced/invoice_chasing_cadence_test.rb +17 -0
  45. data/test/invoiced/invoice_test.rb +10 -83
  46. data/test/invoiced/item_test.rb +10 -83
  47. data/test/invoiced/late_fee_schedule_test.rb +17 -0
  48. data/test/invoiced/line_item_test.rb +10 -86
  49. data/test/invoiced/member_test.rb +17 -0
  50. data/test/invoiced/merchant_account_test.rb +17 -0
  51. data/test/invoiced/note_test.rb +10 -83
  52. data/test/invoiced/operations/create_test.rb +22 -0
  53. data/test/invoiced/operations/delete_test.rb +20 -0
  54. data/test/invoiced/operations/endpoint_test.rb +13 -0
  55. data/test/invoiced/operations/list_test.rb +26 -0
  56. data/test/invoiced/operations/operations.rb +0 -0
  57. data/test/invoiced/operations/retrieve_test.rb +22 -0
  58. data/test/invoiced/operations/update_test.rb +29 -0
  59. data/test/invoiced/payment_method_test.rb +15 -0
  60. data/test/invoiced/payment_plan_test.rb +7 -0
  61. data/test/invoiced/payment_test.rb +10 -83
  62. data/test/invoiced/pdf_template_test.rb +17 -0
  63. data/test/invoiced/plan_test.rb +10 -83
  64. data/test/invoiced/refund_test.rb +5 -3
  65. data/test/invoiced/report_test.rb +14 -0
  66. data/test/invoiced/role_test.rb +17 -0
  67. data/test/invoiced/sign_up_page_test.rb +17 -0
  68. data/test/invoiced/sms_template_test.rb +17 -0
  69. data/test/invoiced/subscription_test.rb +10 -71
  70. data/test/invoiced/task_test.rb +10 -83
  71. data/test/invoiced/tax_rate_test.rb +10 -83
  72. data/test/invoiced/tax_rule_test.rb +17 -0
  73. data/test/invoiced/theme_test.rb +17 -0
  74. data/test/invoiced/webhook_test.rb +17 -0
  75. data/test/test_helper.rb +6 -0
  76. metadata +78 -9
  77. data/.travis.yml +0 -15
  78. data/test/invoiced/credit_balance_adjustment.rb +0 -90
@@ -2,89 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class InvoiceTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- invoice = Invoice.new(@client, 123)
7
- assert_equal('/invoices/123', invoice.endpoint())
8
- end
9
-
10
- should "create an invoice" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":123,"number":"INV-0001"}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- invoice = @client.Invoice.create({:number => "INV-0001"})
19
-
20
- assert_instance_of(Invoiced::Invoice, invoice)
21
- assert_equal(123, invoice.id)
22
- assert_equal('INV-0001', invoice.number)
23
- end
24
-
25
- should "retrieve an invoice" do
26
- mockResponse = mock('RestClient::Response')
27
- mockResponse.stubs(:code).returns(200)
28
- mockResponse.stubs(:body).returns('{"id":123,"number":"INV-0001"}')
29
- mockResponse.stubs(:headers).returns({})
30
-
31
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
-
33
- invoice = @client.Invoice.retrieve(123)
34
-
35
- assert_instance_of(Invoiced::Invoice, invoice)
36
- assert_equal(123, invoice.id)
37
- assert_equal('INV-0001', invoice.number)
38
- end
39
-
40
- should "not update an invoice when no params" do
41
- invoice = Invoice.new(@client, 123)
42
- assert_false(invoice.save)
43
- end
44
-
45
- should "update an invoice" do
46
- mockResponse = mock('RestClient::Response')
47
- mockResponse.stubs(:code).returns(200)
48
- mockResponse.stubs(:body).returns('{"id":123,"closed":true}')
49
- mockResponse.stubs(:headers).returns({})
50
-
51
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
-
53
- invoice = Invoice.new(@client, 123)
54
- invoice.closed = true
55
- assert_true(invoice.save)
56
-
57
- assert_true(invoice.closed)
58
- end
59
-
60
- should "list all invoices" do
61
- mockResponse = mock('RestClient::Response')
62
- mockResponse.stubs(:code).returns(200)
63
- mockResponse.stubs(:body).returns('[{"id":123,"number":"INV-0001"}]')
64
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/invoices?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices?per_page=25&page=1>; rel="last"')
65
-
66
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
-
68
- invoices, metadata = @client.Invoice.list
69
-
70
- assert_instance_of(Array, invoices)
71
- assert_equal(1, invoices.length)
72
- assert_equal(123, invoices[0].id)
73
-
74
- assert_instance_of(Invoiced::List, metadata)
75
- assert_equal(15, metadata.total_count)
76
- end
77
-
78
- should "delete an invoice" do
79
- mockResponse = mock('RestClient::Response')
80
- mockResponse.stubs(:code).returns(204)
81
- mockResponse.stubs(:body).returns('')
82
- mockResponse.stubs(:headers).returns({})
83
-
84
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
-
86
- invoice = Invoice.new(@client, 123)
87
- assert_true(invoice.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Invoice
14
+ @endpoint = '/invoices'
88
15
  end
89
16
 
90
17
  should "send an invoice by email" do
@@ -2,89 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class ItemTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- item = Item.new(@client, "test")
7
- assert_equal('/items/test', item.endpoint())
8
- end
9
-
10
- should "create an item" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- item = @client.Item.create({:name => "Test Item"})
19
-
20
- assert_instance_of(Invoiced::Item, item)
21
- assert_equal("test", item.id)
22
- assert_equal('Test Item', item.name)
23
- end
24
-
25
- should "retrieve an item" do
26
- mockResponse = mock('RestClient::Response')
27
- mockResponse.stubs(:code).returns(200)
28
- mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
29
- mockResponse.stubs(:headers).returns({})
30
-
31
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
-
33
- item = @client.Item.retrieve("test")
34
-
35
- assert_instance_of(Invoiced::Item, item)
36
- assert_equal("test", item.id)
37
- assert_equal('Test Item', item.name)
38
- end
39
-
40
- should "not update an item when no params" do
41
- item = Item.new(@client, "test")
42
- assert_false(item.save)
43
- end
44
-
45
- should "update an item" do
46
- mockResponse = mock('RestClient::Response')
47
- mockResponse.stubs(:code).returns(200)
48
- mockResponse.stubs(:body).returns('{"id":"test","closed":true}')
49
- mockResponse.stubs(:headers).returns({})
50
-
51
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
-
53
- item = Item.new(@client, "test")
54
- item.closed = true
55
- assert_true(item.save)
56
-
57
- assert_true(item.closed)
58
- end
59
-
60
- should "list all items" do
61
- mockResponse = mock('RestClient::Response')
62
- mockResponse.stubs(:code).returns(200)
63
- mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Item"}]')
64
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/items?per_page=25&page=1>; rel="last"')
65
-
66
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
-
68
- items, metadata = @client.Item.list
69
-
70
- assert_instance_of(Array, items)
71
- assert_equal(1, items.length)
72
- assert_equal("test", items[0].id)
73
-
74
- assert_instance_of(Invoiced::List, metadata)
75
- assert_equal(15, metadata.total_count)
76
- end
77
-
78
- should "delete an item" do
79
- mockResponse = mock('RestClient::Response')
80
- mockResponse.stubs(:code).returns(204)
81
- mockResponse.stubs(:body).returns('')
82
- mockResponse.stubs(:headers).returns({})
83
-
84
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
-
86
- item = Item.new(@client, "test")
87
- assert_true(item.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Item
14
+ @endpoint = '/items'
88
15
  end
89
16
  end
90
17
  end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class LateFeeScheduleTest < Test::Unit::TestCase
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = LateFeeSchedule
14
+ @endpoint = '/late_fee_schedules'
15
+ end
16
+ end
17
+ end
@@ -2,92 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class LineItemTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- line = LineItem.new(@client, 123)
7
- assert_equal('/line_items/123', line.endpoint())
8
- end
9
-
10
- should "create a line item" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":123,"unit_cost":500}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- line = LineItem.new(@client)
19
- line_item = line.create({:unit_cost => 500})
20
-
21
- assert_instance_of(Invoiced::LineItem, line_item)
22
- assert_equal(123, line_item.id)
23
- assert_equal(500, line_item.unit_cost)
24
- end
25
-
26
- should "retrieve a line item" do
27
- mockResponse = mock('RestClient::Response')
28
- mockResponse.stubs(:code).returns(200)
29
- mockResponse.stubs(:body).returns('{"id":123,"unit_cost":500}')
30
- mockResponse.stubs(:headers).returns({})
31
-
32
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
33
-
34
- line = LineItem.new(@client)
35
- line_item = line.retrieve(123)
36
-
37
- assert_instance_of(Invoiced::LineItem, line_item)
38
- assert_equal(123, line_item.id)
39
- assert_equal(500, line_item.unit_cost)
40
- end
41
-
42
- should "not update a line item when no params" do
43
- line_item = LineItem.new(@client, 123)
44
- assert_false(line_item.save)
45
- end
46
-
47
- should "update a line item" do
48
- mockResponse = mock('RestClient::Response')
49
- mockResponse.stubs(:code).returns(200)
50
- mockResponse.stubs(:body).returns('{"id":123,"unit_cost":400}')
51
- mockResponse.stubs(:headers).returns({})
52
-
53
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
54
-
55
- line_item = LineItem.new(@client, 123)
56
- line_item.unit_cost = 400
57
- assert_true(line_item.save)
58
-
59
- assert_equal(400, line_item.unit_cost)
60
- end
61
-
62
- should "list all line items" do
63
- mockResponse = mock('RestClient::Response')
64
- mockResponse.stubs(:code).returns(200)
65
- mockResponse.stubs(:body).returns('[{"id":123,"unit_cost":500}]')
66
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/line_items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/line_items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/line_items?per_page=25&page=1>; rel="last"')
67
-
68
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
69
-
70
- line_item = LineItem.new(@client)
71
- line_items, metadata = line_item.list
72
-
73
- assert_instance_of(Array, line_items)
74
- assert_equal(1, line_items.length)
75
- assert_equal(123, line_items[0].id)
76
-
77
- assert_instance_of(Invoiced::List, metadata)
78
- assert_equal(15, metadata.total_count)
79
- end
80
-
81
- should "delete a line item" do
82
- mockResponse = mock('RestClient::Response')
83
- mockResponse.stubs(:code).returns(204)
84
- mockResponse.stubs(:body).returns('')
85
- mockResponse.stubs(:headers).returns({})
86
-
87
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
88
-
89
- line_item = LineItem.new(@client, 123)
90
- assert_true(line_item.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = LineItem
14
+ @endpoint = '/line_items'
91
15
  end
92
16
  end
93
17
  end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class MemberTest < Test::Unit::TestCase
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Member
14
+ @endpoint = '/members'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class MerchantAccountTest < Test::Unit::TestCase
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = MerchantAccount
14
+ @endpoint = '/merchant_accounts'
15
+ end
16
+ end
17
+ end
@@ -2,89 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class NoteTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- note = Note.new(@client, "test")
7
- assert_equal('/notes/test', note.endpoint())
8
- end
9
-
10
- should "create a note" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- note = @client.Note.create({:notes => "Test Note"})
19
-
20
- assert_instance_of(Invoiced::Note, note)
21
- assert_equal("test", note.id)
22
- assert_equal('Test Note', note.notes)
23
- end
24
-
25
- should "retrieve a note" do
26
- mockResponse = mock('RestClient::Response')
27
- mockResponse.stubs(:code).returns(200)
28
- mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
29
- mockResponse.stubs(:headers).returns({})
30
-
31
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
-
33
- note = @client.Note.retrieve("test")
34
-
35
- assert_instance_of(Invoiced::Note, note)
36
- assert_equal("test", note.id)
37
- assert_equal('Test Note', note.notes)
38
- end
39
-
40
- should "not update a note when no params" do
41
- note = Note.new(@client, "test")
42
- assert_false(note.save)
43
- end
44
-
45
- should "update a note" do
46
- mockResponse = mock('RestClient::Response')
47
- mockResponse.stubs(:code).returns(200)
48
- mockResponse.stubs(:body).returns('{"id":"test","notes":"new contents"}')
49
- mockResponse.stubs(:headers).returns({})
50
-
51
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
-
53
- note = Note.new(@client, "test")
54
- note.notes = "new contents"
55
- assert_true(note.save)
56
-
57
- assert_equal(note.notes, 'new contents')
58
- end
59
-
60
- should "list all notes" do
61
- mockResponse = mock('RestClient::Response')
62
- mockResponse.stubs(:code).returns(200)
63
- mockResponse.stubs(:body).returns('[{"id":"test","notes":"Test Note"}]')
64
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="last"')
65
-
66
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
-
68
- notes, metadata = @client.Note.list
69
-
70
- assert_instance_of(Array, notes)
71
- assert_equal(1, notes.length)
72
- assert_equal("test", notes[0].id)
73
-
74
- assert_instance_of(Invoiced::List, metadata)
75
- assert_equal(15, metadata.total_count)
76
- end
77
-
78
- should "delete a note" do
79
- mockResponse = mock('RestClient::Response')
80
- mockResponse.stubs(:code).returns(204)
81
- mockResponse.stubs(:body).returns('')
82
- mockResponse.stubs(:headers).returns({})
83
-
84
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
-
86
- note = Note.new(@client, "test")
87
- assert_true(note.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Note
14
+ @endpoint = '/notes'
88
15
  end
89
16
  end
90
17
  end
@@ -0,0 +1,22 @@
1
+ module Invoiced
2
+ module Operations
3
+ module CreateTest
4
+ include ShouldaContextLoadable
5
+
6
+ should "create a plan" do
7
+ mockResponse = mock('RestClient::Response')
8
+ mockResponse.stubs(:code).returns(201)
9
+ mockResponse.stubs(:body).returns('{"id":"test"}')
10
+ mockResponse.stubs(:headers).returns({})
11
+
12
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
13
+
14
+ client = Invoiced::Client.new('api_key')
15
+ obj = @objectClass.new(client).create({:name => "Test"})
16
+
17
+ assert_instance_of(@objectClass, obj)
18
+ assert_equal("test", obj.id)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Invoiced
2
+ module Operations
3
+ module DeleteTest
4
+ include ShouldaContextLoadable
5
+
6
+ should "delete an object" do
7
+ mockResponse = mock('RestClient::Response')
8
+ mockResponse.stubs(:code).returns(204)
9
+ mockResponse.stubs(:body).returns('')
10
+ mockResponse.stubs(:headers).returns({})
11
+
12
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
13
+
14
+ client = Invoiced::Client.new('api_key')
15
+ obj = @objectClass.new(client, 1234)
16
+ assert_true(obj.delete)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Invoiced
2
+ module Operations
3
+ module EndpointTest
4
+ include ShouldaContextLoadable
5
+
6
+ should "return the api endpoint" do
7
+ client = Invoiced::Client.new('api_key')
8
+ obj = @objectClass.new(client, 1234)
9
+ assert_equal(@endpoint + '/1234', obj.endpoint())
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Invoiced
2
+ module Operations
3
+ module ListTest
4
+ include ShouldaContextLoadable
5
+
6
+ should "list all objects" do
7
+ mockResponse = mock('RestClient::Response')
8
+ mockResponse.stubs(:code).returns(200)
9
+ mockResponse.stubs(:body).returns('[{"id":1234}]')
10
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com' + @endpoint + '?per_page=25&page=1>; rel="self", <https://api.invoiced.com' + @endpoint + '?per_page=25&page=1>; rel="first", <https://api.invoiced.com' + @endpoint + '?per_page=25&page=1>; rel="last"')
11
+
12
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
13
+
14
+ client = Invoiced::Client.new('api_key')
15
+ objects, metadata = @objectClass.new(client).list
16
+
17
+ assert_instance_of(Array, objects)
18
+ assert_equal(1, objects.length)
19
+ assert_equal(1234, objects[0].id)
20
+
21
+ assert_instance_of(Invoiced::List, metadata)
22
+ assert_equal(15, metadata.total_count)
23
+ end
24
+ end
25
+ end
26
+ end
File without changes
@@ -0,0 +1,22 @@
1
+ module Invoiced
2
+ module Operations
3
+ module RetrieveTest
4
+ include ShouldaContextLoadable
5
+
6
+ should 'retrieve an object' do
7
+ mockResponse = mock('RestClient::Response')
8
+ mockResponse.stubs(:code).returns(200)
9
+ mockResponse.stubs(:body).returns('{"id":123}')
10
+ mockResponse.stubs(:headers).returns({})
11
+
12
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
13
+
14
+ client = Invoiced::Client.new('api_key')
15
+ obj = @objectClass.new(client).retrieve(123)
16
+
17
+ assert_instance_of(@objectClass, obj)
18
+ assert_equal(123, obj.id)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module Invoiced
2
+ module Operations
3
+ module UpdateTest
4
+ include ShouldaContextLoadable
5
+
6
+ should "not update an object when no params" do
7
+ client = Invoiced::Client.new('api_key')
8
+ obj = @objectClass.new(client, "test")
9
+ assert_false(obj.save)
10
+ end
11
+
12
+ should "update an object" do
13
+ mockResponse = mock('RestClient::Response')
14
+ mockResponse.stubs(:code).returns(200)
15
+ mockResponse.stubs(:body).returns('{"id":1234,"closed":true}')
16
+ mockResponse.stubs(:headers).returns({})
17
+
18
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
19
+
20
+ client = Invoiced::Client.new('api_key')
21
+ obj = @objectClass.new(client, 1234)
22
+ obj.closed = true
23
+ assert_true(obj.save)
24
+
25
+ assert_true(obj.closed)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class PaymentMethodTest < Test::Unit::TestCase
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::RetrieveTest
7
+ include Invoiced::Operations::UpdateTest
8
+ include Invoiced::Operations::ListTest
9
+
10
+ setup do
11
+ @objectClass = PaymentMethod
12
+ @endpoint = '/payment_methods'
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,13 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class PaymentPlanTest < Test::Unit::TestCase
5
+ include Invoiced::Operations::CreateTest
6
+ include Invoiced::Operations::DeleteTest
7
+
8
+ setup do
9
+ @objectClass = PaymentPlan
10
+ end
11
+
5
12
  should "return the api endpoint" do
6
13
  paymentPlan = PaymentPlan.new(@client, 123)
7
14
  assert_equal('/payment_plan', paymentPlan.endpoint())