boletosimples 0.6.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +34 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +9 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +6 -20
  7. data/Gemfile +2 -0
  8. data/README.md +12 -54
  9. data/Rakefile +3 -1
  10. data/boletosimples.gemspec +14 -11
  11. data/lib/boletosimples.rb +4 -6
  12. data/lib/boletosimples/configuration.rb +14 -25
  13. data/lib/boletosimples/last_request.rb +12 -9
  14. data/lib/boletosimples/middlewares/bearer.rb +12 -0
  15. data/lib/boletosimples/middlewares/last_request.rb +3 -1
  16. data/lib/boletosimples/middlewares/raise_error.rb +9 -2
  17. data/lib/boletosimples/middlewares/user_agent.rb +3 -1
  18. data/lib/boletosimples/resources/bank_billet.rb +5 -11
  19. data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
  20. data/lib/boletosimples/resources/bank_billet_discharge.rb +3 -1
  21. data/lib/boletosimples/resources/bank_billet_payment.rb +3 -1
  22. data/lib/boletosimples/resources/bank_billet_remittance.rb +3 -1
  23. data/lib/boletosimples/resources/base_model.rb +3 -1
  24. data/lib/boletosimples/resources/customer.rb +3 -1
  25. data/lib/boletosimples/resources/customer_import.rb +5 -3
  26. data/lib/boletosimples/resources/customer_subscription.rb +3 -10
  27. data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
  28. data/lib/boletosimples/resources/discharge.rb +4 -11
  29. data/lib/boletosimples/resources/email_delivery.rb +3 -1
  30. data/lib/boletosimples/resources/event.rb +3 -1
  31. data/lib/boletosimples/resources/installment.rb +3 -1
  32. data/lib/boletosimples/resources/remittance.rb +3 -1
  33. data/lib/boletosimples/resources/sms_delivery.rb +6 -0
  34. data/lib/boletosimples/resources/transaction.rb +3 -1
  35. data/lib/boletosimples/resources/webhook.rb +3 -1
  36. data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
  37. data/lib/boletosimples/response_error.rb +8 -3
  38. data/lib/boletosimples/version.rb +3 -1
  39. data/spec/boletosimples/configuration_spec.rb +71 -101
  40. data/spec/boletosimples/last_request_spec.rb +16 -28
  41. data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
  42. data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +7 -12
  43. data/spec/boletosimples/resources/bank_billet_payment_spec.rb +7 -12
  44. data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +7 -12
  45. data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
  46. data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
  47. data/spec/boletosimples/resources/customer_spec.rb +52 -39
  48. data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
  49. data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
  50. data/spec/boletosimples/resources/discharge_spec.rb +64 -11
  51. data/spec/boletosimples/resources/email_delivery_spec.rb +6 -11
  52. data/spec/boletosimples/resources/event_spec.rb +7 -12
  53. data/spec/boletosimples/resources/installment_spec.rb +61 -32
  54. data/spec/boletosimples/resources/remittance_spec.rb +7 -12
  55. data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
  56. data/spec/boletosimples/resources/transactions_spec.rb +7 -12
  57. data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
  58. data/spec/boletosimples/resources/webhook_spec.rb +7 -12
  59. data/spec/fixtures/discharge.RET +3 -0
  60. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +536 -88
  61. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +537 -91
  62. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +34 -92
  63. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -20
  64. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +28 -17
  65. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +43 -27
  66. data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +83 -0
  67. data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +51 -27
  68. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +131 -20
  69. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +34 -20
  70. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +30 -19
  71. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +41 -21
  72. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +38 -18
  73. data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +66 -47
  74. data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +44 -42
  75. data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +95 -48
  76. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +79 -32
  77. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +30 -17
  78. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +28 -17
  79. data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +33 -21
  80. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +33 -19
  81. data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +43 -60
  82. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +37 -51
  83. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +38 -52
  84. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +43 -68
  85. data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +40 -54
  86. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +102 -52
  87. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +40 -50
  88. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +36 -48
  89. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +48 -53
  90. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +44 -50
  91. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +45 -133
  92. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +44 -55
  93. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +37 -52
  94. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +39 -53
  95. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +43 -70
  96. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +40 -55
  97. data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +64 -33
  98. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +70 -0
  99. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +69 -0
  100. data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +84 -0
  101. data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +71 -0
  102. data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +40 -43
  103. data/spec/fixtures/vcr_cassettes/resources/event/all.yml +490 -166
  104. data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +418 -52
  105. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +41 -52
  106. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +36 -48
  107. data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +48 -53
  108. data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +44 -52
  109. data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +53 -33
  110. data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +73 -0
  111. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +34 -22
  112. data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +42 -33
  113. data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +1232 -54
  114. data/spec/spec_helper.rb +3 -20
  115. data/spec/support/stub_env.rb +7 -0
  116. data/spec/support/vcr.rb +3 -4
  117. metadata +87 -52
  118. data/.coveralls.yml +0 -2
  119. data/.travis.yml +0 -46
  120. data/gemfiles/rails_42.gemfile +0 -8
  121. data/gemfiles/rails_50.gemfile +0 -8
  122. data/gemfiles/rails_51.gemfile +0 -8
  123. data/gemfiles/rails_52.gemfile +0 -9
  124. data/lib/boletosimples/extra.rb +0 -8
  125. data/lib/boletosimples/resources/partner/user.rb +0 -7
  126. data/lib/oauth2_patch.rb +0 -24
  127. data/spec/boletosimples/extra_spec.rb +0 -31
  128. data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
  129. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
  130. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
  131. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
  132. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
  133. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
  134. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
  135. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
  136. data/spec/spec.opts +0 -8
