quaderno 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -6
- data/Gemfile.lock +8 -5
- data/README.md +7 -1
- data/VERSION +1 -1
- data/changelog.md +5 -0
- data/lib/quaderno-ruby/behavior/crud.rb +30 -36
- data/lib/quaderno-ruby/behavior/payment.rb +12 -19
- data/lib/quaderno-ruby/behavior/retrieve.rb +20 -0
- data/lib/quaderno-ruby/contact.rb +1 -0
- data/lib/quaderno-ruby/payment.rb +0 -2
- data/lib/quaderno-ruby/tax.rb +3 -3
- data/lib/quaderno-ruby/webhook.rb +0 -2
- data/lib/quaderno-ruby.rb +1 -1
- data/quaderno.gemspec +15 -3
- data/test/fixtures/quaderno_cassettes/all_contacts.yml +295 -31
- data/test/fixtures/quaderno_cassettes/all_estimates.yml +28 -36
- data/test/fixtures/quaderno_cassettes/all_expenses.yml +60 -34
- data/test/fixtures/quaderno_cassettes/all_invoices.yml +2888 -36
- data/test/fixtures/quaderno_cassettes/all_items.yml +22 -27
- data/test/fixtures/quaderno_cassettes/all_receipts.yml +56 -0
- data/test/fixtures/quaderno_cassettes/all_webhooks.yml +98 -126
- data/test/fixtures/quaderno_cassettes/calculate_tax.yml +38 -62
- data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +428 -0
- data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +510 -0
- data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +432 -0
- data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +193 -0
- data/test/fixtures/quaderno_cassettes/deleted_contact.yml +642 -113
- data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +385 -120
- data/test/fixtures/quaderno_cassettes/deleted_expense.yml +414 -118
- data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +3249 -120
- data/test/fixtures/quaderno_cassettes/deleted_item.yml +60 -75
- data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +222 -0
- data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +120 -152
- data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +76 -89
- data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +2935 -89
- data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +140 -0
- data/test/fixtures/quaderno_cassettes/found_contact.yml +319 -60
- data/test/fixtures/quaderno_cassettes/found_estimate.yml +53 -69
- data/test/fixtures/quaderno_cassettes/found_expense.yml +121 -65
- data/test/fixtures/quaderno_cassettes/found_invoice.yml +2916 -67
- data/test/fixtures/quaderno_cassettes/found_item.yml +50 -60
- data/test/fixtures/quaderno_cassettes/found_receipt.yml +101 -0
- data/test/fixtures/quaderno_cassettes/found_webhook.yml +60 -76
- data/test/fixtures/quaderno_cassettes/new_contact.yml +22 -29
- data/test/fixtures/quaderno_cassettes/new_estimate.yml +357 -84
- data/test/fixtures/quaderno_cassettes/new_expense.yml +414 -118
- data/test/fixtures/quaderno_cassettes/new_invoice.yml +361 -84
- data/test/fixtures/quaderno_cassettes/new_item.yml +22 -29
- data/test/fixtures/quaderno_cassettes/new_receipt.yml +169 -0
- data/test/fixtures/quaderno_cassettes/new_webhook.yml +38 -50
- data/test/fixtures/quaderno_cassettes/paid_expense.yml +79 -63
- data/test/fixtures/quaderno_cassettes/paid_invoice.yml +2907 -65
- data/test/fixtures/quaderno_cassettes/rate_limit.yml +22 -26
- data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +98 -85
- data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +2926 -87
- data/test/fixtures/quaderno_cassettes/updated_contact.yml +318 -62
- data/test/fixtures/quaderno_cassettes/updated_estimate.yml +402 -116
- data/test/fixtures/quaderno_cassettes/updated_expense.yml +395 -113
- data/test/fixtures/quaderno_cassettes/updated_invoice.yml +410 -116
- data/test/fixtures/quaderno_cassettes/updated_item.yml +49 -61
- data/test/fixtures/quaderno_cassettes/updated_receipt.yml +214 -0
- data/test/fixtures/quaderno_cassettes/updated_webhook.yml +82 -105
- data/test/fixtures/quaderno_cassettes/wrong_token.yml +11 -25
- data/test/helper.rb +4 -0
- data/test/unit/test_quaderno_contacts.rb +18 -19
- data/test/unit/test_quaderno_estimates.rb +58 -31
- data/test/unit/test_quaderno_expenses.rb +68 -41
- data/test/unit/test_quaderno_invoices.rb +74 -47
- data/test/unit/test_quaderno_items.rb +27 -26
- data/test/unit/test_quaderno_receipts.rb +156 -0
- data/test/unit/test_quaderno_tax.rb +10 -10
- data/test/unit/test_quaderno_webhooks.rb +19 -20
- metadata +14 -2
@@ -5,19 +5,19 @@ class TestQuadernoInvoice < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
setup do
|
7
7
|
Quaderno::Base.configure do |config|
|
8
|
-
config.auth_token =
|
9
|
-
config.
|
10
|
-
config.
|
8
|
+
config.auth_token = TEST_KEY
|
9
|
+
config.url = TEST_URL
|
10
|
+
config.api_version = nil
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
should 'get exception if pass wrong arguments' do
|
15
|
-
assert_raise ArgumentError do
|
15
|
+
assert_raise ArgumentError do
|
16
16
|
VCR.use_cassette('all invoices') do
|
17
17
|
Quaderno::Invoice.all 1, 2, 3
|
18
18
|
end
|
19
19
|
end
|
20
|
-
assert_raise ArgumentError do
|
20
|
+
assert_raise ArgumentError do
|
21
21
|
VCR.use_cassette('found invoice') do
|
22
22
|
Quaderno::Invoice.find
|
23
23
|
end
|
@@ -43,22 +43,22 @@ class TestQuadernoInvoice < Test::Unit::TestCase
|
|
43
43
|
assert_equal invoices.first.id, invoice.id
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
should 'create a invoice' do
|
48
48
|
VCR.use_cassette('new invoice') do
|
49
49
|
contacts = Quaderno::Contact.all
|
50
50
|
invoice = Quaderno::Invoice.create(contact_id: contacts[0].id ,
|
51
|
-
contact_name: contacts[0].full_name,
|
52
|
-
currency: 'EUR',
|
51
|
+
contact_name: contacts[0].full_name,
|
52
|
+
currency: 'EUR',
|
53
53
|
items_attributes: [
|
54
|
-
{
|
55
|
-
description: 'Aircraft',
|
56
|
-
quantity: '1.0',
|
57
|
-
unit_price: '0.0'
|
54
|
+
{
|
55
|
+
description: 'Aircraft',
|
56
|
+
quantity: '1.0',
|
57
|
+
unit_price: '0.0'
|
58
58
|
}
|
59
59
|
],
|
60
|
-
tags: 'tnt',
|
61
|
-
payment_details: '',
|
60
|
+
tags: 'tnt',
|
61
|
+
payment_details: '',
|
62
62
|
notes: '')
|
63
63
|
assert_kind_of Quaderno::Invoice, invoice
|
64
64
|
assert_equal contacts[0].id, invoice.contact.id
|
@@ -66,22 +66,22 @@ class TestQuadernoInvoice < Test::Unit::TestCase
|
|
66
66
|
Quaderno::Invoice.delete(invoice.id)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
should 'update an invoice' do
|
71
71
|
VCR.use_cassette('updated invoice') do
|
72
72
|
contacts = Quaderno::Contact.all
|
73
73
|
invoice = Quaderno::Invoice.create(contact_id: contacts[0].id ,
|
74
|
-
contact_name: contacts[0].full_name,
|
75
|
-
currency: 'EUR',
|
74
|
+
contact_name: contacts[0].full_name,
|
75
|
+
currency: 'EUR',
|
76
76
|
items_attributes: [
|
77
|
-
{
|
78
|
-
description: 'Aircraft',
|
79
|
-
quantity: '1.0',
|
80
|
-
unit_price: '0.0'
|
77
|
+
{
|
78
|
+
description: 'Aircraft',
|
79
|
+
quantity: '1.0',
|
80
|
+
unit_price: '0.0'
|
81
81
|
}
|
82
82
|
],
|
83
|
-
tags: 'tnt',
|
84
|
-
payment_details: '',
|
83
|
+
tags: 'tnt',
|
84
|
+
payment_details: '',
|
85
85
|
notes: '')
|
86
86
|
invoice = Quaderno::Invoice.update(invoice.id, payment_details: 'Show me the moneeeeeeeyy!!!!')
|
87
87
|
assert_kind_of Quaderno::Invoice, invoice
|
@@ -89,29 +89,29 @@ class TestQuadernoInvoice < Test::Unit::TestCase
|
|
89
89
|
Quaderno::Invoice.delete(invoice.id)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
should 'delete an invoice' do
|
94
94
|
VCR.use_cassette('deleted invoice') do
|
95
95
|
contacts = Quaderno::Contact.all
|
96
96
|
invoice = Quaderno::Invoice.create(contact_id: contacts[0].id ,
|
97
|
-
contact_name: contacts[0].full_name,
|
98
|
-
currency: 'EUR',
|
97
|
+
contact_name: contacts[0].full_name,
|
98
|
+
currency: 'EUR',
|
99
99
|
items_attributes: [
|
100
|
-
{
|
101
|
-
description: 'Aircraft',
|
102
|
-
quantity: '1.0',
|
103
|
-
unit_price: '0.0'
|
100
|
+
{
|
101
|
+
description: 'Aircraft',
|
102
|
+
quantity: '1.0',
|
103
|
+
unit_price: '0.0'
|
104
104
|
}
|
105
105
|
],
|
106
|
-
tags: 'tnt',
|
107
|
-
payment_details: '',
|
106
|
+
tags: 'tnt',
|
107
|
+
payment_details: '',
|
108
108
|
notes: '')
|
109
109
|
Quaderno::Invoice.delete invoice.id
|
110
110
|
invoices = Quaderno::Invoice.all
|
111
111
|
assert_not_equal invoices.first.id, invoice.id
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
should 'deliver an invoice' do
|
116
116
|
VCR.use_cassette('delivered invoice') do
|
117
117
|
invoices = Quaderno::Invoice.all
|
@@ -124,27 +124,54 @@ class TestQuadernoInvoice < Test::Unit::TestCase
|
|
124
124
|
assert_equal rate_limit_before[:remaining]-1, rate_limit_after[:remaining]
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
should 'add a payment' do
|
129
129
|
VCR.use_cassette('paid invoice') do
|
130
130
|
invoices = Quaderno::Invoice.all
|
131
|
-
payment = invoices.first.add_payment(payment_method:
|
131
|
+
payment = invoices.first.add_payment(payment_method: 'cash', amount: 100000000)
|
132
132
|
assert_kind_of Quaderno::Payment, payment
|
133
|
-
assert_equal
|
134
|
-
assert_equal
|
135
|
-
assert_equal invoices.first.payments.last.id, payment.id
|
133
|
+
assert_equal 'cash', payment.payment_method
|
134
|
+
assert_equal 10000000000, payment.amount_cents
|
135
|
+
assert_equal invoices.first.payments.last.id, payment.id
|
136
136
|
end
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
should 'remove a payment' do
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
140
|
+
VCR.use_cassette('unpay an invoice') do
|
141
|
+
invoices = Quaderno::Invoice.all
|
142
|
+
invoices.first.add_payment(payment_method: 'cash', amount: 100000000)
|
143
|
+
payment = invoices.first.payments.last
|
144
|
+
array_length = invoices.first.payments.length
|
145
|
+
invoices.first.remove_payment(payment.id) unless payment.nil?
|
146
|
+
assert_equal (array_length.zero? ? array_length : array_length-1), invoices.first.payments.length
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
should 'override version' do
|
151
|
+
Quaderno::Base.api_version = OLDEST_SUPPORTED_API_VERSION
|
152
|
+
|
153
|
+
VCR.use_cassette('create invoice on downgraded API') do
|
154
|
+
contacts = Quaderno::Contact.all
|
155
|
+
invoice = Quaderno::Invoice.create(contact_id: contacts[0].id ,
|
156
|
+
contact_name: contacts[0].full_name,
|
157
|
+
currency: 'EUR',
|
158
|
+
items_attributes: [
|
159
|
+
{
|
160
|
+
description: 'Aircraft',
|
161
|
+
quantity: '1.0',
|
162
|
+
unit_price: '0.0'
|
163
|
+
}
|
164
|
+
],
|
165
|
+
tags: 'tnt',
|
166
|
+
payment_details: '',
|
167
|
+
notes: '')
|
168
|
+
assert invoice.total_cents.nil?
|
169
|
+
assert !invoice.total.nil?
|
170
|
+
assert_kind_of Quaderno::Invoice, invoice
|
171
|
+
assert_equal contacts[0].id, invoice.contact.id
|
172
|
+
assert_equal 'Aircraft', invoice.items[0].description
|
173
|
+
Quaderno::Invoice.delete(invoice.id)
|
174
|
+
end
|
148
175
|
end
|
149
176
|
end
|
150
177
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestQuadernoItem < Test::Unit::TestCase
|
4
|
-
context
|
4
|
+
context 'A user with an authenticate token with items' do
|
5
5
|
|
6
6
|
setup do
|
7
7
|
Quaderno::Base.configure do |config|
|
8
|
-
config.auth_token =
|
9
|
-
config.
|
10
|
-
config.
|
11
|
-
end
|
8
|
+
config.auth_token = TEST_KEY
|
9
|
+
config.url = TEST_URL
|
10
|
+
config.api_version = nil
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
|
-
should
|
15
|
-
assert_raise ArgumentError do
|
14
|
+
should 'get exception if pass wrong arguments' do
|
15
|
+
assert_raise ArgumentError do
|
16
16
|
VCR.use_cassette('all items') do
|
17
17
|
Quaderno::Item.all 1, 2, 3
|
18
18
|
end
|
19
19
|
end
|
20
|
-
assert_raise ArgumentError do
|
20
|
+
assert_raise ArgumentError do
|
21
21
|
VCR.use_cassette('found item') do
|
22
22
|
Quaderno::Item.find
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
should
|
27
|
+
should 'get all items (populated db)' do
|
28
28
|
VCR.use_cassette('all items') do
|
29
29
|
items = Quaderno::Item.all
|
30
30
|
assert_not_nil items
|
@@ -35,16 +35,17 @@ class TestQuadernoItem < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
should
|
38
|
+
should 'find an item' do
|
39
39
|
VCR.use_cassette('found item') do
|
40
|
-
|
41
|
-
item = Quaderno::Item.find
|
40
|
+
new_item = Quaderno::Item.create(code: Time.now.to_i.to_s, name: 'Test_Skynet', unit_cost: 21.00)
|
41
|
+
item = Quaderno::Item.find new_item.id
|
42
|
+
|
42
43
|
assert_kind_of Quaderno::Item, item
|
43
|
-
assert_equal
|
44
|
+
assert_equal new_item.id, item.id
|
44
45
|
end
|
45
46
|
end
|
46
|
-
|
47
|
-
should
|
47
|
+
|
48
|
+
should 'create an item' do
|
48
49
|
VCR.use_cassette('new item') do
|
49
50
|
item = Quaderno::Item.create(code: '000000', name: 'Test_Skynet', unit_cost: 21.00)
|
50
51
|
assert_kind_of Quaderno::Item, item
|
@@ -52,31 +53,31 @@ class TestQuadernoItem < Test::Unit::TestCase
|
|
52
53
|
assert_equal 'Test_Skynet', item.name
|
53
54
|
end
|
54
55
|
end
|
55
|
-
|
56
|
-
should
|
56
|
+
|
57
|
+
should 'update an item' do
|
57
58
|
VCR.use_cassette('updated item') do
|
58
|
-
|
59
|
-
item = Quaderno::Item.update(
|
59
|
+
new_item = Quaderno::Item.create(code: Time.now.to_i.to_s, name: 'Test_Skynet', unit_cost: 21.00)
|
60
|
+
item = Quaderno::Item.update(new_item.id, name: 'Test_OCP')
|
61
|
+
|
60
62
|
assert_kind_of Quaderno::Item, item
|
61
63
|
assert_equal 'Test_OCP', item.name
|
62
64
|
end
|
63
65
|
end
|
64
|
-
|
65
|
-
should
|
66
|
+
|
67
|
+
should 'delete a item' do
|
66
68
|
VCR.use_cassette('deleted item') do
|
67
69
|
items_before = Quaderno::Item.all
|
68
70
|
item_id = items_before.last.id
|
69
71
|
Quaderno::Item.delete item_id
|
70
72
|
items_after = Quaderno::Item.all
|
71
|
-
|
73
|
+
assert_equal (items_before.length - items_after.length), 1
|
72
74
|
end
|
73
75
|
end
|
74
|
-
|
75
|
-
should
|
76
|
+
|
77
|
+
should 'know the rate limit' do
|
76
78
|
VCR.use_cassette('rate limit') do
|
77
79
|
rate_limit_info = Quaderno::Base.rate_limit_info
|
78
|
-
|
79
|
-
assert_operator rate_limit_info[:remaining], :< ,2000
|
80
|
+
assert_operator rate_limit_info[:remaining], :< ,2000
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestQuadernoReceipt < Test::Unit::TestCase
|
4
|
+
context 'A user with an authenticate token with receipts' do
|
5
|
+
|
6
|
+
setup do
|
7
|
+
Quaderno::Base.configure do |config|
|
8
|
+
config.auth_token = TEST_KEY
|
9
|
+
config.url = TEST_URL
|
10
|
+
config.api_version = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'get exception if pass wrong arguments' do
|
15
|
+
assert_raise ArgumentError do
|
16
|
+
VCR.use_cassette('all receipts') do
|
17
|
+
Quaderno::Receipt.all 1, 2, 3
|
18
|
+
end
|
19
|
+
end
|
20
|
+
assert_raise ArgumentError do
|
21
|
+
VCR.use_cassette('found receipt') do
|
22
|
+
Quaderno::Receipt.find
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'get all receipts (populated db)' do
|
28
|
+
VCR.use_cassette('all receipts') do
|
29
|
+
receipts = Quaderno::Receipt.all
|
30
|
+
assert_not_nil receipts
|
31
|
+
assert_kind_of Array, receipts
|
32
|
+
receipts.each do |receipt|
|
33
|
+
assert_kind_of Quaderno::Receipt, receipt
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'find a receipt' do
|
39
|
+
VCR.use_cassette('found receipt') do
|
40
|
+
receipts = Quaderno::Receipt.all
|
41
|
+
receipt = Quaderno::Receipt.find receipts.first.id
|
42
|
+
assert_kind_of Quaderno::Receipt, receipt
|
43
|
+
assert_equal receipts.first.id, receipt.id
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'create a receipt' do
|
48
|
+
VCR.use_cassette('new receipt') do
|
49
|
+
contact = Quaderno::Contact.create(first_name: 'Test customer')
|
50
|
+
receipt = Quaderno::Receipt.create(contact_id: contact.id ,
|
51
|
+
currency: 'EUR',
|
52
|
+
items_attributes: [
|
53
|
+
{
|
54
|
+
description: 'Aircraft',
|
55
|
+
quantity: '1.0',
|
56
|
+
unit_price: '0.0'
|
57
|
+
}
|
58
|
+
],
|
59
|
+
tags: 'tnt',
|
60
|
+
payment_method: :cash,
|
61
|
+
notes: '')
|
62
|
+
assert_kind_of Quaderno::Receipt, receipt
|
63
|
+
assert_equal contact.id, receipt.contact.id
|
64
|
+
assert_equal 'Aircraft', receipt.items[0].description
|
65
|
+
Quaderno::Receipt.delete(receipt.id)
|
66
|
+
Quaderno::Contact.delete(contact.id)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'update an receipt' do
|
71
|
+
VCR.use_cassette('updated receipt') do
|
72
|
+
contact = Quaderno::Contact.create(first_name: 'Test customer')
|
73
|
+
receipt = Quaderno::Receipt.create(contact_id: contact.id ,
|
74
|
+
currency: 'EUR',
|
75
|
+
items_attributes: [
|
76
|
+
{
|
77
|
+
description: 'Aircraft',
|
78
|
+
quantity: '1.0',
|
79
|
+
unit_price: '0.0'
|
80
|
+
}
|
81
|
+
],
|
82
|
+
tags: 'tnt',
|
83
|
+
payment_method: :cash,
|
84
|
+
notes: '')
|
85
|
+
receipt = Quaderno::Receipt.update(receipt.id, notes: 'Show me the moneeeeeeeyy!!!!')
|
86
|
+
assert_kind_of Quaderno::Receipt, receipt
|
87
|
+
assert_equal 'Show me the moneeeeeeeyy!!!!', receipt.notes
|
88
|
+
Quaderno::Receipt.delete(receipt.id)
|
89
|
+
Quaderno::Contact.delete(contact.id)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'delete an receipt' do
|
94
|
+
VCR.use_cassette('deleted receipt') do
|
95
|
+
contact = Quaderno::Contact.create(first_name: 'Test customer')
|
96
|
+
receipt = Quaderno::Receipt.create(contact_id: contact.id ,
|
97
|
+
currency: 'EUR',
|
98
|
+
items_attributes: [
|
99
|
+
{
|
100
|
+
description: 'Aircraft',
|
101
|
+
quantity: '1.0',
|
102
|
+
unit_price: '0.0'
|
103
|
+
}
|
104
|
+
],
|
105
|
+
tags: 'tnt',
|
106
|
+
payment_method: :cash,
|
107
|
+
notes: '')
|
108
|
+
Quaderno::Receipt.delete receipt.id
|
109
|
+
Quaderno::Contact.delete(contact.id)
|
110
|
+
|
111
|
+
receipts = Quaderno::Receipt.all
|
112
|
+
assert_not_equal receipts.first.id, receipt.id
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'deliver an receipt' do
|
117
|
+
VCR.use_cassette('delivered receipt') do
|
118
|
+
receipts = Quaderno::Receipt.all
|
119
|
+
rate_limit_before = Quaderno::Base.rate_limit_info
|
120
|
+
begin
|
121
|
+
rate_limit_after = receipts.first.deliver
|
122
|
+
rescue Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid
|
123
|
+
rate_limit_after = { remaining: (rate_limit_before[:remaining] - 1) }
|
124
|
+
end
|
125
|
+
assert_equal rate_limit_before[:remaining]-1, rate_limit_after[:remaining]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
should 'override version' do
|
130
|
+
Quaderno::Base.api_version = OLDEST_SUPPORTED_API_VERSION
|
131
|
+
|
132
|
+
VCR.use_cassette('create receipt on downgraded API') do
|
133
|
+
contact = Quaderno::Contact.create(first_name: 'Test customer')
|
134
|
+
receipt = Quaderno::Receipt.create(contact_id: contact.id ,
|
135
|
+
currency: 'EUR',
|
136
|
+
items_attributes: [
|
137
|
+
{
|
138
|
+
description: 'Aircraft',
|
139
|
+
quantity: '1.0',
|
140
|
+
unit_price: '0.0'
|
141
|
+
}
|
142
|
+
],
|
143
|
+
tags: 'tnt',
|
144
|
+
payment_method: :cash,
|
145
|
+
notes: '')
|
146
|
+
assert receipt.total_cents.nil?
|
147
|
+
assert !receipt.total.nil?
|
148
|
+
assert_kind_of Quaderno::Receipt, receipt
|
149
|
+
assert_equal contact.id, receipt.contact.id
|
150
|
+
assert_equal 'Aircraft', receipt.items[0].description
|
151
|
+
Quaderno::Receipt.delete(receipt.id)
|
152
|
+
Quaderno::Contact.delete(contact.id)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -1,22 +1,23 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestQuadernoTax < Test::Unit::TestCase
|
4
|
-
context
|
4
|
+
context 'A user with an authenticate token with webhooks' do
|
5
5
|
|
6
6
|
setup do
|
7
7
|
Quaderno::Base.configure do |config|
|
8
|
-
config.auth_token =
|
9
|
-
config.
|
10
|
-
|
8
|
+
config.auth_token = TEST_KEY
|
9
|
+
config.url = TEST_URL
|
10
|
+
config.api_version = nil
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
|
-
should
|
14
|
+
should 'raise exception if pass wrong arguments' do
|
14
15
|
assert_raise ArgumentError do
|
15
16
|
Quaderno::Tax.calculate 1, 2, 3
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
should
|
20
|
+
should 'raise exception if token is wrong' do
|
20
21
|
VCR.use_cassette('wrong token') do
|
21
22
|
assert_raise Quaderno::Exceptions::InvalidSubdomainOrToken do
|
22
23
|
Quaderno::Base.auth_token = '7h15154f4k370k3n'
|
@@ -25,16 +26,15 @@ class TestQuadernoTax < Test::Unit::TestCase
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
should
|
29
|
+
should 'calculate tax' do
|
29
30
|
VCR.use_cassette('calculate tax') do
|
30
31
|
tax = Quaderno::Tax.calculate(country: 'ES', postal_code: '08080')
|
31
|
-
assert_equal '
|
32
|
+
assert_equal 'IVA', tax.name
|
32
33
|
assert_equal 21.0, tax.rate
|
33
34
|
|
34
35
|
tax = Quaderno::Tax.calculate(country: 'ES', postal_code: '35007')
|
35
|
-
|
36
|
+
assert_equal 'IVA',tax.name
|
36
37
|
assert tax.rate.zero?
|
37
|
-
assert_equal 'VAT reverse charged', tax.notes
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestQuadernoWebhook < Test::Unit::TestCase
|
4
|
-
context
|
4
|
+
context 'A user with an authenticate token with webhooks' do
|
5
5
|
|
6
6
|
setup do
|
7
7
|
Quaderno::Base.configure do |config|
|
8
|
-
config.auth_token =
|
9
|
-
config.
|
10
|
-
config.
|
11
|
-
end
|
8
|
+
config.auth_token = TEST_KEY
|
9
|
+
config.url = TEST_URL
|
10
|
+
config.api_version = nil
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
|
-
should
|
15
|
-
assert_raise ArgumentError do
|
14
|
+
should 'get exception if pass wrong arguments' do
|
15
|
+
assert_raise ArgumentError do
|
16
16
|
VCR.use_cassette('all webhooks') do
|
17
17
|
Quaderno::Webhook.all 1, 2, 3
|
18
18
|
end
|
19
19
|
end
|
20
|
-
assert_raise ArgumentError do
|
20
|
+
assert_raise ArgumentError do
|
21
21
|
VCR.use_cassette('found webhook') do
|
22
22
|
Quaderno::Webhook.find
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
should
|
27
|
+
should 'get all webhooks (populated db)' do
|
28
28
|
VCR.use_cassette('all webhooks') do
|
29
29
|
webhook_1 = Quaderno::Webhook.create(url: 'http://google.com', events_types: ['invoice.created', 'invoice.updated'])
|
30
30
|
webhook_2 = Quaderno::Webhook.create(url: 'http://quadernoapp.com', events_types: ['expense.created', 'expense.updated', 'contact.deleted'])
|
@@ -39,7 +39,7 @@ class TestQuadernoWebhook < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
should
|
42
|
+
should 'find a webhook' do
|
43
43
|
VCR.use_cassette('found webhook') do
|
44
44
|
webhook = Quaderno::Webhook.create(url: 'http://quadernoapp.com', events_types: ['invoice.created', 'expense.updated'])
|
45
45
|
webhooks = Quaderno::Webhook.all
|
@@ -48,8 +48,8 @@ class TestQuadernoWebhook < Test::Unit::TestCase
|
|
48
48
|
Quaderno::Webhook.delete webhook.id
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
should
|
51
|
+
|
52
|
+
should 'create a webhook' do
|
53
53
|
VCR.use_cassette('new webhook') do
|
54
54
|
webhook = Quaderno::Webhook.create(url: 'http://quadernoapp.com', events_types: ['invoice.created', 'expense.updated'])
|
55
55
|
assert_kind_of Quaderno::Webhook, webhook
|
@@ -58,8 +58,8 @@ class TestQuadernoWebhook < Test::Unit::TestCase
|
|
58
58
|
Quaderno::Webhook.delete webhook.id
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
|
-
should
|
61
|
+
|
62
|
+
should 'update a webhook' do
|
63
63
|
VCR.use_cassette('updated webhook') do
|
64
64
|
Quaderno::Webhook.create(url: 'http://quadernoapp.com', events_types: ['invoice.created', 'expense.updated'])
|
65
65
|
webhooks = Quaderno::Webhook.all
|
@@ -69,8 +69,8 @@ class TestQuadernoWebhook < Test::Unit::TestCase
|
|
69
69
|
Quaderno::Webhook.delete webhook.id
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
73
|
-
should
|
72
|
+
|
73
|
+
should 'delete a webhook' do
|
74
74
|
VCR.use_cassette('deleted webhook') do
|
75
75
|
webhook_1 = Quaderno::Webhook.create(url: 'http://google.com', events_types: ['invoice.created', 'expense.updated'])
|
76
76
|
webhook_2 = Quaderno::Webhook.create(url: 'http://quadernoapp.com', events_types: ['invoice.created', 'expense.updated'])
|
@@ -82,12 +82,11 @@ class TestQuadernoWebhook < Test::Unit::TestCase
|
|
82
82
|
Quaderno::Webhook.delete webhooks_after.last.id
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
86
|
-
should
|
85
|
+
|
86
|
+
should 'know the rate limit' do
|
87
87
|
VCR.use_cassette('rate limit') do
|
88
88
|
rate_limit_info = Quaderno::Base.rate_limit_info
|
89
|
-
|
90
|
-
assert_operator rate_limit_info[:remaining], :< ,2000
|
89
|
+
assert_operator rate_limit_info[:remaining], :< ,2000
|
91
90
|
end
|
92
91
|
end
|
93
92
|
end
|