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,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::CustomerSubscriptionImport 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_subscription_import/create/valid') do
16
- @customer_subscription_import = BoletoSimples::CustomerSubscriptionImport.create({
17
- source: Faraday::UploadIO.new(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'customer_subscription_imports.csv'), 'text/csv', 'customer_subscriptions.csv')
18
- })
10
+ @customer_subscription_import = described_class.create({
11
+ source: Faraday::UploadIO.new(
12
+ File.join(File.dirname(__FILE__), '..', '..', 'fixtures',
13
+ 'customer_subscription_imports.csv'), 'text/csv', 'customer_subscriptions.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_subscription_import }
24
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerSubscriptionImport) }
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_subscription_import/create/invalid_root') do
32
- BoletoSimples::CustomerSubscriptionImport.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_subscription_import não pode ficar em branco' }])
34
40
  }
35
- it { expect(subject.response_errors).to eq({:customer_subscription_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_subscription_import/create/invalid_params') do
40
- BoletoSimples::CustomerSubscriptionImport.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_subscription_import/find'} do
48
- subject { BoletoSimples::CustomerSubscriptionImport.find(@customer_subscription_import.id) }
49
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerSubscriptionImport) }
54
+
55
+ describe 'find', vcr: { cassette_name: 'resources/customer_subscription_import/find' } do
56
+ subject { described_class.find(@customer_subscription_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_subscription_import/all'} do
52
- subject { BoletoSimples::CustomerSubscriptionImport.all }
53
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::CustomerSubscriptionImport) }
60
+
61
+ describe 'all', vcr: { cassette_name: 'resources/customer_subscription_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
@@ -1,65 +1,93 @@
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::CustomerSubscription 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_subscription/create/valid') do
16
- @customer_subscription = BoletoSimples::CustomerSubscription.create({
17
- customer_id: "11",
18
- bank_billet_account_id: "12",
19
- amount: "1.120,4",
20
- cycle: "monthly",
21
- description: "Hospedagem"
22
- })
10
+ @customer_subscription = described_class.create(
11
+ amount: 1120.4,
12
+ cycle: 'monthly',
13
+ description: 'Hospedagem',
14
+ customer_address: 'Rua quinhentos',
15
+ customer_address_complement: 'Sala 4',
16
+ customer_address_number: '111',
17
+ customer_city_name: 'Rio de Janeiro',
18
+ customer_cnpj_cpf: '18.033.842/0001-05',
19
+ customer_email: 'cliente@example.com',
20
+ customer_neighborhood: 'Sao Francisco',
21
+ customer_person_name: 'Joao da Silva',
22
+ customer_person_type: 'individual',
23
+ customer_phone_number: '2112123434',
24
+ customer_state: 'RJ',
25
+ customer_zipcode: '12312-123'
26
+ )
23
27
  end
24
- }
28
+ end
29
+
25
30
  describe 'create' do
26
31
  context 'valid parameters' do
27
32
  subject { @customer_subscription }
28
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerSubscription) }
29
- it { expect(subject.response_errors).to eq({}) }
30
- it { expect(subject.attributes.keys).to match_array(["amount", "bank_billet_account_id", "created_at", "created_via_api", "customer_id", "cycle", "days_in_advance", "description", "end_at", "id", "instructions", "next_billing", "updated_at"]) }
33
+
34
+ it do
35
+ expect(subject).to be_a_kind_of(described_class)
36
+ expect(subject.response_errors).to eq({})
37
+ end
31
38
  end
39
+
32
40
  context 'invalid parameters' do
33
41
  context 'empty bank_billet' do
34
- subject {
42
+ subject do
35
43
  VCR.use_cassette('resources/customer_subscription/create/invalid_root') do
36
- BoletoSimples::CustomerSubscription.create({})
44
+ described_class.create({})
37
45
  end
46
+ end
47
+
48
+ it {
49
+ expect(subject.response_errors).to eq([{ code: 422,
50
+ status: 422,
51
+ title: 'customer_subscription não pode ficar em branco' }])
38
52
  }
39
- it { expect(subject.response_errors).to eq({ :customer_subscription => ["não pode ficar em branco"] }) }
40
53
  end
54
+
41
55
  context 'invalid params' do
42
- subject {
56
+ subject do
43
57
  VCR.use_cassette('resources/customer_subscription/create/invalid_params') do
44
- BoletoSimples::CustomerSubscription.create({ customer_id: '' })
58
+ described_class.create({ customer_id: '' })
45
59
  end
60
+ end
61
+
62
+ it {
63
+ expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
64
+ customer_cnpj_cpf: ['não pode ficar em branco'],
65
+ customer_zipcode: ['não pode ficar em branco'],
66
+ amount: ['não pode ficar em branco'],
67
+ customer_address: ['não pode ficar em branco'],
68
+ customer_neighborhood: ['não pode ficar em branco'],
69
+ customer_city_name: ['não pode ficar em branco'],
70
+ customer_state: ['não está incluído na lista'] })
46
71
  }