@@ -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
@@ -1,62 +1,86 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletAccount do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
7
  describe 'methods' do
14
- before {
8
+ before do
15
9
  VCR.use_cassette('resources/bank_billet_account/create/valid') do
16
- @bank_billet_account = BoletoSimples::BankBilletAccount.create({
17
- bank_contract_slug: 'sicoob-02',
18
- next_our_number: '1',
19
- agency_number: '4327',
20
- agency_digit: '3',
21
- account_number: '3666',
22
- account_digit: '8',
23
- extra1_length: '1234567'
24
- })
10
+ @bank_billet_account = described_class.create(
11
+ bank_contract_slug: 'sicoob-02',
12
+ next_our_number: '1',
13
+ agency_number: '4327',
14
+ agency_digit: '3',
15
+ account_number: '3666',
16
+ account_digit: '8',
17
+ extra1: '1234567',
18
+ beneficiary_name: 'XPTO S.A.',
19
+ beneficiary_cnpj_cpf: '22.622.867/0001-11',
20
+ beneficiary_address_street: 'Rua S',
21
+ beneficiary_address_city: 'São Paulo',
22
+ beneficiary_address_state: 'SP',
23
+ beneficiary_address_neighborhood: 'Moema',
24
+ beneficiary_address_zipcode: '04524030'
25
+ )
25
26
  end
26
- }
27
+ end
28
+
27
29
  describe 'create' do
28
30
  context 'valid parameters' do
29
31
  subject { @bank_billet_account }
30
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
31
- it { expect(subject.response_errors).to eq({}) }
32
- it { expect(subject.attributes.keys).to match_array(["account_digit", "account_number", "agency_digit", "agency_number", "bank_contract_slug", "extra1", "extra1_digit", "extra1_length", "extra2", "extra2_digit", "id", "next_our_number"]) }
32
+
33
+ it do
34
+ expect(subject).to be_a_kind_of(described_class)
35
+ expect(subject.response_errors).to eq({})
36
+ end
33
37
  end
38
+
34
39
  context 'invalid parameters' do
35
40
  context 'empty bank_billet' do
36
- subject {
41
+ subject do
37
42
  VCR.use_cassette('resources/bank_billet_account/create/invalid_root') do
38
- BoletoSimples::BankBilletAccount.create({})
43
+ described_class.create({})
39
44
  end
45
+ end
46
+
47
+ it {
48
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
49
+ title: 'bank_billet_account não pode ficar em branco' }])
40
50
  }
