invoiced 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/Gemfile +2 -2
- data/README.md +11 -2
- data/lib/invoiced/bank_account.rb +0 -1
- data/lib/invoiced/card.rb +0 -1
- data/lib/invoiced/custom_field.rb +10 -0
- data/lib/invoiced/customer_chasing_cadence.rb +10 -0
- data/lib/invoiced/email_template.rb +10 -0
- data/lib/invoiced/gl_account.rb +10 -0
- data/lib/invoiced/inbox.rb +7 -0
- data/lib/invoiced/invoice_chasing_cadence.rb +10 -0
- data/lib/invoiced/late_fee_schedule.rb +10 -0
- data/lib/invoiced/member.rb +10 -0
- data/lib/invoiced/merchant_account.rb +10 -0
- data/lib/invoiced/object.rb +5 -1
- data/lib/invoiced/payment_method.rb +8 -0
- data/lib/invoiced/pdf_template.rb +10 -0
- data/lib/invoiced/report.rb +7 -0
- data/lib/invoiced/role.rb +10 -0
- data/lib/invoiced/sign_up_page.rb +10 -0
- data/lib/invoiced/sms_template.rb +10 -0
- data/lib/invoiced/tax_rule.rb +10 -0
- data/lib/invoiced/theme.rb +10 -0
- data/lib/invoiced/version.rb +1 -1
- data/lib/invoiced/webhook.rb +10 -0
- data/lib/invoiced.rb +39 -2
- data/test/invoiced/charge_test.rb +8 -6
- data/test/invoiced/contact_test.rb +10 -86
- data/test/invoiced/coupon_test.rb +10 -83
- data/test/invoiced/credit_balance_adjustment_test.rb +17 -0
- data/test/invoiced/credit_note_test.rb +10 -83
- data/test/invoiced/custom_field_test.rb +17 -0
- data/test/invoiced/customer_chasing_cadence_test.rb +17 -0
- data/test/invoiced/customer_test.rb +10 -83
- data/test/invoiced/email_template_test.rb +17 -0
- data/test/invoiced/estimate_test.rb +10 -83
- data/test/invoiced/event_test.rb +6 -21
- data/test/invoiced/file_test.rb +8 -47
- data/test/invoiced/gl_account_test.rb +17 -0
- data/test/invoiced/inbox_test.rb +13 -0
- data/test/invoiced/invoice_chasing_cadence_test.rb +17 -0
- data/test/invoiced/invoice_test.rb +10 -83
- data/test/invoiced/item_test.rb +10 -83
- data/test/invoiced/late_fee_schedule_test.rb +17 -0
- data/test/invoiced/line_item_test.rb +10 -86
- data/test/invoiced/member_test.rb +17 -0
- data/test/invoiced/merchant_account_test.rb +17 -0
- data/test/invoiced/note_test.rb +10 -83
- data/test/invoiced/operations/create_test.rb +22 -0
- data/test/invoiced/operations/delete_test.rb +20 -0
- data/test/invoiced/operations/endpoint_test.rb +13 -0
- data/test/invoiced/operations/list_test.rb +26 -0
- data/test/invoiced/operations/operations.rb +0 -0
- data/test/invoiced/operations/retrieve_test.rb +22 -0
- data/test/invoiced/operations/update_test.rb +29 -0
- data/test/invoiced/payment_method_test.rb +15 -0
- data/test/invoiced/payment_plan_test.rb +7 -0
- data/test/invoiced/payment_test.rb +10 -83
- data/test/invoiced/pdf_template_test.rb +17 -0
- data/test/invoiced/plan_test.rb +10 -83
- data/test/invoiced/refund_test.rb +5 -3
- data/test/invoiced/report_test.rb +14 -0
- data/test/invoiced/role_test.rb +17 -0
- data/test/invoiced/sign_up_page_test.rb +17 -0
- data/test/invoiced/sms_template_test.rb +17 -0
- data/test/invoiced/subscription_test.rb +10 -71
- data/test/invoiced/task_test.rb +10 -83
- data/test/invoiced/tax_rate_test.rb +10 -83
- data/test/invoiced/tax_rule_test.rb +17 -0
- data/test/invoiced/theme_test.rb +17 -0
- data/test/invoiced/webhook_test.rb +17 -0
- data/test/test_helper.rb +6 -0
- metadata +76 -8
- data/.travis.yml +0 -15
- data/test/invoiced/credit_balance_adjustment.rb +0 -90
data/test/invoiced/item_test.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/test/invoiced/note_test.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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())
|
@@ -2,89 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Invoiced
|
4
4
|
class PaymentTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
17
|
-
|
18
|
-
payment = @client.Payment.create({:amount => 800})
|
19
|
-
|
20
|
-
assert_instance_of(Invoiced::Payment, payment)
|
21
|
-
assert_equal(123, payment.id)
|
22
|
-
assert_equal(100, payment.amount)
|
23
|
-
end
|
24
|
-
|
25
|
-
should "retrieve a payment" do
|
26
|
-
mockResponse = mock('RestClient::Response')
|
27
|
-
mockResponse.stubs(:code).returns(200)
|
28
|
-
mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
|
29
|
-
mockResponse.stubs(:headers).returns({})
|
30
|
-
|
31
|
-
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
32
|
-
|
33
|
-
payment = @client.Payment.retrieve(123)
|
34
|
-
|
35
|
-
assert_instance_of(Invoiced::Payment, payment)
|
36
|
-
assert_equal(123, payment.id)
|
37
|
-
assert_equal(100, payment.amount)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "not update a payment when no params" do
|
41
|
-
payment = Payment.new(@client, 123)
|
42
|
-
assert_false(payment.save)
|
43
|
-
end
|
44
|
-
|
45
|
-
should "update a payment" do
|
46
|
-
mockResponse = mock('RestClient::Response')
|
47
|
-
mockResponse.stubs(:code).returns(200)
|
48
|
-
mockResponse.stubs(:body).returns('{"id":123,"sent":true}')
|
49
|
-
mockResponse.stubs(:headers).returns({})
|
50
|
-
|
51
|
-
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
52
|
-
|
53
|
-
payment = Payment.new(@client, 123)
|
54
|
-
payment.sent = true
|
55
|
-
assert_true(payment.save)
|
56
|
-
|
57
|
-
assert_true(payment.sent)
|
58
|
-
end
|
59
|
-
|
60
|
-
should "list all payments" do
|
61
|
-
mockResponse = mock('RestClient::Response')
|
62
|
-
mockResponse.stubs(:code).returns(200)
|
63
|
-
mockResponse.stubs(:body).returns('[{"id":123,"amount":100}]')
|
64
|
-
mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/payments?per_page=25&page=1>; rel="self", <https://api.invoiced.com/payments?per_page=25&page=1>; rel="first", <https://api.invoiced.com/payments?per_page=25&page=1>; rel="last"')
|
65
|
-
|
66
|
-
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
67
|
-
|
68
|
-
payments, metadata = @client.Payment.list
|
69
|
-
|
70
|
-
assert_instance_of(Array, payments)
|
71
|
-
assert_equal(1, payments.length)
|
72
|
-
assert_equal(123, payments[0].id)
|
73
|
-
|
74
|
-
assert_instance_of(Invoiced::List, metadata)
|
75
|
-
assert_equal(15, metadata.total_count)
|
76
|
-
end
|
77
|
-
|
78
|
-
should "delete a payment" 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
|
-
payment = Payment.new(@client, 123)
|
87
|
-
assert_true(payment.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 = Payment
|
14
|
+
@endpoint = '/payments'
|
88
15
|
end
|
89
16
|
|
90
17
|
should "send a payment receipt" do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class PdfTemplateTest < 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 = PdfTemplate
|
14
|
+
@endpoint = '/pdf_templates'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|