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
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri:
|
5
|
+
uri: http://7h15154f4k370k3n@development.lvh.me:3000/api/taxes/calculate.json?country=ES&postal_code=08080
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -14,37 +14,23 @@ http_interactions:
|
|
14
14
|
code: 401
|
15
15
|
message: Unauthorized
|
16
16
|
headers:
|
17
|
-
|
18
|
-
-
|
19
|
-
date:
|
20
|
-
- Thu, 27 Nov 2014 12:26:50 GMT
|
17
|
+
x-frame-options:
|
18
|
+
- ALLOWALL
|
21
19
|
content-type:
|
22
20
|
- application/json; charset=utf-8
|
23
|
-
transfer-encoding:
|
24
|
-
- chunked
|
25
|
-
connection:
|
26
|
-
- close
|
27
|
-
status:
|
28
|
-
- 401 Unauthorized
|
29
|
-
x-ua-compatible:
|
30
|
-
- IE=Edge,chrome=1
|
31
21
|
cache-control:
|
32
|
-
- no-cache
|
33
|
-
set-cookie:
|
34
|
-
- ahoy_visitor=8e8063c8-23dd-4de2-bddc-6fe1f6f70c09; domain=.quadernoapp.com;
|
35
|
-
path=/; expires=Sun, 27-Nov-2016 12:26:50 GMT
|
36
|
-
- ahoy_visit=3be8bbfd-9aca-4073-99f0-061791482dc9; domain=.quadernoapp.com;
|
37
|
-
path=/; expires=Thu, 27-Nov-2014 16:26:50 GMT
|
38
|
-
- ahoy_track=true; domain=.quadernoapp.com; path=/
|
22
|
+
- no-cache
|
39
23
|
x-request-id:
|
40
|
-
-
|
24
|
+
- 97610b4b-4ca4-4c71-84db-ce9eb7daf230
|
41
25
|
x-runtime:
|
42
|
-
- '0.
|
43
|
-
|
44
|
-
-
|
26
|
+
- '0.058704'
|
27
|
+
connection:
|
28
|
+
- close
|
29
|
+
server:
|
30
|
+
- thin
|
45
31
|
body:
|
46
32
|
encoding: UTF-8
|
47
33
|
string: '{"error":"Wrong API key or the user does not exist."}'
|
48
34
|
http_version: '1.1'
|
49
|
-
recorded_at: Thu,
|
35
|
+
recorded_at: Thu, 23 Jun 2016 11:28:24 GMT
|
50
36
|
recorded_with: VCR 2.9.2
|
data/test/helper.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestQuadernoContact < Test::Unit::TestCase
|
4
|
-
context
|
4
|
+
context 'A user with an authenticate token with contacts' do
|
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
|
-
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 contacts') do
|
17
17
|
Quaderno::Contact.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 contact') do
|
22
22
|
Quaderno::Contact.find
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
should
|
27
|
+
should 'get all contacts (populated db)' do
|
28
28
|
VCR.use_cassette('all contacts') do
|
29
29
|
contacts = Quaderno::Contact.all
|
30
30
|
assert_not_nil contacts
|
@@ -35,7 +35,7 @@ class TestQuadernoContact < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
should
|
38
|
+
should 'find a contact' do
|
39
39
|
VCR.use_cassette('found contact') do
|
40
40
|
contacts = Quaderno::Contact.all
|
41
41
|
contact = Quaderno::Contact.find contacts[2].id
|
@@ -43,8 +43,8 @@ class TestQuadernoContact < Test::Unit::TestCase
|
|
43
43
|
assert_equal contacts[2].id, contact.id
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
47
|
-
should
|
46
|
+
|
47
|
+
should 'create a contact' do
|
48
48
|
VCR.use_cassette('new contact') do
|
49
49
|
contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny')
|
50
50
|
assert_kind_of Quaderno::Contact, contact
|
@@ -52,8 +52,8 @@ class TestQuadernoContact < Test::Unit::TestCase
|
|
52
52
|
assert_equal 'Test_Skynet', contact.full_name
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
56
|
-
should
|
55
|
+
|
56
|
+
should 'update a contact' do
|
57
57
|
VCR.use_cassette('updated contact') do
|
58
58
|
contacts = Quaderno::Contact.all
|
59
59
|
contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing')
|
@@ -61,8 +61,8 @@ class TestQuadernoContact < Test::Unit::TestCase
|
|
61
61
|
assert_equal 'Test_OCP', contact.first_name || contact.full_name
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
65
|
-
should
|
64
|
+
|
65
|
+
should 'delete a contact' do
|
66
66
|
VCR.use_cassette('deleted contact') do
|
67
67
|
new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw')
|
68
68
|
contacts_before = Quaderno::Contact.all
|
@@ -72,12 +72,11 @@ class TestQuadernoContact < Test::Unit::TestCase
|
|
72
72
|
assert_not_equal contacts_after.last.id, contact_id
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
76
|
-
should
|
75
|
+
|
76
|
+
should 'know the rate limit' do
|
77
77
|
VCR.use_cassette('rate limit') do
|
78
78
|
rate_limit_info = Quaderno::Base.rate_limit_info
|
79
|
-
|
80
|
-
assert_operator rate_limit_info[:remaining], :< ,2000
|
79
|
+
assert_operator rate_limit_info[:remaining], :< ,2000
|
81
80
|
end
|
82
81
|
end
|
83
82
|
end
|
@@ -5,19 +5,19 @@ class TestQuadernoEstimate < 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 estimates') do
|
17
17
|
Quaderno::Estimate.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 estimate') do
|
22
22
|
Quaderno::Estimate.find
|
23
23
|
end
|
@@ -43,22 +43,22 @@ class TestQuadernoEstimate < Test::Unit::TestCase
|
|
43
43
|
assert_equal estimates.first.id, estimate.id
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
should 'create an estimate' do
|
48
48
|
VCR.use_cassette('new estimate') do
|
49
49
|
contacts = Quaderno::Contact.all
|
50
50
|
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id ,
|
51
51
|
number: 'test number 42',
|
52
|
-
contact_name: contacts.first.full_name,
|
53
|
-
currency: 'EUR',
|
52
|
+
contact_name: contacts.first.full_name,
|
53
|
+
currency: 'EUR',
|
54
54
|
items_attributes: [
|
55
|
-
{
|
56
|
-
description: 'Aircraft',
|
57
|
-
quantity: '1.0',
|
58
|
-
unit_price: '0.0'
|
55
|
+
{
|
56
|
+
description: 'Aircraft',
|
57
|
+
quantity: '1.0',
|
58
|
+
unit_price: '0.0'
|
59
59
|
}
|
60
60
|
],
|
61
|
-
tags: 'tnt', payment_details: '',
|
61
|
+
tags: 'tnt', payment_details: '',
|
62
62
|
notes: '')
|
63
63
|
assert_kind_of Quaderno::Estimate, estimate
|
64
64
|
assert_equal contacts.first.id, estimate.contact.id
|
@@ -66,52 +66,52 @@ class TestQuadernoEstimate < Test::Unit::TestCase
|
|
66
66
|
Quaderno::Estimate.delete(estimate.id)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
should 'update an estimate' do
|
71
71
|
VCR.use_cassette('updated estimate') do
|
72
72
|
contacts = Quaderno::Contact.all
|
73
73
|
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id,
|
74
74
|
number: 'test number 4400',
|
75
|
-
contact_name: contacts.first.full_name,
|
76
|
-
currency: 'EUR',
|
75
|
+
contact_name: contacts.first.full_name,
|
76
|
+
currency: 'EUR',
|
77
77
|
items_attributes: [
|
78
|
-
{
|
79
|
-
description: 'Aircraft',
|
80
|
-
quantity: '1.0',
|
81
|
-
unit_price: '0.0'
|
78
|
+
{
|
79
|
+
description: 'Aircraft',
|
80
|
+
quantity: '1.0',
|
81
|
+
unit_price: '0.0'
|
82
82
|
}
|
83
83
|
],
|
84
|
-
tags: 'tnt', payment_details: '',
|
85
|
-
notes: '')
|
84
|
+
tags: 'tnt', payment_details: '',
|
85
|
+
notes: '')
|
86
86
|
estimate = Quaderno::Estimate.update(estimate.id, payment_details: 'Show me the moneeeeeeeyy!!!!')
|
87
87
|
assert_kind_of Quaderno::Estimate, estimate
|
88
88
|
assert_equal 'Show me the moneeeeeeeyy!!!!', estimate.payment_details
|
89
89
|
Quaderno::Estimate.delete(estimate.id)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
should 'delete an estimate' do
|
94
94
|
VCR.use_cassette('deleted estimate') do
|
95
95
|
contacts = Quaderno::Contact.all
|
96
96
|
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id,
|
97
97
|
number: 'test number 4400',
|
98
|
-
contact_name: contacts.first.full_name,
|
99
|
-
currency: 'EUR',
|
98
|
+
contact_name: contacts.first.full_name,
|
99
|
+
currency: 'EUR',
|
100
100
|
items_attributes: [
|
101
|
-
{
|
102
|
-
description: 'Aircraft',
|
103
|
-
quantity: '1.0',
|
104
|
-
unit_price: '0.0'
|
101
|
+
{
|
102
|
+
description: 'Aircraft',
|
103
|
+
quantity: '1.0',
|
104
|
+
unit_price: '0.0'
|
105
105
|
}
|
106
106
|
],
|
107
|
-
tags: 'tnt', payment_details: '',
|
107
|
+
tags: 'tnt', payment_details: '',
|
108
108
|
notes: '')
|
109
109
|
Quaderno::Estimate.delete estimate.id
|
110
110
|
estimates = Quaderno::Estimate.all
|
111
111
|
assert_not_equal estimates.first.id, estimate.id
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
should 'deliver an estimate' do
|
116
116
|
VCR.use_cassette('delivered estimate') do
|
117
117
|
estimates = Quaderno::Estimate.all
|
@@ -124,5 +124,32 @@ class TestQuadernoEstimate < Test::Unit::TestCase
|
|
124
124
|
assert_equal rate_limit_before[:remaining]-1, rate_limit_after[:remaining]
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
should 'override version' do
|
129
|
+
Quaderno::Base.api_version = OLDEST_SUPPORTED_API_VERSION
|
130
|
+
|
131
|
+
VCR.use_cassette('create estimate on downgraded API') do
|
132
|
+
contacts = Quaderno::Contact.all
|
133
|
+
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id ,
|
134
|
+
number: 'test number 42',
|
135
|
+
contact_name: contacts.first.full_name,
|
136
|
+
currency: 'EUR',
|
137
|
+
items_attributes: [
|
138
|
+
{
|
139
|
+
description: 'Aircraft',
|
140
|
+
quantity: '1.0',
|
141
|
+
unit_price: '0.0'
|
142
|
+
}
|
143
|
+
],
|
144
|
+
tags: 'tnt', payment_details: '',
|
145
|
+
notes: '')
|
146
|
+
assert_kind_of Quaderno::Estimate, estimate
|
147
|
+
assert estimate.total_cents.nil?
|
148
|
+
assert !estimate.total.nil?
|
149
|
+
assert_equal contacts.first.id, estimate.contact.id
|
150
|
+
assert_equal 'Aircraft', estimate.items.first.description
|
151
|
+
Quaderno::Estimate.delete(estimate.id)
|
152
|
+
end
|
153
|
+
end
|
127
154
|
end
|
128
155
|
end
|
@@ -5,19 +5,19 @@ class TestQuadernoExpense < 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 expenses') do
|
17
17
|
Quaderno::Expense.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 expense') do
|
22
22
|
Quaderno::Expense.find
|
23
23
|
end
|
@@ -43,22 +43,22 @@ class TestQuadernoExpense < Test::Unit::TestCase
|
|
43
43
|
assert_equal expenses.first.id, expense.id
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
should 'create a expense' do
|
48
48
|
VCR.use_cassette('new expense') do
|
49
49
|
expenses = Quaderno::Expense.all
|
50
50
|
contacts = Quaderno::Contact.all
|
51
51
|
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
52
|
-
contact_name: contacts.first.full_name,
|
53
|
-
currency: 'EUR',
|
52
|
+
contact_name: contacts.first.full_name,
|
53
|
+
currency: 'EUR',
|
54
54
|
items_attributes: [
|
55
|
-
{
|
56
|
-
description: 'Aircraft',
|
57
|
-
quantity: '1.0',
|
58
|
-
unit_price: '0.0'
|
55
|
+
{
|
56
|
+
description: 'Aircraft',
|
57
|
+
quantity: '1.0',
|
58
|
+
unit_price: '0.0'
|
59
59
|
}
|
60
60
|
],
|
61
|
-
tags: 'tnt', payment_details: '',
|
61
|
+
tags: 'tnt', payment_details: '',
|
62
62
|
notes: '')
|
63
63
|
assert_kind_of Quaderno::Expense, expense
|
64
64
|
assert_equal contacts.first.id, expense.contact.id
|
@@ -66,21 +66,21 @@ class TestQuadernoExpense < Test::Unit::TestCase
|
|
66
66
|
Quaderno::Expense.delete(expense.id)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
should 'update an expense' do
|
71
71
|
VCR.use_cassette('updated expense') do
|
72
72
|
contacts = Quaderno::Contact.all
|
73
73
|
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
74
|
-
contact_name: contacts.first.full_name,
|
75
|
-
currency: 'EUR',
|
74
|
+
contact_name: contacts.first.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', payment_details: '',
|
83
|
+
tags: 'tnt', payment_details: '',
|
84
84
|
notes: '')
|
85
85
|
expense = Quaderno::Expense.update(expense.id, currency: 'USD')
|
86
86
|
assert_kind_of Quaderno::Expense, expense
|
@@ -88,48 +88,75 @@ class TestQuadernoExpense < Test::Unit::TestCase
|
|
88
88
|
Quaderno::Expense.delete(expense.id)
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
should 'delete an expense' do
|
93
93
|
VCR.use_cassette('deleted expense') do
|
94
94
|
contacts = Quaderno::Contact.all
|
95
95
|
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
96
|
-
contact_name: contacts.first.full_name,
|
97
|
-
currency: 'EUR',
|
96
|
+
contact_name: contacts.first.full_name,
|
97
|
+
currency: 'EUR',
|
98
98
|
items_attributes: [
|
99
|
-
{
|
100
|
-
description: 'Aircraft',
|
101
|
-
quantity: '1.0',
|
102
|
-
unit_price: '0.0'
|
99
|
+
{
|
100
|
+
description: 'Aircraft',
|
101
|
+
quantity: '1.0',
|
102
|
+
unit_price: '0.0'
|
103
103
|
}
|
104
104
|
],
|
105
|
-
tags: 'tnt', payment_details: '',
|
105
|
+
tags: 'tnt', payment_details: '',
|
106
106
|
notes: '')
|
107
107
|
Quaderno::Expense.delete expense.id
|
108
108
|
expenses = Quaderno::Expense.all
|
109
109
|
assert_not_equal expenses.first.id, expense.id
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
should 'add a payment' do
|
114
114
|
VCR.use_cassette('paid expense') do
|
115
115
|
expenses = Quaderno::Expense.all
|
116
116
|
payment = expenses.first.add_payment(payment_method: "cash", amount: "10000")
|
117
117
|
assert_kind_of Quaderno::Payment, payment
|
118
118
|
assert_equal "cash", payment.payment_method
|
119
|
-
assert_equal
|
120
|
-
assert_equal expenses.first.payments.last.id, payment.id
|
119
|
+
assert_equal 1000000, payment.amount_cents
|
120
|
+
assert_equal expenses.first.payments.last.id, payment.id
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
should 'remove a payment' do
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
125
|
+
VCR.use_cassette('unpay an expense') do
|
126
|
+
expenses = Quaderno::Expense.all
|
127
|
+
expenses.first.add_payment(payment_method: "cash", amount: "10000")
|
128
|
+
payment = expenses.first.payments.last
|
129
|
+
array_length = expenses.first.payments.length
|
130
|
+
expenses.first.remove_payment(payment.id) unless payment.nil?
|
131
|
+
assert_equal (array_length.zero? ? array_length : array_length-1), expenses.first.payments.length
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'override version' do
|
136
|
+
Quaderno::Base.api_version = OLDEST_SUPPORTED_API_VERSION
|
137
|
+
|
138
|
+
VCR.use_cassette('create expense on downgraded API') do
|
139
|
+
expenses = Quaderno::Expense.all
|
140
|
+
contacts = Quaderno::Contact.all
|
141
|
+
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
142
|
+
contact_name: contacts.first.full_name,
|
143
|
+
currency: 'EUR',
|
144
|
+
items_attributes: [
|
145
|
+
{
|
146
|
+
description: 'Aircraft',
|
147
|
+
quantity: '1.0',
|
148
|
+
unit_price: '0.0'
|
149
|
+
}
|
150
|
+
],
|
151
|
+
tags: 'tnt', payment_details: '',
|
152
|
+
notes: '')
|
153
|
+
assert_kind_of Quaderno::Expense, expense
|
154
|
+
assert !expense.total.nil?
|
155
|
+
assert expense.total_cents.nil?
|
156
|
+
assert_equal contacts.first.id, expense.contact.id
|
157
|
+
assert_equal 'Aircraft', expense.items.first.description
|
158
|
+
Quaderno::Expense.delete(expense.id)
|
159
|
+
end
|
133
160
|
end
|
134
161
|
end
|
135
162
|
end
|