41
- it { expect(subject.response_errors).to eq({ bank_billet_account: ["não pode ficar em branco"] }) }
42
51
  end
52
+
43
53
  context 'invalid params' do
44
- subject {
54
+ subject do
45
55
  VCR.use_cassette('resources/bank_billet_account/create/invalid_params') do
46
- BoletoSimples::BankBilletAccount.create({ bank_contract_slug: '' })
56
+ described_class.create({ bank_contract_slug: '' })
47
57
  end
58
+ end
59
+
60
+ it {
61
+ expect(subject.response_errors).to eq({ bank_contract_slug: ['não pode ficar em branco'],
62
+ beneficiary_name: ['não pode ficar em branco'],
63
+ beneficiary_cnpj_cpf: ['não pode ficar em branco'],
64
+ beneficiary_address_street: ['não pode ficar em branco'],
65
+ beneficiary_address_city: ['não pode ficar em branco'],
66
+ beneficiary_address_neighborhood: ['não pode ficar em branco'],
67
+ beneficiary_address_state: ['não pode ficar em branco'],
68
+ beneficiary_address_zipcode: ['não pode ficar em branco'] })
48
69
  }
49
- it { expect(subject.response_errors).to eq({ :agency_number => ["não pode ficar em branco"], :account_number => ["não pode ficar em branco"], :bank_contract_slug => ["não pode ficar em branco"] }) }
50
70
  end
51
71
  end
52
72
  end
73
+
53
74
  describe 'find', vcr: { cassette_name: 'resources/bank_billet_account/find' } do
54
- subject { BoletoSimples::BankBilletAccount.find(@bank_billet_account.id) }
55
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
75
+ subject { described_class.find(@bank_billet_account.id) }
76
+
77
+ it { expect(subject).to be_a_kind_of(described_class) }
56
78
  end
79
+
57
80
  describe 'all', vcr: { cassette_name: 'resources/bank_billet_account/all' } do
58
- subject { BoletoSimples::BankBilletAccount.all }
59
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
81
+ subject { described_class.all }
82
+
83
+ it { expect(subject.first).to be_a_kind_of(described_class) }
60
84
  end
61
85
  end
62
- end
86
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletDischarge do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_discharge/all'} do
14
- subject { BoletoSimples::BankBilletDischarge.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletDischarge) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_discharge/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletPayment do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_payment/all'} do
14
- subject { BoletoSimples::BankBilletPayment.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletPayment) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_payment/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletRemittance do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_remittance/all'} do
14
- subject { BoletoSimples::BankBilletRemittance.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletRemittance) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_remittance/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end
@@ -1,85 +1,99 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBillet do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
7
  describe 'methods' do
14
- before {
8
+ before do
15
9
  VCR.use_cassette('resources/bank_billet/create/valid') do
16
- @bank_billet = BoletoSimples::BankBillet.create({
10
+ @bank_billet = described_class.create(
17
11
  amount: 9.01,
18
12
  description: 'Despesas do contrato 0012',
19
- expire_at: '2014-01-01',
13
+ expire_at: '2022-01-01',
20
14
  customer_address: 'Rua quinhentos',
21
15
  customer_address_complement: 'Sala 4',
22
16
  customer_address_number: '111',
23
17
  customer_city_name: 'Rio de Janeiro',
24
- customer_cnpj_cpf: '012.345.678-90',
18
+ customer_cnpj_cpf: '34.565.715/0001-03',
25
19
  customer_email: 'cliente@example.com',
26
20
  customer_neighborhood: 'Sao Francisco',
27
21
  customer_person_name: 'Joao da Silva',
28
22
  customer_person_type: 'individual',
29
23
  customer_phone_number: '2112123434',
30
24
  customer_state: 'RJ',
31
- customer_zipcode: '12312-123',
32
- notification_url: 'http://example.com.br/notify'
33
- })
25
+ customer_zipcode: '12312-123'
26
+ )
34
27
  end
35
- }
28
+ end
29
+
36
30
  describe 'create' do
37
31
  context 'valid parameters' do
38
32
  subject { @bank_billet }
39
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBillet) }
40
- it { expect(subject.response_errors).to eq({}) }
41
- it { expect(subject.attributes.keys).to match_array(["amount","description","expire_at","customer_address","customer_address_complement","customer_address_number","customer_city_name","customer_cnpj_cpf","customer_email","customer_neighborhood","customer_person_name","customer_person_type","customer_phone_number","customer_state","customer_zipcode","notification_url","id","paid_at","status","shorten_url","send_email_on_creation","created_via_api","paid_amount"]) }
33
+
34
+ it do
35
+ expect(subject).to be_a_kind_of(described_class)
36
+ expect(subject.response_errors).to eq({})
37
+ end
42
38
  end
