boletosimples 0.4.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +9 -17
  3. data/README.md +14 -54
  4. data/lib/boletosimples.rb +9 -6
  5. data/lib/boletosimples/configuration.rb +19 -28
  6. data/lib/boletosimples/last_request.rb +12 -9
  7. data/lib/boletosimples/middlewares/bearer.rb +12 -0
  8. data/lib/boletosimples/middlewares/debug.rb +30 -0
  9. data/lib/boletosimples/middlewares/last_request.rb +3 -1
  10. data/lib/boletosimples/middlewares/raise_error.rb +9 -2
  11. data/lib/boletosimples/middlewares/user_agent.rb +3 -1
  12. data/lib/boletosimples/resources/bank_billet.rb +5 -11
  13. data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
  14. data/lib/boletosimples/resources/bank_billet_discharge.rb +6 -0
  15. data/lib/boletosimples/resources/bank_billet_payment.rb +6 -0
  16. data/lib/boletosimples/resources/bank_billet_remittance.rb +6 -0
  17. data/lib/boletosimples/resources/base_model.rb +3 -1
  18. data/lib/boletosimples/resources/customer.rb +3 -1
  19. data/lib/boletosimples/resources/customer_import.rb +5 -3
  20. data/lib/boletosimples/resources/customer_subscription.rb +3 -10
  21. data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
  22. data/lib/boletosimples/resources/discharge.rb +4 -11
  23. data/lib/boletosimples/resources/email_delivery.rb +6 -0
  24. data/lib/boletosimples/resources/event.rb +3 -1
  25. data/lib/boletosimples/resources/installment.rb +3 -1
  26. data/lib/boletosimples/resources/remittance.rb +3 -1
  27. data/lib/boletosimples/resources/sms_delivery.rb +6 -0
  28. data/lib/boletosimples/resources/transaction.rb +3 -1
  29. data/lib/boletosimples/resources/webhook.rb +3 -1
  30. data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
  31. data/lib/boletosimples/response_error.rb +8 -3
  32. data/lib/boletosimples/version.rb +3 -1
  33. data/spec/boletosimples/configuration_spec.rb +71 -99
  34. data/spec/boletosimples/last_request_spec.rb +16 -28
  35. data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
  36. data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +12 -0
  37. data/spec/boletosimples/resources/bank_billet_payment_spec.rb +12 -0
  38. data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +12 -0
  39. data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
  40. data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
  41. data/spec/boletosimples/resources/customer_spec.rb +52 -39
  42. data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
  43. data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
  44. data/spec/boletosimples/resources/discharge_spec.rb +64 -11
  45. data/spec/boletosimples/resources/email_delivery_spec.rb +12 -0
  46. data/spec/boletosimples/resources/event_spec.rb +7 -12
  47. data/spec/boletosimples/resources/installment_spec.rb +61 -32
  48. data/spec/boletosimples/resources/remittance_spec.rb +7 -12
  49. data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
  50. data/spec/boletosimples/resources/transactions_spec.rb +7 -12
  51. data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
  52. data/spec/boletosimples/resources/webhook_spec.rb +7 -12
  53. data/spec/fixtures/discharge.RET +3 -0
  54. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +536 -88
  55. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +537 -91
  56. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +34 -92
  57. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -20
  58. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +28 -17
  59. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +43 -27
  60. data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +83 -0
  61. data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +51 -27
  62. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +131 -20
  63. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +34 -20
  64. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +30 -19
  65. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +41 -21
  66. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +38 -18
  67. data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +97 -0
  68. data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +75 -0
  69. data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +126 -0
  70. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +79 -32
  71. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +30 -17
  72. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +28 -17
  73. data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +33 -21
  74. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +33 -19
  75. data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +43 -60
  76. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +37 -51
  77. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +38 -52
  78. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +43 -68
  79. data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +40 -54
  80. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +102 -52
  81. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +40 -50
  82. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +36 -48
  83. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +48 -53
  84. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +44 -50
  85. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +45 -133
  86. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +44 -55
  87. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +37 -52
  88. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +39 -53
  89. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +43 -70
  90. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +40 -55
  91. data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +64 -33
  92. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +70 -0
  93. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +69 -0
  94. data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +84 -0
  95. data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +71 -0
  96. data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +73 -0
  97. data/spec/fixtures/vcr_cassettes/resources/event/all.yml +490 -166
  98. data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +418 -52
  99. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +41 -52
  100. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +36 -48
  101. data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +48 -53
  102. data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +44 -52
  103. data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +53 -33
  104. data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +73 -0
  105. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +34 -22
  106. data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +42 -33
  107. data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +1232 -54
  108. data/spec/spec_helper.rb +3 -20
  109. data/spec/support/stub_env.rb +7 -0
  110. data/spec/support/vcr.rb +3 -4
  111. metadata +120 -55
  112. data/.coveralls.yml +0 -2
  113. data/.gitignore +0 -19
  114. data/.ruby-gemset +0 -1
  115. data/.ruby-version +0 -1
  116. data/.travis.yml +0 -12
  117. data/Gemfile +0 -4
  118. data/Rakefile +0 -6
  119. data/boletosimples.gemspec +0 -38
  120. data/lib/boletosimples/extra.rb +0 -8
  121. data/lib/boletosimples/resources/partner/user.rb +0 -7
  122. data/lib/oauth2_patch.rb +0 -24
  123. data/spec/boletosimples/extra_spec.rb +0 -31
  124. data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
  125. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
  126. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
  127. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
  128. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
  129. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
  130. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
  131. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
  132. data/spec/spec.opts +0 -8
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  module Middleware
3
5
  class UserAgent < Faraday::Middleware