47
- it { expect(subject.response_errors).to eq({ :customer=>["não pode ficar em branco"], :bank_billet_account=>["não pode ficar em branco"], :amount=>["não pode ficar em branco"], :description=>["não pode ficar em branco"] }) }
48
72
  end
49
73
  end
50
74
  end
75
+
51
76
  describe 'find', vcr: { cassette_name: 'resources/customer_subscription/find' } do
52
- subject { BoletoSimples::CustomerSubscription.find(@customer_subscription.id) }
53
- it { expect(subject).to be_a_kind_of(BoletoSimples::CustomerSubscription) }
77
+ subject { described_class.find(@customer_subscription.id) }
78
+
79
+ it { expect(subject).to be_a_kind_of(described_class) }
54
80
  end
81
+
55
82
  describe 'all', vcr: { cassette_name: 'resources/customer_subscription/all' } do
56
- subject { BoletoSimples::CustomerSubscription.all }
57
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::CustomerSubscription) }
83
+ subject { described_class.all }
84
+
85
+ it { expect(subject.first).to be_a_kind_of(described_class) }
58
86
  end
87
+
59
88
  describe 'cancel' do
60
- context 'success', vcr: { cassette_name: 'resources/customer_subscription/next_charge'} do
61
- subject { BoletoSimples::CustomerSubscription.find(@customer_subscription.id) }
62
- it { expect(subject.next_charge).to be_truthy }
89
+ context 'success', vcr: { cassette_name: 'resources/customer_subscription/next_charge' } do
90
+ it { expect(described_class.next_charge(id: @customer_subscription.id)).to be_truthy }
63
91
  end
64
92
  end
65
93
  end
@@ -1,17 +1,70 @@
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::Discharge do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
7
+ describe 'methods' do
8
+ before do
9
+ VCR.use_cassette('resources/discharge/create/valid') do
10
+ @discharge = described_class.create({
11
+ file: Faraday::UploadIO.new(
12
+ File.join(File.dirname(__FILE__), '..', '..',
13
+ 'fixtures', 'discharge.RET'), 'text/plain', 'discharge.RET'
14
+ )
15
+ })
16
+ end
17
+ end
18
+
19
+ describe 'create' do
20
+ context 'valid parameters' do
21
+ subject { @discharge }
22
+
23
+ it do
24
+ expect(subject).to be_a_kind_of(described_class)
25
+ expect(subject.response_errors).to eq({})
26
+ end
27
+ end
28
+
29
+ context 'invalid parameters' do
30
+ context 'empty bank_billet' do
31
+ subject do
32
+ VCR.use_cassette('resources/discharge/create/invalid_root') do
33
+ described_class.create({})
34
+ end
35
+ end
36
+
37
+ it {
38
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
39
+ title: 'discharge não pode ficar em branco' }])
40
+ }
41
+ end
42
+
43
+ context 'invalid params' do
44
+ subject do
45
+ VCR.use_cassette('resources/discharge/create/invalid_params') do
46
+ described_class.create({ content: '' })
47
+ end
48
+ end
49
+
50
+ it {
51
+ expect(subject.response_errors).to eq({ content: ['não pode ficar em branco'],
52
+ filename: ['não pode ficar em branco'] })
53
+ }
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'find', vcr: { cassette_name: 'resources/discharge/find' } do
59
+ subject { described_class.find(@discharge.id) }
60
+
61
+ it { expect(subject).to be_a_kind_of(described_class) }
62
+ end
63
+
64
+ describe 'all', vcr: { cassette_name: 'resources/discharge/all' } do
65
+ subject { described_class.all }
66
+
67
+ it { expect(subject.first).to be_a_kind_of(described_class) }
11
68
  end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/discharge/all'} do
14
- subject { BoletoSimples::Discharge.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::Discharge) }
16
69
  end