39
+
43
40
  context 'invalid parameters' do
44
41
  context 'empty bank_billet' do
45
- subject {
42
+ subject do
46
43
  VCR.use_cassette('resources/bank_billet/create/invalid_root') do
47
- BoletoSimples::BankBillet.create({})
44
+ described_class.create({})
48
45
  end
46
+ end
47
+
48
+ it {
49
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
50
+ title: 'bank_billet não pode ficar em branco' }])
49
51
  }
50
- it { expect(subject.response_errors).to eq({:bank_billet=>["não pode ficar em branco"]}) }
51
52
  end
53
+
52
54
  context 'invalid params' do
53
- subject {
55
+ subject do
54
56
  VCR.use_cassette('resources/bank_billet/create/invalid_params') do
55
- BoletoSimples::BankBillet.create({amount: 9.1})
57
+ described_class.create({ amount: 9.1 })
56
58
  end
59
+ end
60
+
61
+ it {
62
+ expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
63
+ customer_cnpj_cpf: ['não pode ficar em branco'],
64
+ customer_zipcode: ['não pode ficar em branco'],
65
+ expire_at: ['não pode ficar em branco', 'não é uma data válida'],
66
+ customer_address: ['não pode ficar em branco'],
67
+ customer_neighborhood: ['não pode ficar em branco'],
68
+ customer_city_name: ['não pode ficar em branco'],
69
+ customer_state: ['não está incluído na lista'] })
57
70
  }
58
- it { expect(subject.response_errors).to eq({:expire_at=>["não pode ficar em branco", "não é uma data válida"], :customer_person_name=>["não pode ficar em branco"], :customer_cnpj_cpf=>["não pode ficar em branco"], :description=>["não pode ficar em branco"], :customer_zipcode=>["não pode ficar em branco"]}) }
59
71
  end
60
72
  end
61
73
  end
62
- describe 'find', vcr: { cassette_name: 'resources/bank_billet/find'} do
63
- subject { BoletoSimples::BankBillet.find(@bank_billet.id) }
64
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBillet) }
74
+
75
+ describe 'find', vcr: { cassette_name: 'resources/bank_billet/find' } do
76
+ subject { described_class.find(@bank_billet.id) }
77
+
78
+ it { expect(subject).to be_a_kind_of(described_class) }
65
79
  end
80
+
66
81
  describe 'cancel' do
67
- context 'success', vcr: { cassette_name: 'resources/bank_billet/cancel/success'} do
68
- subject { BoletoSimples::BankBillet.find(@bank_billet.id) }
69
- it { expect(subject.cancel).to be_truthy }
82
+ context 'success', vcr: { cassette_name: 'resources/bank_billet/cancel/success' } do
83
+ it { expect(described_class.cancel(id: @bank_billet.id)).to be_truthy }
70
84
  end
71
- context 'failure', vcr: { cassette_name: 'resources/bank_billet/cancel/failure'} do
72
- subject { BoletoSimples::BankBillet.find(863) }
73
- it { expect(subject.cancel).to be_falsy }
74
- context 'after cancel' do
75
- before { subject.cancel }
76
- it { expect(subject.response_errors).to eq({:status=>["cannot transition via cancel"]}) }
77
- end
85
+ end
86
+
87
+ describe 'duplicate' do
88
+ context 'success', vcr: { cassette_name: 'resources/bank_billet/duplicate/success' } do
89
+ it { expect(described_class.duplicate(id: @bank_billet.id)).to be_truthy }
78
90
  end
