boletosimples 0.6.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -12
- data/README.md +21 -59
- data/lib/boletosimples/configuration.rb +25 -28
- data/lib/boletosimples/last_request.rb +17 -10
- data/lib/boletosimples/middlewares/bearer.rb +12 -0
- data/lib/boletosimples/middlewares/custom_headers.rb +12 -0
- data/lib/boletosimples/middlewares/debug.rb +30 -0
- data/lib/boletosimples/middlewares/last_request.rb +3 -1
- data/lib/boletosimples/middlewares/raise_error.rb +9 -2
- data/lib/boletosimples/middlewares/user_agent.rb +3 -1
- data/lib/boletosimples/resources/bank_billet.rb +5 -11
- data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
- data/lib/boletosimples/resources/bank_billet_discharge.rb +3 -1
- data/lib/boletosimples/resources/bank_billet_payment.rb +3 -1
- data/lib/boletosimples/resources/bank_billet_remittance.rb +3 -1
- data/lib/boletosimples/resources/base_model.rb +3 -1
- data/lib/boletosimples/resources/customer.rb +3 -1
- data/lib/boletosimples/resources/customer_import.rb +5 -3
- data/lib/boletosimples/resources/customer_subscription.rb +3 -10
- data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
- data/lib/boletosimples/resources/discharge.rb +4 -11
- data/lib/boletosimples/resources/email_delivery.rb +3 -1
- data/lib/boletosimples/resources/event.rb +3 -1
- data/lib/boletosimples/resources/installment.rb +3 -1
- data/lib/boletosimples/resources/remittance.rb +3 -1
- data/lib/boletosimples/resources/sms_delivery.rb +6 -0
- data/lib/boletosimples/resources/transaction.rb +3 -1
- data/lib/boletosimples/resources/webhook.rb +3 -1
- data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
- data/lib/boletosimples/response_error.rb +10 -5
- data/lib/boletosimples/version.rb +3 -1
- data/lib/boletosimples.rb +6 -6
- data/spec/boletosimples/configuration_spec.rb +67 -80
- data/spec/boletosimples/last_request_spec.rb +17 -28
- data/spec/boletosimples/middlewares/custom_headers_spec.rb +26 -0
- data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
- data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_payment_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
- data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
- data/spec/boletosimples/resources/customer_spec.rb +57 -39
- data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
- data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
- data/spec/boletosimples/resources/discharge_spec.rb +64 -11
- data/spec/boletosimples/resources/email_delivery_spec.rb +6 -11
- data/spec/boletosimples/resources/event_spec.rb +7 -12
- data/spec/boletosimples/resources/installment_spec.rb +61 -32
- data/spec/boletosimples/resources/remittance_spec.rb +7 -12
- data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
- data/spec/boletosimples/resources/transactions_spec.rb +7 -12
- data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
- data/spec/boletosimples/resources/webhook_spec.rb +7 -12
- data/spec/fixtures/discharge.RET +3 -0
- data/spec/fixtures/vcr_cassettes/custom_headers.yml +113 -0
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +409 -95
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +101 -99
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +55 -95
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +55 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +51 -24
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +64 -34
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +97 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +73 -34
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +82 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +57 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +53 -26
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +64 -28
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +61 -25
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +59 -46
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +74 -71
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +63 -47
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +141 -39
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +54 -25
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +54 -24
- data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +56 -28
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +56 -26
- data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +58 -59
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +53 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +54 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +58 -67
- data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +55 -53
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +65 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +56 -50
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +52 -48
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +63 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +61 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +60 -132
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +58 -54
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +53 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +55 -53
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +58 -69
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +55 -54
- data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +63 -34
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +86 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +85 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +100 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +89 -0
- data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +40 -43
- data/spec/fixtures/vcr_cassettes/resources/event/all.yml +326 -167
- data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +113 -51
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +57 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +52 -48
- data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +63 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +83 -51
- data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +83 -62
- data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +89 -0
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +73 -60
- data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +59 -34
- data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +2684 -55
- data/spec/spec_helper.rb +3 -20
- data/spec/support/stub_env.rb +7 -0
- data/spec/support/vcr.rb +3 -4
- metadata +42 -176
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -19
- data/.ruby-version +0 -1
- data/.travis.yml +0 -46
- data/Gemfile +0 -4
- data/Rakefile +0 -14
- data/boletosimples.gemspec +0 -38
- data/gemfiles/rails_42.gemfile +0 -8
- data/gemfiles/rails_50.gemfile +0 -8
- data/gemfiles/rails_51.gemfile +0 -8
- data/gemfiles/rails_52.gemfile +0 -9
- data/lib/boletosimples/extra.rb +0 -8
- data/lib/boletosimples/resources/partner/user.rb +0 -7
- data/lib/oauth2_patch.rb +0 -24
- data/spec/boletosimples/extra_spec.rb +0 -31
- data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
- data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
- data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
- data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
- data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
- data/spec/spec.opts +0 -8
@@ -1,85 +1,99 @@
|
|
1
|
-
#
|
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
|
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 =
|
10
|
+
@bank_billet = described_class.create(
|
17
11
|
amount: 9.01,
|
18
12
|
description: 'Despesas do contrato 0012',
|
19
|
-
expire_at: '
|
13
|
+
expire_at: '2024-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: '
|
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
|
-
|
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
|
-
|
40
|
-
it
|
41
|
-
|
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
|
-
|
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
|
-
|
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 é um CNPJ ou CPF válido'],
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
#
|
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
|
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 =
|
17
|
-
|
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
|
-
|
25
|
-
it
|
26
|
-
|
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
|
-
|
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
|
-
|
46
|
+
described_class.create({ source: '' })
|
41
47
|
end
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
@@ -1,66 +1,84 @@
|
|
1
|
-
#
|
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
|
5
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
|
6
6
|
RSpec.describe BoletoSimples::Customer 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/create/valid') do
|
16
|
-
@customer =
|
17
|
-
person_name:
|
18
|
-
cnpj_cpf:
|
19
|
-
email:
|
20
|
-
address:
|
21
|
-
city_name:
|
22
|
-
state:
|
23
|
-
neighborhood:
|
24
|
-
zipcode:
|
25
|
-
address_number:
|
26
|
-
address_complement:
|
27
|
-
phone_number:
|
28
|
-
|
10
|
+
@customer = described_class.create(
|
11
|
+
person_name: 'Maria José',
|
12
|
+
cnpj_cpf: '84.232.027/0001-08',
|
13
|
+
email: 'cliente@example.com',
|
14
|
+
address: 'Rua quinhentos',
|
15
|
+
city_name: 'Rio de Janeiro',
|
16
|
+
state: 'RJ',
|
17
|
+
neighborhood: 'bairro',
|
18
|
+
zipcode: '12312-123',
|
19
|
+
address_number: '111',
|
20
|
+
address_complement: 'Sala 4',
|
21
|
+
phone_number: '2112123434'
|
22
|
+
)
|
29
23
|
end
|
30
|
-
|
24
|
+
end
|
25
|
+
|
31
26
|
describe 'create' do
|
32
27
|
context 'valid parameters' do
|
33
28
|
subject { @customer }
|
34
|
-
|
35
|
-
it
|
36
|
-
|
29
|
+
|
30
|
+
it do
|
31
|
+
expect(subject).to be_a_kind_of(described_class)
|
32
|
+
expect(subject.response_errors).to eq({})
|
33
|
+
end
|
37
34
|
end
|
35
|
+
|
38
36
|
context 'invalid parameters' do
|
39
37
|
context 'empty bank_billet' do
|
40
|
-
subject
|
38
|
+
subject do
|
41
39
|
VCR.use_cassette('resources/customer/create/invalid_root') do
|
42
|
-
|
40
|
+
described_class.create({})
|
43
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it {
|
45
|
+
expect(subject.response_errors).to eq({ address: ['não pode ficar em branco'],
|
46
|
+
city_name: ['não pode ficar em branco'],
|
47
|
+
cnpj_cpf: ['não é um CNPJ ou CPF válido'],
|
48
|
+
neighborhood: ['não pode ficar em branco'],
|
49
|
+
person_name: ['não pode ficar em branco'],
|
50
|
+
state: ['não está incluído na lista'],
|
51
|
+
zipcode: ['não pode ficar em branco'] })
|
44
52
|
}
|
45
|
-
it { expect(subject.response_errors).to eq({:customer=>["não pode ficar em branco"]}) }
|
46
53
|
end
|
54
|
+
|
47
55
|
context 'invalid params' do
|
48
|
-
subject
|
56
|
+
subject do
|
49
57
|
VCR.use_cassette('resources/customer/create/invalid_params') do
|
50
|
-
|
58
|
+
described_class.create({ person_name: '' })
|
51
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it {
|
63
|
+
expect(subject.response_errors).to eq({ person_name: ['não pode ficar em branco'],
|
64
|
+
cnpj_cpf: ['não é um CNPJ ou CPF válido'], zipcode: ['não pode ficar em branco'],
|
65
|
+
address: ['não pode ficar em branco'], neighborhood: ['não pode ficar em branco'],
|
66
|
+
city_name: ['não pode ficar em branco'], state: ['não está incluído na lista'] })
|
52
67
|
}
|
53
|
-
it { expect(subject.response_errors).to eq({:person_name=>["não pode ficar em branco"], :cnpj_cpf=>["não pode ficar em branco"], :zipcode=>["não pode ficar em branco"]}) }
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
71
|
+
|
72
|
+
describe 'find', vcr: { cassette_name: 'resources/customer/find' } do
|
73
|
+
subject { described_class.find(@customer.id) }
|
74
|
+
|
75
|
+
it { expect(subject).to be_a_kind_of(described_class) }
|
60
76
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
77
|
+
|
78
|
+
describe 'all', vcr: { cassette_name: 'resources/customer/all' } do
|
79
|
+
subject { described_class.all }
|
80
|
+
|
81
|
+
it { expect(subject.first).to be_a_kind_of(described_class) }
|
64
82
|
end
|
65
83
|
end
|
66
|
-
end
|
84
|
+
end
|
@@ -1,56 +1,67 @@
|
|
1
|
-
#
|
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
|
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 =
|
17
|
-
|
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
|
-
|
25
|
-
it
|
26
|
-
|
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
|
-
|
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
|
-
|
46
|
+
described_class.create({ source: '' })
|
41
47
|
end
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
#
|
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
|
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 =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
29
|
-
it
|
30
|
-
|
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
|
-
|
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
|
-
|
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 é um CNPJ ou CPF válido'],
|
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 {
|
53
|
-
|
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 {
|
57
|
-
|
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
|
-
|
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
|