4
6
  def call(env)
5
- env[:request_headers]["User-Agent"] = BoletoSimples.configuration.user_agent
7
+ env[:request_headers]['User-Agent'] = BoletoSimples.configuration.user_agent
6
8
  @app.call(env)
7
9
  end
8
10
  end
@@ -1,14 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class BankBillet < BaseModel
3
-
4
- def cancel
5
- self.class.request(:_method => :put, :_path => self.class.build_request_path('bank_billets/:id/cancel', {self.class.primary_key => id})) do |parsed_data, response|
6
- assign_attributes(self.class.parse(parsed_data[:data])) if parsed_data[:data].any?
7
- @metadata = parsed_data[:metadata]
8
- @response_errors = parsed_data[:errors]
9
- @response = response
10
- end
11
- return @response.success?
12
- end
5
+ custom_put :pay, :cancel
6
+ custom_post :duplicate
13
7
  end
14
- end
8
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class BankBilletAccount < BaseModel
3
5
  end
4
- end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ class BankBilletDischarge < BaseModel
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ class BankBilletPayment < BaseModel
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ class BankBilletRemittance < BaseModel
5
+ end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class BaseModel
3
5
  include Her::Model
@@ -5,4 +7,4 @@ module BoletoSimples
5
7
  parse_root_in_json true
6
8
  include_root_in_json true
7
9
  end
8
- end
10
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Customer < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class CustomerImport < BaseModel
3
- collection_path "imports/customers"
4
- resource_path "imports/customers/:id"
5
+ collection_path 'imports/customers'
6
+ resource_path 'imports/customers/:id'
5
7
  end
6
- end
8
+ end
@@ -1,14 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class CustomerSubscription < BaseModel
3
-
4
- def next_charge
5
- self.class.request(:_method => :post, :_path => self.class.build_request_path('customer_subscriptions/:id/next_charge', {self.class.primary_key => id})) do |parsed_data, response|
6
- assign_attributes(self.class.parse(parsed_data[:data])) if parsed_data[:data].any?
7
- @metadata = parsed_data[:metadata]
8
- @response_errors = parsed_data[:errors]
9
- @response = response
10
- end
11
- return @response.success?
12
- end
5
+ custom_post :next_charge
13
6
  end