79
91
  end
80
- describe 'all', vcr: { cassette_name: 'resources/bank_billet/all'} do
81
- subject { BoletoSimples::BankBillet.all }
82
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBillet) }
92
+
93
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet/all' } do
94
+ subject { described_class.all }
95
+
96
+ it { expect(subject.first).to be_a_kind_of(described_class) }
83
97
  end
84
98
  end
85
- end
99
+ end
@@ -1,56 +1,67 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::CustomerImport do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
7
  describe 'methods' do
14
- before {
8
+ before do
15
9
  VCR.use_cassette('resources/customer_import/create/valid') do
16
- @customer_import = BoletoSimples::CustomerImport.create({
17
- source: Faraday::UploadIO.new(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'customer_imports.csv'), 'text/csv', 'customers.csv')
18
- })
10
+ @customer_import = described_class.create({
11
+ source: Faraday::UploadIO.new(
12
+ File.join(File.dirname(__FILE__), '..', '..',
13
+ 'fixtures', 'customer_imports.csv'), 'text/csv', 'customers.csv'
14
+ )
15
+ })
19
16
  end
20
- }
17
+ end
18
+
21
19
  describe 'create' do
22
20
  context 'valid parameters' do
23
21
  subject { @customer_import }
24
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerImport) }
25
- it { expect(subject.response_errors).to eq({}) }
26
- it { expect(subject.attributes.keys).to match_array(["created_rows", "enqueued_at", "failed_to_create_rows", "failed_to_update_rows", "finished_at", "id", "import_errors", "processed_at", "processed_rows", "records_count", "source", "source_content_type", "source_file_name", "source_file_size", "source_updated_at", "started_at", "status", "total_rows", "updated_rows"]) }
22
+
23
+ it do
24
+ expect(subject).to be_a_kind_of(described_class)
25
+ expect(subject.response_errors).to eq({})
26
+ end
27
27
  end
28
+
28
29
  context 'invalid parameters' do
29
30
  context 'empty bank_billet' do
30
- subject {
31
+ subject do
31
32
  VCR.use_cassette('resources/customer_import/create/invalid_root') do
32
- BoletoSimples::CustomerImport.create({})
33
+ described_class.create({})
33
34
  end
35
+ end
36
+
37
+ it {
38
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
39
+ title: 'customer_import não pode ficar em branco' }])
34
40
  }
35
- it { expect(subject.response_errors).to eq({:customer_import=>["não pode ficar em branco"]}) }
36
41
  end
42
+
37
43
  context 'invalid params' do
38
- subject {
44
+ subject do
39
45
  VCR.use_cassette('resources/customer_import/create/invalid_params') do
40
- BoletoSimples::CustomerImport.create({source: ''})
46
+ described_class.create({ source: '' })
41
47
  end
42
- }
43
- it { expect(subject.response_errors).to eq(source: ["não pode ficar em branco"]) }
48
+ end
49
+
50
+ it { expect(subject.response_errors).to eq(source: ['não pode ficar em branco']) }
44
51
  end
45
52
  end
46
53
  end
47
- describe 'find', vcr: { cassette_name: 'resources/customer_import/find'} do
48
- subject { BoletoSimples::CustomerImport.find(@customer_import.id) }
49
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerImport) }
54
+
55
+ describe 'find', vcr: { cassette_name: 'resources/customer_import/find' } do
56
+ subject { described_class.find(@customer_import.id) }
57
+
58
+ it { expect(subject).to be_a_kind_of(described_class) }
50
59
  end
51
- describe 'all', vcr: { cassette_name: 'resources/customer_import/all'} do
52
- subject { BoletoSimples::CustomerImport.all }
53
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::CustomerImport) }
60
+
61
+ describe 'all', vcr: { cassette_name: 'resources/customer_import/all' } do
62
+ subject { described_class.all }
63
+
64
+ it { expect(subject.first).to be_a_kind_of(described_class) }
54
65
  end
55
66
  end
56
- end
67
+ end