invoiced 0.12.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -1
- data/.travis.yml +5 -1
- data/Gemfile +6 -2
- data/README.md +4 -2
- data/invoiced.gemspec +2 -8
- data/lib/invoiced.rb +43 -5
- data/lib/invoiced/attachment.rb +1 -0
- data/lib/invoiced/bank_account.rb +6 -0
- data/lib/invoiced/card.rb +6 -0
- data/lib/invoiced/catalog_item.rb +2 -0
- data/lib/invoiced/charge.rb +12 -0
- data/lib/invoiced/contact.rb +2 -0
- data/lib/invoiced/coupon.rb +10 -0
- data/lib/invoiced/credit_note.rb +10 -0
- data/lib/invoiced/customer.rb +36 -0
- data/lib/invoiced/email.rb +1 -0
- data/lib/invoiced/estimate.rb +10 -0
- data/lib/invoiced/event.rb +2 -0
- data/lib/invoiced/file.rb +2 -0
- data/lib/invoiced/invoice.rb +33 -1
- data/lib/invoiced/letter.rb +5 -0
- data/lib/invoiced/line_item.rb +2 -0
- data/lib/invoiced/note.rb +10 -0
- data/lib/invoiced/object.rb +11 -5
- data/lib/invoiced/operations/create.rb +1 -1
- data/lib/invoiced/payment.rb +18 -0
- data/lib/invoiced/payment_plan.rb +2 -0
- data/lib/invoiced/payment_source.rb +8 -0
- data/lib/invoiced/payment_source_object.rb +5 -0
- data/lib/invoiced/plan.rb +2 -0
- data/lib/invoiced/refund.rb +11 -0
- data/lib/invoiced/subscription.rb +8 -0
- data/lib/invoiced/task.rb +10 -0
- data/lib/invoiced/tax_rate.rb +10 -0
- data/lib/invoiced/text_message.rb +5 -0
- data/lib/invoiced/transaction.rb +8 -0
- data/lib/invoiced/util.rb +13 -1
- data/lib/invoiced/version.rb +1 -1
- data/test/invoiced/charge_test.rb +25 -0
- data/test/invoiced/coupon_test.rb +90 -0
- data/test/invoiced/credit_note_test.rb +14 -0
- data/test/invoiced/customer_test.rb +101 -2
- data/test/invoiced/estimate_test.rb +14 -0
- data/test/invoiced/invoice_test.rb +69 -1
- data/test/invoiced/invoiced_test.rb +27 -1
- data/test/invoiced/note_test.rb +90 -0
- data/test/invoiced/payment_source_test.rb +57 -0
- data/test/invoiced/payment_test.rb +107 -0
- data/test/invoiced/refund_test.rb +25 -0
- data/test/invoiced/subscription_test.rb +13 -0
- data/test/invoiced/task_test.rb +90 -0
- data/test/invoiced/tax_rate_test.rb +90 -0
- data/test/invoiced/transaction_test.rb +15 -0
- metadata +36 -78
@@ -137,5 +137,19 @@ module Invoiced
|
|
137
137
|
assert_instance_of(Invoiced::List, metadata)
|
138
138
|
assert_equal(10, metadata.total_count)
|
139
139
|
end
|
140
|
+
|
141
|
+
should "void an estimate" do
|
142
|
+
mockResponse = mock('RestClient::Response')
|
143
|
+
mockResponse.stubs(:code).returns(200)
|
144
|
+
mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
|
145
|
+
mockResponse.stubs(:headers).returns({})
|
146
|
+
|
147
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
148
|
+
|
149
|
+
estimate = Estimate.new(@client, 123)
|
150
|
+
assert_true(estimate.void)
|
151
|
+
|
152
|
+
assert_equal(estimate.status, 'voided')
|
153
|
+
end
|
140
154
|
end
|
141
155
|
end
|
@@ -87,7 +87,7 @@ module Invoiced
|
|
87
87
|
assert_true(invoice.delete)
|
88
88
|
end
|
89
89
|
|
90
|
-
should "send an invoice" do
|
90
|
+
should "send an invoice by email" do
|
91
91
|
mockResponse = mock('RestClient::Response')
|
92
92
|
mockResponse.stubs(:code).returns(201)
|
93
93
|
mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
|
@@ -104,6 +104,40 @@ module Invoiced
|
|
104
104
|
assert_equal(4567, emails[0].id)
|
105
105
|
end
|
106
106
|
|
107
|
+
should "send an invoice by text message" do
|
108
|
+
mockResponse = mock('RestClient::Response')
|
109
|
+
mockResponse.stubs(:code).returns(201)
|
110
|
+
mockResponse.stubs(:body).returns('[{"id":5678,"state":"sent"}]')
|
111
|
+
mockResponse.stubs(:headers).returns({})
|
112
|
+
|
113
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
114
|
+
|
115
|
+
invoice = Invoice.new(@client, 1234)
|
116
|
+
text_messages = invoice.send_sms(:message => "example")
|
117
|
+
|
118
|
+
assert_instance_of(Array, text_messages)
|
119
|
+
assert_equal(1, text_messages.length)
|
120
|
+
assert_instance_of(Invoiced::TextMessage, text_messages[0])
|
121
|
+
assert_equal(5678, text_messages[0].id)
|
122
|
+
end
|
123
|
+
|
124
|
+
should "send an invoice by letter" do
|
125
|
+
mockResponse = mock('RestClient::Response')
|
126
|
+
mockResponse.stubs(:code).returns(201)
|
127
|
+
mockResponse.stubs(:body).returns('[{"id":6789,"state":"queued"}]')
|
128
|
+
mockResponse.stubs(:headers).returns({})
|
129
|
+
|
130
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
131
|
+
|
132
|
+
invoice = Invoice.new(@client, 1234)
|
133
|
+
letters = invoice.send_letter
|
134
|
+
|
135
|
+
assert_instance_of(Array, letters)
|
136
|
+
assert_equal(1, letters.length)
|
137
|
+
assert_instance_of(Invoiced::Letter, letters[0])
|
138
|
+
assert_equal(6789, letters[0].id)
|
139
|
+
end
|
140
|
+
|
107
141
|
should "pay an invoice" do
|
108
142
|
mockResponse = mock('RestClient::Response')
|
109
143
|
mockResponse.stubs(:code).returns(200)
|
@@ -170,5 +204,39 @@ module Invoiced
|
|
170
204
|
assert_equal("active", payment_plan.status)
|
171
205
|
assert_equal('/invoices/456/payment_plan', payment_plan.endpoint())
|
172
206
|
end
|
207
|
+
|
208
|
+
should "list all notes associated with invoice" do
|
209
|
+
mockResponse = mock('RestClient::Response')
|
210
|
+
mockResponse.stubs(:code).returns(200)
|
211
|
+
mockResponse.stubs(:body).returns('[{"id":1212,"notes":"example"}]')
|
212
|
+
mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="last"')
|
213
|
+
|
214
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
215
|
+
|
216
|
+
invoice = Invoice.new(@client, 1234)
|
217
|
+
notes, metadata = invoice.notes.list
|
218
|
+
|
219
|
+
assert_instance_of(Array, notes)
|
220
|
+
assert_equal(1, notes.length)
|
221
|
+
assert_equal(1212, notes[0].id)
|
222
|
+
assert_equal('/invoices/1234/notes/1212', notes[0].endpoint())
|
223
|
+
|
224
|
+
assert_instance_of(Invoiced::List, metadata)
|
225
|
+
assert_equal(15, metadata.total_count)
|
226
|
+
end
|
227
|
+
|
228
|
+
should "void an invoice" do
|
229
|
+
mockResponse = mock('RestClient::Response')
|
230
|
+
mockResponse.stubs(:code).returns(200)
|
231
|
+
mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
|
232
|
+
mockResponse.stubs(:headers).returns({})
|
233
|
+
|
234
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
235
|
+
|
236
|
+
invoice = Invoice.new(@client, 123)
|
237
|
+
assert_true(invoice.void)
|
238
|
+
|
239
|
+
assert_equal(invoice.status, 'voided')
|
240
|
+
end
|
173
241
|
end
|
174
242
|
end
|
@@ -261,5 +261,31 @@ module Invoiced
|
|
261
261
|
client.request("POST", "/invoices")
|
262
262
|
end
|
263
263
|
end
|
264
|
+
|
265
|
+
should "generate a single sign-on token" do
|
266
|
+
ssoKey = '8baa4dbc338a54bbf7696eef3ee4aa2daadd61bba85fcfe8df96c7cfa227c43'
|
267
|
+
client = Invoiced::Client.new('API_KEY', false, ssoKey)
|
268
|
+
t = Time.now
|
269
|
+
|
270
|
+
token = client.generate_sign_in_token(1234, 3600)
|
271
|
+
|
272
|
+
decrypted = JWT.decode token, ssoKey, true, { :algorithm => 'HS256' }
|
273
|
+
assert_operator decrypted[0]['exp'] - t.to_i - 3600, :<, 3 # this accounts for slow running tests
|
274
|
+
decrypted[0].delete('exp')
|
275
|
+
|
276
|
+
expected = {
|
277
|
+
'iat' => t.to_i,
|
278
|
+
'sub' => 1234,
|
279
|
+
'iss' => 'Invoiced Ruby/'+Invoiced::VERSION
|
280
|
+
}
|
281
|
+
assert_equal(expected, decrypted[0])
|
282
|
+
end
|
283
|
+
|
284
|
+
should "raise an error when generating a single sign-on token with no key" do
|
285
|
+
client = Invoiced::Client.new('test')
|
286
|
+
assert_raise do
|
287
|
+
client.generate_sign_in_token(1234, 3600)
|
288
|
+
end
|
289
|
+
end
|
264
290
|
end
|
265
|
-
end
|
291
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
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)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class PaymentSourceTest < Test::Unit::TestCase
|
5
|
+
should "return the api endpoint" do
|
6
|
+
payment_source = Customer.new(@client, 1234).payment_sources()
|
7
|
+
assert_equal('/customers/1234/payment_sources', payment_source.endpoint())
|
8
|
+
end
|
9
|
+
|
10
|
+
should "list all payment sources" do
|
11
|
+
mockResponse = mock('RestClient::Response')
|
12
|
+
mockResponse.stubs(:code).returns(200)
|
13
|
+
mockResponse.stubs(:body).returns('[{"id":123,"object":"card"},{"id":234,"object":"bank_account"}]')
|
14
|
+
mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="self", <https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="first", <https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="last"')
|
15
|
+
|
16
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
17
|
+
|
18
|
+
payment_source = PaymentSource.new(@client)
|
19
|
+
payment_sources, metadata = payment_source.list
|
20
|
+
|
21
|
+
assert_instance_of(Array, payment_sources)
|
22
|
+
assert_instance_of(Invoiced::Card, payment_sources[0])
|
23
|
+
assert_instance_of(Invoiced::BankAccount, payment_sources[1])
|
24
|
+
assert_equal(2, payment_sources.length)
|
25
|
+
assert_equal(123, payment_sources[0][:id])
|
26
|
+
|
27
|
+
assert_instance_of(Invoiced::List, metadata)
|
28
|
+
assert_equal(15, metadata.total_count)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "delete a card payment source" do
|
32
|
+
mockResponse = mock('RestClient::Response')
|
33
|
+
mockResponse.stubs(:code).returns(204)
|
34
|
+
mockResponse.stubs(:body).returns('')
|
35
|
+
mockResponse.stubs(:headers).returns({})
|
36
|
+
|
37
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
38
|
+
|
39
|
+
card = Card.new(@client, 123)
|
40
|
+
card.object = 'card'
|
41
|
+
assert_true(card.delete)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "delete a bank account payment source" do
|
45
|
+
mockResponse = mock('RestClient::Response')
|
46
|
+
mockResponse.stubs(:code).returns(204)
|
47
|
+
mockResponse.stubs(:body).returns('')
|
48
|
+
mockResponse.stubs(:headers).returns({})
|
49
|
+
|
50
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
51
|
+
|
52
|
+
bank_account = BankAccount.new(@client, 123)
|
53
|
+
bank_account.object = 'bank_account'
|
54
|
+
assert_true(bank_account.delete)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class PaymentTest < Test::Unit::TestCase
|
5
|
+
should "return the api endpoint" do
|
6
|
+
payment = Payment.new(@client, 123)
|
7
|
+
assert_equal('/payments/123', payment.endpoint())
|
8
|
+
end
|
9
|
+
|
10
|
+
should "create a payment" do
|
11
|
+
mockResponse = mock('RestClient::Response')
|
12
|
+
mockResponse.stubs(:code).returns(201)
|
13
|
+
mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
|
14
|
+
mockResponse.stubs(:headers).returns({})
|
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)
|
88
|
+
end
|
89
|
+
|
90
|
+
should "send a payment receipt" do
|
91
|
+
mockResponse = mock('RestClient::Response')
|
92
|
+
mockResponse.stubs(:code).returns(201)
|
93
|
+
mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
|
94
|
+
mockResponse.stubs(:headers).returns({})
|
95
|
+
|
96
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
97
|
+
|
98
|
+
payment = Payment.new(@client, 1234)
|
99
|
+
emails = payment.send
|
100
|
+
|
101
|
+
assert_instance_of(Array, emails)
|
102
|
+
assert_equal(1, emails.length)
|
103
|
+
assert_instance_of(Invoiced::Email, emails[0])
|
104
|
+
assert_equal(4567, emails[0].id)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class RefundTest < Test::Unit::TestCase
|
5
|
+
should "return the api endpoint" do
|
6
|
+
refund = Refund.new(@client, 123)
|
7
|
+
assert_equal('/refunds/123', refund.endpoint())
|
8
|
+
end
|
9
|
+
|
10
|
+
should "create a refund" do
|
11
|
+
mockResponse = mock('RestClient::Response')
|
12
|
+
mockResponse.stubs(:code).returns(201)
|
13
|
+
mockResponse.stubs(:body).returns('{"id":456}')
|
14
|
+
mockResponse.stubs(:headers).returns({})
|
15
|
+
|
16
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
17
|
+
|
18
|
+
refund = Refund.new(@client, 1234)
|
19
|
+
refund = refund.create(456, {:amount => 800})
|
20
|
+
|
21
|
+
assert_instance_of(Invoiced::Refund, refund)
|
22
|
+
assert_equal(456, refund.id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -87,5 +87,18 @@ module Invoiced
|
|
87
87
|
assert_true(subscription.cancel)
|
88
88
|
assert_equal("canceled", subscription.status)
|
89
89
|
end
|
90
|
+
|
91
|
+
should "preview a subscription" do
|
92
|
+
mockResponse = mock('RestClient::Response')
|
93
|
+
mockResponse.stubs(:code).returns(200)
|
94
|
+
mockResponse.stubs(:body).returns('{"first_invoice": {"id": false}, "mrr": 9}')
|
95
|
+
mockResponse.stubs(:headers).returns({})
|
96
|
+
|
97
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
98
|
+
|
99
|
+
subscription = Subscription.new(@client, 123)
|
100
|
+
preview = subscription.preview(:customer => 1234, :plan => "enterprise")
|
101
|
+
assert_equal(preview[:first_invoice], {:id=>false})
|
102
|
+
end
|
90
103
|
end
|
91
104
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Invoiced
|
4
|
+
class TaskTest < Test::Unit::TestCase
|
5
|
+
should "return the api endpoint" do
|
6
|
+
task = Task.new(@client, "test")
|
7
|
+
assert_equal('/tasks/test', task.endpoint())
|
8
|
+
end
|
9
|
+
|
10
|
+
should "create a task" do
|
11
|
+
mockResponse = mock('RestClient::Response')
|
12
|
+
mockResponse.stubs(:code).returns(201)
|
13
|
+
mockResponse.stubs(:body).returns('{"id":"test","name":"Test Task"}')
|
14
|
+
mockResponse.stubs(:headers).returns({})
|
15
|
+
|
16
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
17
|
+
|
18
|
+
task = @client.Task.create({:name => "Test Task"})
|
19
|
+
|
20
|
+
assert_instance_of(Invoiced::Task, task)
|
21
|
+
assert_equal("test", task.id)
|
22
|
+
assert_equal('Test Task', task.name)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "retrieve a task" do
|
26
|
+
mockResponse = mock('RestClient::Response')
|
27
|
+
mockResponse.stubs(:code).returns(200)
|
28
|
+
mockResponse.stubs(:body).returns('{"id":"test","name":"Test Task"}')
|
29
|
+
mockResponse.stubs(:headers).returns({})
|
30
|
+
|
31
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
32
|
+
|
33
|
+
task = @client.Task.retrieve("test")
|
34
|
+
|
35
|
+
assert_instance_of(Invoiced::Task, task)
|
36
|
+
assert_equal("test", task.id)
|
37
|
+
assert_equal('Test Task', task.name)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "not update a task when no params" do
|
41
|
+
task = Task.new(@client, "test")
|
42
|
+
assert_false(task.save)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "update a task" do
|
46
|
+
mockResponse = mock('RestClient::Response')
|
47
|
+
mockResponse.stubs(:code).returns(200)
|
48
|
+
mockResponse.stubs(:body).returns('{"id":"test","name":"new contents"}')
|
49
|
+
mockResponse.stubs(:headers).returns({})
|
50
|
+
|
51
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
52
|
+
|
53
|
+
task = Task.new(@client, "test")
|
54
|
+
task.name = "new contents"
|
55
|
+
assert_true(task.save)
|
56
|
+
|
57
|
+
assert_equal(task.name, 'new contents')
|
58
|
+
end
|
59
|
+
|
60
|
+
should "list all tasks" do
|
61
|
+
mockResponse = mock('RestClient::Response')
|
62
|
+
mockResponse.stubs(:code).returns(200)
|
63
|
+
mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Task"}]')
|
64
|
+
mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/tasks?per_page=25&page=1>; rel="self", <https://api.invoiced.com/tasks?per_page=25&page=1>; rel="first", <https://api.invoiced.com/tasks?per_page=25&page=1>; rel="last"')
|
65
|
+
|
66
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
67
|
+
|
68
|
+
tasks, metadata = @client.Task.list
|
69
|
+
|
70
|
+
assert_instance_of(Array, tasks)
|
71
|
+
assert_equal(1, tasks.length)
|
72
|
+
assert_equal("test", tasks[0].id)
|
73
|
+
|
74
|
+
assert_instance_of(Invoiced::List, metadata)
|
75
|
+
assert_equal(15, metadata.total_count)
|
76
|
+
end
|
77
|
+
|
78
|
+
should "delete a task" 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
|
+
task = Task.new(@client, "test")
|
87
|
+
assert_true(task.delete)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|