14
7
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class CustomerSubscriptionImport < BaseModel
3
- collection_path "imports/customer_subscriptions"
4
- resource_path "imports/customer_subscriptions/:id"
5
+ collection_path 'imports/customer_subscriptions'
6
+ resource_path 'imports/customer_subscriptions/:id'
5
7
  end
6
- end
8
+ end
@@ -1,14 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Discharge < BaseModel
3
-
4
- def pay_off
5
- self.class.request(:_method => :put, :_path => self.class.build_request_path('discharges/:id/pay_off', {self.class.primary_key => id})) do |parsed_data, response|
6
- assign_attributes(self.class.parse(parsed_data[:data])) if parsed_data[:data].any?
7
- @metadata = parsed_data[:metadata]
8
- @response_errors = parsed_data[:errors]
9
- @response = response
10
- end
11
- return @response.success?
12
- end
5
+ custom_put :pay_off
13
6
  end
14
- end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ class EmailDelivery < BaseModel
5
+ end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Event < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Installment < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Remittance < BaseModel
3
5
  end
4
- end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ class SmsDelivery < BaseModel
5
+ end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Transaction < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Webhook < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class WebhookDelivery < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  # BoletoSimples::ResponseError
3
5
  # Exception that gets raised if the response is an error (4xx or 5xx)
@@ -29,15 +31,18 @@ module BoletoSimples
29
31
  @status = response[:status].to_i
30
32
  @method = response[:method].to_s.upcase
31
33
  @url = response[:url]
32
- @error_message = @body[:error]
34
+
35
+ errors = response[:body][:errors]
36
+ @error_message = errors.first[:title] unless errors.blank?
33
37
 
34
38
  super
35
39
  end
36
40
 
37
41
  def to_s
38
- msg = "#{status} #{method} #{url}"
42
+ msg = ''
43
+ msg += "#{status} #{method} #{url}"
39
44
  msg << " (#{error_message})" unless error_message.blank?
40
45
  msg
41
46
  end
42
47
  end
43
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
- VERSION = '0.4.2'
4
+ VERSION = '1.0.3'
3
5
  end
@@ -1,100 +1,72 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
1
+ # # frozen_string_literal: true
3
2
 