17
- end
70
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
+ RSpec.describe BoletoSimples::EmailDelivery do
7
+ describe 'all', vcr: { cassette_name: 'resources/email_delivery/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_nil }
11
+ 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::Event 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/event/all'} do
14
- subject { BoletoSimples::Event.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::Event) }
7
+ describe 'all', vcr: { cassette_name: 'resources/event/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,62 +1,91 @@
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::Installment 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/installment/create/valid') do
16
- @installment = BoletoSimples::Installment.create({
17
- customer_id: "11",
18
- bank_billet_account_id: "12",
19
- amount: "1.120,4",
20
- cycle: "monthly",
21
- start_at: "2016-09-15",
22
- total: "3",
23
- description: "Hospedagem"
24
- })
10
+ @installment = described_class.create(
11
+ amount: '1.120,4',
12
+ cycle: 'monthly',
13
+ start_at: '2022-09-15',
14
+ total: '3',
15
+ description: 'Hospedagem',
16
+ customer_address: 'Rua quinhentos',
17
+ customer_address_complement: 'Sala 4',
18
+ customer_address_number: '111',
19
+ customer_city_name: 'Rio de Janeiro',
20
+ customer_cnpj_cpf: '18.033.842/0001-05',
21
+ customer_email: 'cliente@example.com',
22
+ customer_neighborhood: 'Sao Francisco',
23
+ customer_person_name: 'Joao da Silva',
24
+ customer_person_type: 'individual',
25
+ customer_phone_number: '2112123434',
26
+ customer_state: 'RJ',
27
+ customer_zipcode: '12312-123'
28
+ )
25
29
  end
26
- }
30
+ end
31
+
27
32
  describe 'create' do
28
33
  context 'valid parameters' do
29
34
  subject { @installment }
30
- it { expect(subject).to be_a_kind_of(BoletoSimples::Installment) }
31
- it { expect(subject.response_errors).to eq({}) }
32
- it { expect(subject.attributes.keys).to match_array(["amount", "bank_billet_account_id", "created_at", "created_via_api", "customer_id", "cycle", "description", "end_at", "id", "instructions", "start_at", "status", "total", "updated_at"]) }
35
+
36
+ it do
37
+ expect(subject).to be_a_kind_of(described_class)
38
+ expect(subject.response_errors).to eq({})
39
+ end
33
40
  end
41
+
34
42
  context 'invalid parameters' do
35
43
  context 'empty bank_billet' do
36
- subject {
44
+ subject do
37
45
  VCR.use_cassette('resources/installment/create/invalid_root') do
38
- BoletoSimples::Installment.create({})
46
+ described_class.create({})
39
47
  end
48
+ end
49
+
50
+ it {
51
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
52
+ title: 'installment não pode ficar em branco' }])
40
53
  }
41
- it { expect(subject.response_errors).to eq({ :installment => ["não pode ficar em branco"] }) }
42
54
  end
55
+
43
56
  context 'invalid params' do
44
- subject {
57
+ subject do
45
58
  VCR.use_cassette('resources/installment/create/invalid_params') do
46
- BoletoSimples::Installment.create({ person_name: '' })
59
+ described_class.create({ person_name: '' })
47
60
  end
61
+ end
62
+
63
+ it {
64
+ expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
65
+ customer_cnpj_cpf: ['não pode ficar em branco'],
66
+ customer_zipcode: ['não pode ficar em branco'],
67
+ total: ['não pode ficar em branco', 'não é um número'],
68
+ start_at: ['não pode ficar em branco'],
69
+ amount: ['não pode ficar em branco'],
70
+ customer_address: ['não pode ficar em branco'],
71
+ customer_neighborhood: ['não pode ficar em branco'],
72
+ customer_city_name: ['não pode ficar em branco'],
73
+ customer_state: ['não está incluído na lista'] })
48
74
  }
49
- it { expect(subject.response_errors).to eq({ :customer=>["não pode ficar em branco"], :bank_billet_account=>["não pode ficar em branco"], :cycle=>["não pode ficar em branco", "não está incluído na lista"], :total=>["não pode ficar em branco"], :start_at=>["não pode ficar em branco"], :description=>["não pode ficar em branco"], :amount=>["deve ser maior que 0"] }) }
50
75
  end
51
76
  end
52
77
  end
78
+
53
79
  describe 'find', vcr: { cassette_name: 'resources/installment/find' } do
54
- subject { BoletoSimples::Installment.find(@installment.id) }
55
- it { expect(subject).to be_a_kind_of(BoletoSimples::Installment) }
80
+ subject { described_class.find(@installment.id) }
81
+
82
+ it { expect(subject).to be_a_kind_of(described_class) }
56
83
  end
84
+
57
85
  describe 'all', vcr: { cassette_name: 'resources/installment/all' } do
58
- subject { BoletoSimples::Installment.all }
59
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::Installment) }
86
+ subject { described_class.all }
87
+
88
+ it { expect(subject.first).to be_a_kind_of(described_class) }
60
89
  end
61
90
  end
62
91
  end