quaderno 1.14.0 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +56 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -15
- data/README.md +1 -1
- data/Rakefile +4 -50
- data/changelog.md +9 -0
- data/lib/quaderno-ruby.rb +3 -4
- data/lib/quaderno-ruby/base.rb +106 -108
- data/lib/quaderno-ruby/behavior/block.rb +17 -19
- data/lib/quaderno-ruby/behavior/crud.rb +93 -95
- data/lib/quaderno-ruby/behavior/deliver.rb +16 -18
- data/lib/quaderno-ruby/behavior/payment.rb +32 -34
- data/lib/quaderno-ruby/behavior/retrieve.rb +23 -25
- data/lib/quaderno-ruby/contact.rb +6 -8
- data/lib/quaderno-ruby/credit.rb +10 -12
- data/lib/quaderno-ruby/document_item.rb +1 -3
- data/lib/quaderno-ruby/estimate.rb +5 -7
- data/lib/quaderno-ruby/evidence.rb +5 -7
- data/lib/quaderno-ruby/exceptions/exceptions.rb +42 -44
- data/lib/quaderno-ruby/expense.rb +6 -8
- data/lib/quaderno-ruby/helpers/authentication.rb +16 -18
- data/lib/quaderno-ruby/income.rb +8 -10
- data/lib/quaderno-ruby/invoice.rb +9 -11
- data/lib/quaderno-ruby/item.rb +3 -6
- data/lib/quaderno-ruby/payment.rb +1 -3
- data/lib/quaderno-ruby/receipt.rb +6 -8
- data/lib/quaderno-ruby/recurring.rb +4 -7
- data/lib/quaderno-ruby/report.rb +56 -58
- data/lib/quaderno-ruby/tax.rb +45 -47
- data/lib/quaderno-ruby/version.rb +3 -0
- data/lib/quaderno-ruby/webhook.rb +3 -5
- data/quaderno.gemspec +28 -148
- metadata +83 -84
- data/Gemfile.lock +0 -91
- data/VERSION +0 -1
- data/test/fixtures/quaderno_cassettes/.DS_Store +0 -0
- data/test/fixtures/quaderno_cassettes/all_contacts.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +0 -57
- data/test/fixtures/quaderno_cassettes/all_estimates.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_expenses.yml +0 -55
- data/test/fixtures/quaderno_cassettes/all_invoices.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_items.yml +0 -46
- data/test/fixtures/quaderno_cassettes/all_receipts.yml +0 -53
- data/test/fixtures/quaderno_cassettes/all_webhooks.yml +0 -214
- data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +0 -156
- data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +0 -278
- data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +0 -159
- data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +0 -196
- data/test/fixtures/quaderno_cassettes/deleted_contact.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +0 -190
- data/test/fixtures/quaderno_cassettes/deleted_item.yml +0 -128
- data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +0 -223
- data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +0 -257
- data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +0 -136
- data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +0 -143
- data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +0 -140
- data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_contact.yml +0 -95
- data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_estimate.yml +0 -97
- data/test/fixtures/quaderno_cassettes/found_expense.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_invoice.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_item.yml +0 -91
- data/test/fixtures/quaderno_cassettes/found_receipt.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_webhook.yml +0 -130
- data/test/fixtures/quaderno_cassettes/new_contact.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_estimate.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_evidence.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/new_invoice.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_item.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_receipt.yml +0 -173
- data/test/fixtures/quaderno_cassettes/new_webhook.yml +0 -87
- data/test/fixtures/quaderno_cassettes/paid_expense.yml +0 -98
- data/test/fixtures/quaderno_cassettes/paid_invoice.yml +0 -99
- data/test/fixtures/quaderno_cassettes/rate_limit.yml +0 -46
- data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +0 -138
- data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +0 -138
- data/test/fixtures/quaderno_cassettes/updated_contact.yml +0 -97
- data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +0 -101
- data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +0 -102
- data/test/fixtures/quaderno_cassettes/updated_estimate.yml +0 -185
- data/test/fixtures/quaderno_cassettes/updated_expense.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_invoice.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_item.yml +0 -93
- data/test/fixtures/quaderno_cassettes/updated_receipt.yml +0 -220
- data/test/fixtures/quaderno_cassettes/updated_webhook.yml +0 -175
- data/test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml +0 -44
- data/test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml +0 -44
- data/test/helper.rb +0 -32
- data/test/unit/test_quaderno_contacts.rb +0 -83
- data/test/unit/test_quaderno_contacts_thread_safe.rb +0 -104
- data/test/unit/test_quaderno_estimates.rb +0 -155
- data/test/unit/test_quaderno_evidences.rb +0 -41
- data/test/unit/test_quaderno_expenses.rb +0 -162
- data/test/unit/test_quaderno_invoices.rb +0 -177
- data/test/unit/test_quaderno_items.rb +0 -84
- data/test/unit/test_quaderno_receipts.rb +0 -156
- data/test/unit/test_quaderno_tax.rb +0 -46
- data/test/unit/test_quaderno_webhooks.rb +0 -93
data/test/helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler'
|
6
|
-
|
7
|
-
begin
|
8
|
-
Bundler.setup(:default, :test)
|
9
|
-
rescue Bundler::BundlerError => e
|
10
|
-
$stderr.puts e.message
|
11
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
-
exit e.status_code
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'vcr'
|
16
|
-
require 'test/unit'
|
17
|
-
require 'shoulda-context'
|
18
|
-
require 'quaderno-ruby'
|
19
|
-
|
20
|
-
VCR.configure do |c|
|
21
|
-
c.cassette_library_dir = 'test/fixtures/quaderno_cassettes'
|
22
|
-
c.ignore_localhost = false
|
23
|
-
c.hook_into :fakeweb
|
24
|
-
end
|
25
|
-
|
26
|
-
TEST_URL = 'http://development.lvh.me:3000/api/'
|
27
|
-
TEST_KEY = 'sk_test_B7xXrTspfeGukQqGN1pK'
|
28
|
-
TEST_OAUTH_ACCESS_TOKEN = '36b82411e6686581fe3d7d10fbe931a3fdc9265a353832f0e3ff6269bd319e12'
|
29
|
-
OLDEST_SUPPORTED_API_VERSION = 20160602
|
30
|
-
|
31
|
-
class Test::Unit::TestCase
|
32
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestQuadernoContact < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context 'using the default configuration with an authentication token' do
|
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 contacts') do
|
17
|
-
Quaderno::Contact.all 1, 2, 3
|
18
|
-
end
|
19
|
-
end
|
20
|
-
assert_raise ArgumentError do
|
21
|
-
VCR.use_cassette('found contact') do
|
22
|
-
Quaderno::Contact.find
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'get all contacts (populated db)' do
|
28
|
-
VCR.use_cassette('all contacts') do
|
29
|
-
contacts = Quaderno::Contact.all
|
30
|
-
assert_not_nil contacts
|
31
|
-
assert_kind_of Array, contacts
|
32
|
-
contacts.each do |contact|
|
33
|
-
assert_kind_of Quaderno::Contact, contact
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'find a contact' do
|
39
|
-
VCR.use_cassette('found contact') do
|
40
|
-
contacts = Quaderno::Contact.all
|
41
|
-
contact = Quaderno::Contact.find contacts[2].id
|
42
|
-
assert_kind_of Quaderno::Contact, contact
|
43
|
-
assert_equal contacts[2].id, contact.id
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
should 'create a contact' do
|
48
|
-
VCR.use_cassette('new contact') do
|
49
|
-
contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny')
|
50
|
-
assert_kind_of Quaderno::Contact, contact
|
51
|
-
assert_equal 'company', contact.kind
|
52
|
-
assert_equal 'Test_Skynet', contact.full_name
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
should 'update a contact' do
|
57
|
-
VCR.use_cassette('updated contact') do
|
58
|
-
contacts = Quaderno::Contact.all
|
59
|
-
contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing')
|
60
|
-
assert_kind_of Quaderno::Contact, contact
|
61
|
-
assert_equal 'Test_OCP', contact.first_name || contact.full_name
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
should 'delete a contact' do
|
66
|
-
VCR.use_cassette('deleted contact') do
|
67
|
-
new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw')
|
68
|
-
contacts_before = Quaderno::Contact.all
|
69
|
-
contact_id = contacts_before.last.id
|
70
|
-
Quaderno::Contact.delete contact_id
|
71
|
-
contacts_after = Quaderno::Contact.all
|
72
|
-
assert_not_equal contacts_after.last.id, contact_id
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
should 'know the rate limit' do
|
77
|
-
VCR.use_cassette('rate limit') do
|
78
|
-
rate_limit_info = Quaderno::Base.rate_limit_info
|
79
|
-
assert_operator rate_limit_info[:remaining], :< ,2000
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestQuadernoContactThreadSafe < Test::Unit::TestCase
|
4
|
-
context 'using the thread-safe configuration' do
|
5
|
-
context 'with an authentication token' do
|
6
|
-
should 'get all contacts (populated db)' do
|
7
|
-
VCR.use_cassette('all contacts by authentication token') do
|
8
|
-
puts Quaderno::Base.url
|
9
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
|
10
|
-
assert_not_nil contacts
|
11
|
-
assert_kind_of Array, contacts
|
12
|
-
contacts.each { |contact| assert_kind_of Quaderno::Contact, contact }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
should 'find a contact' do
|
17
|
-
VCR.use_cassette('found contact by authentication token') do
|
18
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
|
19
|
-
contact = Quaderno::Contact.find contacts[2].id, api_url: TEST_URL, auth_token: TEST_KEY
|
20
|
-
assert_kind_of Quaderno::Contact, contact
|
21
|
-
assert_equal contacts[2].id, contact.id
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
should 'create a contact' do
|
26
|
-
VCR.use_cassette('new contact by authentication token') do
|
27
|
-
contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny', api_url: TEST_URL, auth_token: TEST_KEY)
|
28
|
-
assert_kind_of Quaderno::Contact, contact
|
29
|
-
assert_equal 'company', contact.kind
|
30
|
-
assert_equal 'Test_Skynet', contact.full_name
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
should 'update a contact' do
|
35
|
-
VCR.use_cassette('updated contact by authentication token') do
|
36
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
|
37
|
-
contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing', api_url: TEST_URL, auth_token: TEST_KEY)
|
38
|
-
assert_kind_of Quaderno::Contact, contact
|
39
|
-
assert_equal 'Test_OCP', contact.first_name || contact.full_name
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
should 'delete a contact' do
|
44
|
-
VCR.use_cassette('deleted contact by authentication token') do
|
45
|
-
new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw', api_url: TEST_URL, auth_token: TEST_KEY)
|
46
|
-
contacts_before = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
|
47
|
-
contact_id = contacts_before.last.id
|
48
|
-
Quaderno::Contact.delete contact_id, api_url: TEST_URL, auth_token: TEST_KEY
|
49
|
-
contacts_after = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
|
50
|
-
assert_not_equal contacts_after.last.id, contact_id
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with an OAuth 2.0 access token' do
|
56
|
-
should 'get all contacts (populated db)' do
|
57
|
-
VCR.use_cassette('all contacts by access token') do
|
58
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
59
|
-
assert_not_nil contacts
|
60
|
-
assert_kind_of Array, contacts
|
61
|
-
contacts.each { |contact| assert_kind_of Quaderno::Contact, contact }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
should 'find a contact' do
|
66
|
-
VCR.use_cassette('found contact by access token') do
|
67
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
68
|
-
contact = Quaderno::Contact.find contacts[2].id, api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN
|
69
|
-
assert_kind_of Quaderno::Contact, contact
|
70
|
-
assert_equal contacts[2].id, contact.id
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
should 'create a contact' do
|
75
|
-
VCR.use_cassette('new contact by access token') do
|
76
|
-
contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
77
|
-
assert_kind_of Quaderno::Contact, contact
|
78
|
-
assert_equal 'company', contact.kind
|
79
|
-
assert_equal 'Test_Skynet', contact.full_name
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
should 'update a contact' do
|
84
|
-
VCR.use_cassette('updated contact by access token') do
|
85
|
-
contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
86
|
-
contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
87
|
-
assert_kind_of Quaderno::Contact, contact
|
88
|
-
assert_equal 'Test_OCP', contact.first_name || contact.full_name
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
should 'delete a contact' do
|
93
|
-
VCR.use_cassette('deleted contact by access token') do
|
94
|
-
new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
95
|
-
contacts_before = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
96
|
-
contact_id = contacts_before.last.id
|
97
|
-
Quaderno::Contact.delete contact_id, api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN
|
98
|
-
contacts_after = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
|
99
|
-
assert_not_equal contacts_after.last.id, contact_id
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestQuadernoEstimate < Test::Unit::TestCase
|
4
|
-
context 'A user with an authenticate token with estimates' 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 estimates') do
|
17
|
-
Quaderno::Estimate.all 1, 2, 3
|
18
|
-
end
|
19
|
-
end
|
20
|
-
assert_raise ArgumentError do
|
21
|
-
VCR.use_cassette('found estimate') do
|
22
|
-
Quaderno::Estimate.find
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'get all estimates (populated db)' do
|
28
|
-
VCR.use_cassette('all estimates') do
|
29
|
-
estimates = Quaderno::Estimate.all
|
30
|
-
assert_not_nil estimates
|
31
|
-
assert_kind_of Array, estimates
|
32
|
-
estimates.each do |estimate|
|
33
|
-
assert_kind_of Quaderno::Estimate, estimate
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'find an estimate' do
|
39
|
-
VCR.use_cassette('found estimate') do
|
40
|
-
estimates = Quaderno::Estimate.all
|
41
|
-
estimate = Quaderno::Estimate.find estimates.first.id
|
42
|
-
assert_kind_of Quaderno::Estimate, estimate
|
43
|
-
assert_equal estimates.first.id, estimate.id
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
should 'create an estimate' do
|
48
|
-
VCR.use_cassette('new estimate') do
|
49
|
-
contacts = Quaderno::Contact.all
|
50
|
-
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id ,
|
51
|
-
number: 'test number 42',
|
52
|
-
contact_name: contacts.first.full_name,
|
53
|
-
currency: 'EUR',
|
54
|
-
items_attributes: [
|
55
|
-
{
|
56
|
-
description: 'Aircraft',
|
57
|
-
quantity: '1.0',
|
58
|
-
unit_price: '0.0'
|
59
|
-
}
|
60
|
-
],
|
61
|
-
tags: 'tnt', payment_details: '',
|
62
|
-
notes: '')
|
63
|
-
assert_kind_of Quaderno::Estimate, estimate
|
64
|
-
assert_equal contacts.first.id, estimate.contact.id
|
65
|
-
assert_equal 'Aircraft', estimate.items.first.description
|
66
|
-
Quaderno::Estimate.delete(estimate.id)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should 'update an estimate' do
|
71
|
-
VCR.use_cassette('updated estimate') do
|
72
|
-
contacts = Quaderno::Contact.all
|
73
|
-
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id,
|
74
|
-
number: 'test number 4400',
|
75
|
-
contact_name: contacts.first.full_name,
|
76
|
-
currency: 'EUR',
|
77
|
-
items_attributes: [
|
78
|
-
{
|
79
|
-
description: 'Aircraft',
|
80
|
-
quantity: '1.0',
|
81
|
-
unit_price: '0.0'
|
82
|
-
}
|
83
|
-
],
|
84
|
-
tags: 'tnt', payment_details: '',
|
85
|
-
notes: '')
|
86
|
-
estimate = Quaderno::Estimate.update(estimate.id, payment_details: 'Show me the moneeeeeeeyy!!!!')
|
87
|
-
assert_kind_of Quaderno::Estimate, estimate
|
88
|
-
assert_equal 'Show me the moneeeeeeeyy!!!!', estimate.payment_details
|
89
|
-
Quaderno::Estimate.delete(estimate.id)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
should 'delete an estimate' do
|
94
|
-
VCR.use_cassette('deleted estimate') do
|
95
|
-
contacts = Quaderno::Contact.all
|
96
|
-
estimate = Quaderno::Estimate.create(contact_id: contacts.first.id,
|
97
|
-
number: 'test number 4400',
|
98
|
-
contact_name: contacts.first.full_name,
|
99
|
-
currency: 'EUR',
|
100
|
-
items_attributes: [
|
101
|
-
{
|
102
|
-
description: 'Aircraft',
|
103
|
-
quantity: '1.0',
|
104
|
-
unit_price: '0.0'
|
105
|
-
}
|
106
|
-
],
|
107
|
-
tags: 'tnt', payment_details: '',
|
108
|
-
notes: '')
|
109
|
-
Quaderno::Estimate.delete estimate.id
|
110
|
-
estimates = Quaderno::Estimate.all
|
111
|
-
assert_not_equal estimates.first.id, estimate.id
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
should 'deliver an estimate' do
|
116
|
-
VCR.use_cassette('delivered estimate') do
|
117
|
-
estimates = Quaderno::Estimate.all
|
118
|
-
rate_limit_before = Quaderno::Base.rate_limit_info
|
119
|
-
begin
|
120
|
-
rate_limit_after = estimates.first.deliver
|
121
|
-
rescue Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid
|
122
|
-
rate_limit_after = { remaining: (rate_limit_before[:remaining] - 1) }
|
123
|
-
end
|
124
|
-
assert_equal rate_limit_before[:remaining]-1, rate_limit_after[:remaining]
|
125
|
-
end
|
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
|
154
|
-
end
|
155
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestQuadernoEstimate < Test::Unit::TestCase
|
4
|
-
context 'A user with an authenticate token with invoices' do
|
5
|
-
setup do
|
6
|
-
Quaderno::Base.configure do |config|
|
7
|
-
config.auth_token = TEST_KEY
|
8
|
-
config.url = TEST_URL
|
9
|
-
config.api_version = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
VCR.use_cassette('evidence invoice') do
|
13
|
-
@contacts = Quaderno::Contact.all
|
14
|
-
@invoice = Quaderno::Invoice.create(contact_id: @contacts[0].id ,
|
15
|
-
contact_name: @contacts[0].full_name,
|
16
|
-
currency: 'EUR',
|
17
|
-
items_attributes: [
|
18
|
-
{
|
19
|
-
description: 'Aircraft',
|
20
|
-
quantity: '1.0',
|
21
|
-
unit_price: '0.0'
|
22
|
-
}
|
23
|
-
],
|
24
|
-
tags: 'tnt',
|
25
|
-
payment_details: '',
|
26
|
-
notes: '')
|
27
|
-
assert_kind_of Quaderno::Invoice, @invoice
|
28
|
-
assert_equal @contacts[0].id, @invoice.contact.id
|
29
|
-
assert_equal 'Aircraft', @invoice.items[0].description
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
should 'create an evidence' do
|
34
|
-
VCR.use_cassette('new evidence') do
|
35
|
-
evidence = Quaderno::Evidence.create(document_id: @invoice.id, billing_country: @contacts[0].country, bank_country: @contacts[0].country)
|
36
|
-
assert_kind_of Quaderno::Evidence, evidence
|
37
|
-
assert_equal @contacts[0].country, evidence.billing_country
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestQuadernoExpense < Test::Unit::TestCase
|
4
|
-
context 'A user with an authenticate token with expenses' 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 expenses') do
|
17
|
-
Quaderno::Expense.all 1, 2, 3
|
18
|
-
end
|
19
|
-
end
|
20
|
-
assert_raise ArgumentError do
|
21
|
-
VCR.use_cassette('found expense') do
|
22
|
-
Quaderno::Expense.find
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'get all expenses (populated db)' do
|
28
|
-
VCR.use_cassette('all expenses') do
|
29
|
-
expenses = Quaderno::Expense.all
|
30
|
-
assert_not_nil expenses
|
31
|
-
assert_kind_of Array, expenses
|
32
|
-
expenses.each do |expense|
|
33
|
-
assert_kind_of Quaderno::Expense, expense
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'find a expense' do
|
39
|
-
VCR.use_cassette('found expense') do
|
40
|
-
expenses = Quaderno::Expense.all
|
41
|
-
expense = Quaderno::Expense.find expenses.first.id
|
42
|
-
assert_kind_of Quaderno::Expense, expense
|
43
|
-
assert_equal expenses.first.id, expense.id
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
should 'create a expense' do
|
48
|
-
VCR.use_cassette('new expense') do
|
49
|
-
expenses = Quaderno::Expense.all
|
50
|
-
contacts = Quaderno::Contact.all
|
51
|
-
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
52
|
-
contact_name: contacts.first.full_name,
|
53
|
-
currency: 'EUR',
|
54
|
-
items_attributes: [
|
55
|
-
{
|
56
|
-
description: 'Aircraft',
|
57
|
-
quantity: '1.0',
|
58
|
-
unit_price: '0.0'
|
59
|
-
}
|
60
|
-
],
|
61
|
-
tags: 'tnt', payment_details: '',
|
62
|
-
notes: '')
|
63
|
-
assert_kind_of Quaderno::Expense, expense
|
64
|
-
assert_equal contacts.first.id, expense.contact.id
|
65
|
-
assert_equal 'Aircraft', expense.items.first.description
|
66
|
-
Quaderno::Expense.delete(expense.id)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should 'update an expense' do
|
71
|
-
VCR.use_cassette('updated expense') do
|
72
|
-
contacts = Quaderno::Contact.all
|
73
|
-
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
74
|
-
contact_name: contacts.first.full_name,
|
75
|
-
currency: 'EUR',
|
76
|
-
items_attributes: [
|
77
|
-
{
|
78
|
-
description: 'Aircraft',
|
79
|
-
quantity: '1.0',
|
80
|
-
unit_price: '0.0'
|
81
|
-
}
|
82
|
-
],
|
83
|
-
tags: 'tnt', payment_details: '',
|
84
|
-
notes: '')
|
85
|
-
expense = Quaderno::Expense.update(expense.id, po_number: 'Updated expense!')
|
86
|
-
assert_kind_of Quaderno::Expense, expense
|
87
|
-
assert_equal 'Updated expense!', expense.po_number
|
88
|
-
Quaderno::Expense.delete(expense.id)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
should 'delete an expense' do
|
93
|
-
VCR.use_cassette('deleted expense') do
|
94
|
-
contacts = Quaderno::Contact.all
|
95
|
-
expense = Quaderno::Expense.create(contact_id: contacts.first.id ,
|
96
|
-
contact_name: contacts.first.full_name,
|
97
|
-
currency: 'EUR',
|
98
|
-
items_attributes: [
|
99
|
-
{
|
100
|
-
description: 'Aircraft',
|
101
|
-
quantity: '1.0',
|
102
|
-
unit_price: '0.0'
|
103
|
-
}
|
104
|
-
],
|
105
|
-
tags: 'tnt', payment_details: '',
|
106
|
-
notes: '')
|
107
|
-
Quaderno::Expense.delete expense.id
|
108
|
-
expenses = Quaderno::Expense.all
|
109
|
-
assert_not_equal expenses.first.id, expense.id
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
should 'add a payment' do
|
114
|
-
VCR.use_cassette('paid expense') do
|
115
|
-
expenses = Quaderno::Expense.all
|
116
|
-
payment = expenses.first.add_payment(payment_method: "cash", amount: "10000")
|
117
|
-
assert_kind_of Quaderno::Payment, payment
|
118
|
-
assert_equal "cash", payment.payment_method
|
119
|
-
assert_equal 1000000, payment.amount_cents
|
120
|
-
assert_equal expenses.first.payments.last.id, payment.id
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
should 'remove a payment' do
|
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)
|
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
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|