4
- RSpec.describe BoletoSimples::Configuration do
5
- before {
6
- @last_env = {}
7
- @last_env['BOLETOSIMPLES_ENV'] = ENV['BOLETOSIMPLES_ENV']
8
- @last_env['BOLETOSIMPLES_APP_ID'] = ENV['BOLETOSIMPLES_APP_ID']
9
- @last_env['BOLETOSIMPLES_APP_SECRET'] = ENV['BOLETOSIMPLES_APP_SECRET']
10
- @last_env['BOLETOSIMPLES_ACCESS_TOKEN'] = ENV['BOLETOSIMPLES_ACCESS_TOKEN']
11
- }
12
- after {
13
- ENV['BOLETOSIMPLES_ENV'] = @last_env['BOLETOSIMPLES_ENV']
14
- ENV['BOLETOSIMPLES_APP_ID'] = @last_env['BOLETOSIMPLES_APP_ID']
15
- ENV['BOLETOSIMPLES_APP_SECRET'] = @last_env['BOLETOSIMPLES_APP_SECRET']
16
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = @last_env['BOLETOSIMPLES_ACCESS_TOKEN']
17
- }
18
- describe 'defaults' do
19
- before {
20
- ENV['BOLETOSIMPLES_ENV'] = nil
21
- ENV['BOLETOSIMPLES_APP_ID'] = nil
22
- ENV['BOLETOSIMPLES_APP_SECRET'] = nil
23
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = nil
24
- }
25
- subject { BoletoSimples::Configuration.new }
26
- before { subject.setup_her}
27
- it { expect(subject.environment).to eq(:sandbox) }
28
- it { expect(subject.base_uri).to eq('https://sandbox.boletosimples.com.br/api/v1') }
29
- it { expect(subject.application_id).to be_nil }
30
- it { expect(subject.application_secret).to be_nil }
31
- it { expect(subject.access_token).to be_nil }
32
- it { expect(subject.cache).to be_nil }
33
- it { expect(subject).not_to be_access_token }
34
- end
35
- describe 'environment variables' do
36
- before {
37
- ENV['BOLETOSIMPLES_ENV'] = 'production'
38
- ENV['BOLETOSIMPLES_APP_ID'] = 'app-id'
39
- ENV['BOLETOSIMPLES_APP_SECRET'] = 'app-secret'
40
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = 'access-token'
41
- }
42
- before { BoletoSimples.configure }
43
- subject { BoletoSimples.configuration }
44
- # subject { BoletoSimples::Configuration.new }
45
- it { expect(subject.environment).to eq(:production) }
46
- it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
47
- it { expect(subject.application_id).to eq('app-id') }
48
- it { expect(subject.application_secret).to eq('app-secret') }
49
- it { expect(subject.access_token).to eq('access-token') }
50
- it { expect(subject).to be_access_token }
51
- describe 'cache' do
52
- it { expect(subject.cache).to be_nil }
53
- it { expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache) }
54
- end
55
- end
56
- describe 'configuration' do
57
- let(:cache_object) { double('Dalli') }
58
- before {
59
- BoletoSimples.configure do |c|
60
- c.environment = :production
61
- c.application_id = 'app-id'
62
- c.application_secret = 'app-secret'
63
- c.access_token = 'access-token'
64
- c.cache = cache_object
65
- end
66
- }
67
- subject { BoletoSimples.configuration }
68
- it { expect(subject.environment).to eq(:production) }
69
- it { expect(subject.user_agent).to eq("BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)") }
70
- it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
71
- it { expect(subject.application_id).to eq('app-id') }
72
- it { expect(subject.application_secret).to eq('app-secret') }
73
- it { expect(subject.access_token).to eq('access-token') }
74
- describe 'cache' do
75
- it { expect(subject.cache).to eq(cache_object) }
76
- it { expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache) }
77
- end
78
- describe 'client credentials' do
79
- context 'invalid credentials', vcr: { cassette_name: 'configuration/client_credentials/invalid'} do
80
- before {
81
- BoletoSimples.configure do |c|
82
- c.application_id = 'app-id'
83
- c.application_secret = 'app-secret'
84
- c.access_token = nil
85
- end
86
- }
87
- it { expect{subject.client_credentials}.to raise_error(BoletoSimples::ResponseError, "401 POST https://sandbox.boletosimples.com.br/api/v1/oauth2/token (invalid_client)") }
88
- end
89
- context 'valid credentials', vcr: { cassette_name: 'configuration/client_credentials/valid'} do
90
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_APP_ID and BOLETOSIMPLES_APP_SECRET
91
- before {
92
- BoletoSimples.configure do |c|
93
- c.access_token = nil
94
- end
95
- }
96
- it { expect(subject.client_credentials).to include(:access_token) }
97
- end
98
- end
99
- end
100
- end
3
+ # require 'spec_helper'
4
+
5
+ # RSpec.describe BoletoSimples::Configuration do
6
+ # describe 'defaults' do
7
+ # subject { described_class.new }
8
+
9
+ # before do
10
+ # stub_env('BOLETOSIMPLES_ENV', nil)
11
+ # stub_env('BOLETOSIMPLES_USER_AGENT', nil)
12
+ # subject.setup_her
13
+ # end
14
+
15
+ # it do
16
+ # expect(subject.environment).to eq(:sandbox)
17
+ # expect(subject.base_uri).to eq('https://sandbox.boletosimples.com.br/api/v1')
18
+ # expect(subject.cache).to be_nil
19
+ # expect(subject.user_agent).to be_nil
20
+ # end
21
+ # end
22
+
23
+ # describe 'environment variables' do
24
+ # subject { BoletoSimples.configuration }
25
+
26
+ # before do
27
+ # stub_env('BOLETOSIMPLES_ENV', 'production')
28
+ # stub_env('BOLETOSIMPLES_USER_AGENT', 'email@minhaempresa.com.br')
29
+ # BoletoSimples.configure
30
+ # end
31
+
32
+ # it do
33
+ # expect(subject.environment).to eq(:production)
34
+ # expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1')
35
+ # expect(subject.user_agent).to eq('email@minhaempresa.com.br')
36
+ # end
37
+
38
+ # describe 'cache' do
39
+ # it do
40
+ # expect(subject.cache).to be_nil
41
+ # expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache)
42
+ # end
43
+ # end
44
+ # end
45
+
46
+ # describe 'configuration' do
47
+ # subject { BoletoSimples.configuration }
48
+
49
+ # let(:cache_object) { double('Dalli') }
50
+
51
+ # before do
52
+ # BoletoSimples.configure do |c|
53
+ # c.environment = :production
54
+ # c.cache = cache_object
55
+ # c.user_agent = 'Meu agent'
56
+ # end
57
+ # end
58
+
59
+ # it do
60
+ # expect(subject.environment).to eq(:production)
61
+ # expect(subject.user_agent).to eq('Meu agent')
62
+ # expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1')
63
+ # end
64
+
65
+ # describe 'cache' do
66
+ # it do
67
+ # expect(subject.cache).to eq(cache_object)
68
+ # expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache)
69
+ # end
70
+ # end
71
+ # end
72
+ # end
@@ -1,34 +1,22 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe BoletoSimples::LastRequest do
5
- before {
6
- BoletoSimples.configure do |c|
7
- c.application_id = nil
8
- c.application_secret = nil
9
- end
10
- }
11
- describe 'bank_billets', vcr: { cassette_name: 'last_request/bank_billets'} do
12
- before { BoletoSimples::BankBillet.all.size }
13
- subject { BoletoSimples.last_request }
14
- it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
15
- it { expect(subject.body).to be_kind_of(Array) }
16
- it { expect(subject.body.first).to be_kind_of(Hash) }
17
- it { expect(subject.response_headers).to be_kind_of(Hash) }
18
- it { expect(subject.total).to be_kind_of(Integer) }
19
- it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
20
- it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
21
- it { expect(subject.links.keys).to match_array([:next, :last]) }
22
- end
23
- describe 'user_info', vcr: { cassette_name: 'last_request/userinfo'} do
24
- before { BoletoSimples::Extra.userinfo }
6
+ describe 'bank_billets', vcr: { cassette_name: 'last_request/bank_billets' } do
25
7
  subject { BoletoSimples.last_request }
26
- it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
27
- it { expect(subject.body).to be_kind_of(Hash) }
28
- it { expect(subject.response_headers).to be_kind_of(Hash) }
29
- it { expect(subject.total).to eq(0) }
30
- it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
31
- it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
32
- it { expect(subject.links).to eq({}) }
8
+
9
+ before { BoletoSimples::BankBillet.all(page: 2).size }
10
+
11
+ it do
12
+ expect(subject).to be_kind_of(described_class)
13
+ expect(subject.body).to be_kind_of(Array)
14
+ expect(subject.body.first).to be_kind_of(Hash)
15
+ expect(subject.response_headers).to be_kind_of(Hash)
16
+ expect(subject.total).to be_kind_of(Integer)
17
+ expect(subject.ratelimit_limit).to be_kind_of(Integer)
18
+ expect(subject.ratelimit_remaining).to be_kind_of(Integer)
19
+ expect(subject.links.keys).to match_array(%i[first next prev])
20
+ end
33
21
  end
34
22
  end