pagseguro-oficial 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/CONTRIBUTING.md +39 -0
  4. data/Dockerfile +20 -0
  5. data/README.md +22 -0
  6. data/docker-compose.yml +5 -0
  7. data/examples/checkout/create_payment_request.rb +1 -1
  8. data/examples/direct/create_transaction_using_boleto.rb +1 -1
  9. data/examples/direct/create_transaction_using_credit_card.rb +1 -1
  10. data/examples/direct/create_transaction_using_online_debit.rb +1 -1
  11. data/examples/preapproval/cancel_preapproval.rb +26 -0
  12. data/examples/preapproval/change_preapproval_payment.rb +50 -0
  13. data/examples/preapproval/change_preapproval_status.rb +29 -0
  14. data/examples/preapproval/charge_preapproval.rb +36 -0
  15. data/examples/preapproval/create_preapproval.rb +68 -0
  16. data/examples/preapproval/create_preapproval_auto.rb +53 -0
  17. data/examples/preapproval/create_preapproval_discount.rb +30 -0
  18. data/examples/preapproval/create_preapproval_manual.rb +58 -0
  19. data/examples/preapproval/create_preapproval_transparent.rb +41 -0
  20. data/examples/preapproval/preapproval_retry.rb +29 -0
  21. data/examples/preapproval/search/search_by_date_interval.rb +45 -0
  22. data/examples/preapproval/search/search_by_days_interval.rb +46 -0
  23. data/examples/preapproval/search/search_by_notification_code.rb +50 -0
  24. data/examples/preapproval/search/search_by_subscription_code.rb +50 -0
  25. data/examples/preapproval/search/search_subscription_payment_orders.rb +53 -0
  26. data/examples/split_payment/create_payment_request.rb +1 -1
  27. data/examples/split_payment/create_transaction_using_boleto.rb +118 -0
  28. data/examples/split_payment/create_transaction_using_credit_card.rb +152 -0
  29. data/lib/pagseguro.rb +33 -1
  30. data/lib/pagseguro/credit_card_transaction_request.rb +1 -1
  31. data/lib/pagseguro/document.rb +8 -0
  32. data/lib/pagseguro/holder.rb +8 -0
  33. data/lib/pagseguro/manual_subscription_charger.rb +59 -0
  34. data/lib/pagseguro/manual_subscription_charger/request_serializer.rb +50 -0
  35. data/lib/pagseguro/manual_subscription_charger/response.rb +36 -0
  36. data/lib/pagseguro/manual_subscription_charger/response_serializer.rb +17 -0
  37. data/lib/pagseguro/payment_request/request_serializer.rb +25 -1
  38. data/lib/pagseguro/receiver.rb +3 -0
  39. data/lib/pagseguro/request.rb +32 -2
  40. data/lib/pagseguro/sender.rb +21 -3
  41. data/lib/pagseguro/subscription.rb +132 -0
  42. data/lib/pagseguro/subscription/request_serializer.rb +129 -0
  43. data/lib/pagseguro/subscription/response.rb +49 -0
  44. data/lib/pagseguro/subscription/response_serializer.rb +62 -0
  45. data/lib/pagseguro/subscription/subscription_search.rb +135 -0
  46. data/lib/pagseguro/subscription_canceller.rb +30 -0
  47. data/lib/pagseguro/subscription_canceller/response.rb +34 -0
  48. data/lib/pagseguro/subscription_change_payment.rb +46 -0
  49. data/lib/pagseguro/subscription_change_payment/request_serializer.rb +80 -0
  50. data/lib/pagseguro/subscription_change_payment/response.rb +26 -0
  51. data/lib/pagseguro/subscription_change_status.rb +50 -0
  52. data/lib/pagseguro/subscription_change_status/request_serializer.rb +28 -0
  53. data/lib/pagseguro/subscription_change_status/response.rb +26 -0
  54. data/lib/pagseguro/subscription_discount.rb +41 -0
  55. data/lib/pagseguro/subscription_discount/request_serializer.rb +34 -0
  56. data/lib/pagseguro/subscription_discount/response.rb +34 -0
  57. data/lib/pagseguro/subscription_payment_method.rb +21 -0
  58. data/lib/pagseguro/subscription_payment_order.rb +57 -0
  59. data/lib/pagseguro/subscription_payment_order/response.rb +37 -0
  60. data/lib/pagseguro/subscription_payment_order/response_serializer.rb +51 -0
  61. data/lib/pagseguro/subscription_plan.rb +69 -0
  62. data/lib/pagseguro/subscription_plan/request_serializer.rb +81 -0
  63. data/lib/pagseguro/subscription_plan/response.rb +36 -0
  64. data/lib/pagseguro/subscription_plan/response_serializer.rb +17 -0
  65. data/lib/pagseguro/subscription_retry.rb +35 -0
  66. data/lib/pagseguro/subscription_retry/response.rb +34 -0
  67. data/lib/pagseguro/subscription_search_payment_orders.rb +131 -0
  68. data/lib/pagseguro/subscription_transaction.rb +29 -0
  69. data/lib/pagseguro/subscription_transactions.rb +5 -0
  70. data/lib/pagseguro/transaction.rb +0 -10
  71. data/lib/pagseguro/transaction/serializer.rb +19 -2
  72. data/lib/pagseguro/transaction_request.rb +26 -1
  73. data/lib/pagseguro/transaction_request/request_serializer.rb +164 -1
  74. data/lib/pagseguro/version.rb +1 -1
  75. data/spec/fixtures/manual_subscription_charger/fail.xml +6 -0
  76. data/spec/fixtures/manual_subscription_charger/success.xml +4 -0
  77. data/spec/fixtures/subscription/fail.xml +6 -0
  78. data/spec/fixtures/subscription/find_success.xml +28 -0
  79. data/spec/fixtures/subscription/search_success.xml +18 -0
  80. data/spec/fixtures/subscription/success.xml +4 -0
  81. data/spec/fixtures/subscription_canceller/fail.xml +6 -0
  82. data/spec/fixtures/subscription_change_payment/fail.xml +7 -0
  83. data/spec/fixtures/subscription_change_status/fail.xml +7 -0
  84. data/spec/fixtures/subscription_discount/fail.xml +6 -0
  85. data/spec/fixtures/subscription_payment_order/success.xml +18 -0
  86. data/spec/fixtures/subscription_plan/fail.xml +6 -0
  87. data/spec/fixtures/subscription_plan/success.xml +4 -0
  88. data/spec/fixtures/subscription_retry/fail.xml +7 -0
  89. data/spec/fixtures/subscription_search_payment_orders/success.xml +43 -0
  90. data/spec/fixtures/transactions/without_status_and_type.xml +71 -0
  91. data/spec/pagseguro/credit_card_transaction_request_spec.rb +1 -1
  92. data/spec/pagseguro/document_spec.rb +15 -0
  93. data/spec/pagseguro/holder_spec.rb +1 -0
  94. data/spec/pagseguro/manual_subscription_charger/request_serializer_spec.rb +79 -0
  95. data/spec/pagseguro/manual_subscription_charger/response_serializer_spec.rb +10 -0
  96. data/spec/pagseguro/manual_subscription_charger/response_spec.rb +65 -0
  97. data/spec/pagseguro/manual_subscription_charger_spec.rb +68 -0
  98. data/spec/pagseguro/payment_request/request_serializer_spec.rb +54 -22
  99. data/spec/pagseguro/receiver_spec.rb +1 -0
  100. data/spec/pagseguro/sender_spec.rb +16 -2
  101. data/spec/pagseguro/subscription/request_serializer_spec.rb +233 -0
  102. data/spec/pagseguro/subscription/response_serializer_spec.rb +46 -0
  103. data/spec/pagseguro/subscription/response_spec.rb +79 -0
  104. data/spec/pagseguro/subscription/subscription_search_spec.rb +154 -0
  105. data/spec/pagseguro/subscription_canceller/response_spec.rb +58 -0
  106. data/spec/pagseguro/subscription_canceller_spec.rb +57 -0
  107. data/spec/pagseguro/subscription_change_payment/request_serializer_spec.rb +150 -0
  108. data/spec/pagseguro/subscription_change_payment/response_spec.rb +41 -0
  109. data/spec/pagseguro/subscription_change_payment_spec.rb +60 -0
  110. data/spec/pagseguro/subscription_change_status/request_serializer_spec.rb +19 -0
  111. data/spec/pagseguro/subscription_change_status/response_spec.rb +41 -0
  112. data/spec/pagseguro/subscription_change_status_spec.rb +53 -0
  113. data/spec/pagseguro/subscription_discount/request_serializer_spec.rb +27 -0
  114. data/spec/pagseguro/subscription_discount/response_spec.rb +58 -0
  115. data/spec/pagseguro/subscription_discount_spec.rb +60 -0
  116. data/spec/pagseguro/subscription_payment_method_spec.rb +10 -0
  117. data/spec/pagseguro/subscription_payment_order/response_serializer_spec.rb +24 -0
  118. data/spec/pagseguro/subscription_payment_order/response_spec.rb +55 -0
  119. data/spec/pagseguro/subscription_payment_order_spec.rb +27 -0
  120. data/spec/pagseguro/subscription_plan/request_serializer_spec.rb +253 -0
  121. data/spec/pagseguro/subscription_plan/response_serializer_spec.rb +10 -0
  122. data/spec/pagseguro/subscription_plan/response_spec.rb +65 -0
  123. data/spec/pagseguro/subscription_plan_spec.rb +118 -0
  124. data/spec/pagseguro/subscription_retry/response_spec.rb +58 -0
  125. data/spec/pagseguro/subscription_retry_spec.rb +62 -0
  126. data/spec/pagseguro/subscription_search_payment_order_spec.rb +129 -0
  127. data/spec/pagseguro/subscription_spec.rb +137 -0
  128. data/spec/pagseguro/subscription_transaction_spec.rb +24 -0
  129. data/spec/pagseguro/subscription_transactions_spec.rb +37 -0
  130. data/spec/pagseguro/transaction/response_spec.rb +0 -42
  131. data/spec/pagseguro/transaction/serializer_spec.rb +5 -6
  132. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +623 -159
  133. data/spec/pagseguro/transaction_request_spec.rb +26 -0
  134. data/spec/pagseguro/transaction_spec.rb +0 -48
  135. data/spec/spec_helper.rb +1 -0
  136. metadata +154 -8
  137. data/examples/checkout/search/search_transaction_status_history.rb +0 -22
  138. data/lib/pagseguro/transaction/status_collection.rb +0 -20
  139. data/spec/fixtures/transactions/status_history.xml +0 -12
  140. data/spec/pagseguro/transaction/status_collection_spec.rb +0 -43
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionChangePayment::Response do
4
+ subject { described_class.new(response, object) }
5
+
6
+ let(:object) { PagSeguro::SubscriptionChangePayment.new(subscription_code: '1234') }
7
+
8
+ context 'when request succeeds' do
9
+ let(:response) do
10
+ double(
11
+ :Response,
12
+ xml?: true,
13
+ success?: true
14
+ )
15
+ end
16
+
17
+ it 'not change object errors' do
18
+ expect{ subject.serialize }.to_not change{ object.errors.empty? }
19
+ end
20
+ end
21
+
22
+ context 'when request fails' do
23
+ let(:response) do
24
+ double(
25
+ :Response,
26
+ xml?: true,
27
+ error?: true,
28
+ error: Aitch::BadRequestError,
29
+ success?: false,
30
+ data: parsed_data
31
+ )
32
+ end
33
+
34
+ let(:source) { File.read('./spec/fixtures/subscription_change_payment/fail.xml') }
35
+ let(:parsed_data) { Nokogiri::XML(source) }
36
+
37
+ it 'must change object errors' do
38
+ expect { subject.serialize }.to change { object.errors.empty? }.to false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionChangePayment do
4
+ it_assigns_attribute :subscription_code
5
+
6
+ it_ensures_type PagSeguro::Sender, :sender
7
+ it_ensures_type PagSeguro::SubscriptionPaymentMethod, :subscription_payment_method
8
+
9
+ subject do
10
+ described_class.new(subscription_code: '12345')
11
+ end
12
+
13
+ let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
14
+
15
+ before do
16
+ subject.credentials = credentials
17
+ end
18
+
19
+ context 'errors attribute' do
20
+ it 'should start with errors' do
21
+ expect(subject.errors).to be_a PagSeguro::Errors
22
+ end
23
+
24
+ it 'should start with empty errors' do
25
+ expect(subject.errors).to be_empty
26
+ end
27
+ end
28
+
29
+ context '#update' do
30
+ context 'when succeed' do
31
+ before do
32
+ FakeWeb.register_uri(
33
+ :put,
34
+ "https://ws.pagseguro.uol.com.br/pre-approvals/12345/payment-method?email=user@example.com&token=TOKEN",
35
+ status: ['204', 'No Content']
36
+ )
37
+ end
38
+
39
+ it 'errors must not be present' do
40
+ expect{ subject.update }.to_not change{ subject.errors.empty? }
41
+ end
42
+ end
43
+
44
+ context 'when fails' do
45
+ before do
46
+ FakeWeb.register_uri(
47
+ :put,
48
+ 'https://ws.pagseguro.uol.com.br/pre-approvals/12345/payment-method?email=user@example.com&token=TOKEN',
49
+ body: File.read('./spec/fixtures/subscription_change_payment/fail.xml'),
50
+ status: ['400', 'Bad Request'],
51
+ content_type: 'text/xml'
52
+ )
53
+ end
54
+
55
+ it 'should change errors' do
56
+ expect { subject.update }.to change { subject.errors.empty? }.to false
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionChangeStatus::RequestSerializer do
4
+ let(:object) do
5
+ PagSeguro::SubscriptionChangeStatus.new(12345, :active)
6
+ end
7
+
8
+ subject { described_class.new(object) }
9
+
10
+ context '#serialize' do
11
+ it 'must serialize status' do
12
+ expect(subject.serialize).to match %r[
13
+ .*<directPreApproval>
14
+ .*<status>ACTIVE</status>
15
+ .*</directPreApproval>
16
+ ]xm
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionChangeStatus::Response do
4
+ subject { described_class.new(response, object) }
5
+
6
+ let(:object) { PagSeguro::SubscriptionChangeStatus.new(12345, :active) }
7
+
8
+ context 'when request succeeds' do
9
+ let(:response) do
10
+ double(
11
+ :Response,
12
+ xml?: true,
13
+ success?: true
14
+ )
15
+ end
16
+
17
+ it 'not change object errors' do
18
+ expect{ subject.serialize }.to_not change{ object.errors.empty? }
19
+ end
20
+ end
21
+
22
+ context 'when request fails' do
23
+ let(:response) do
24
+ double(
25
+ :Response,
26
+ xml?: true,
27
+ error?: true,
28
+ error: Aitch::BadRequestError,
29
+ success?: false,
30
+ data: parsed_data
31
+ )
32
+ end
33
+
34
+ let(:source) { File.read('./spec/fixtures/subscription_change_status/fail.xml') }
35
+ let(:parsed_data) { Nokogiri::XML(source) }
36
+
37
+ it 'must change object errors' do
38
+ expect{ subject.serialize }.to change{ object.errors.empty? }.to false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionChangeStatus do
4
+ subject { PagSeguro::SubscriptionChangeStatus.new('12345', :active) }
5
+
6
+ let(:credentials) { PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN') }
7
+
8
+ before do
9
+ subject.credentials = credentials
10
+ end
11
+
12
+ context 'errors attribute' do
13
+ it 'should start with errors' do
14
+ expect(subject.errors).to be_a PagSeguro::Errors
15
+ end
16
+
17
+ it 'should start with empty errors' do
18
+ expect(subject.errors).to be_empty
19
+ end
20
+ end
21
+
22
+ context '#save' do
23
+ context 'when succeed' do
24
+ before do
25
+ FakeWeb.register_uri(
26
+ :put,
27
+ "https://ws.pagseguro.uol.com.br/pre-approvals/12345/status?email=user@example.com&token=TOKEN",
28
+ status: ['204', 'No Content']
29
+ )
30
+ end
31
+
32
+ it 'errors must not be present' do
33
+ expect{ subject.save }.to_not change{ subject.errors.empty? }
34
+ end
35
+ end
36
+
37
+ context 'when fails' do
38
+ before do
39
+ FakeWeb.register_uri(
40
+ :put,
41
+ "https://ws.pagseguro.uol.com.br/pre-approvals/12345/status?email=user@example.com&token=TOKEN",
42
+ body: File.read('./spec/fixtures/subscription_change_status/fail.xml'),
43
+ status: ['400', 'Bad Request'],
44
+ content_type: 'text/xml'
45
+ )
46
+ end
47
+
48
+ it 'errors must be present' do
49
+ expect{ subject.save }.to change{ subject.errors.empty? }.to false
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionDiscount::RequestSerializer do
4
+ context '#to_xml_params' do
5
+ subject { described_class.new(discount) }
6
+
7
+ let(:discount) { PagSeguro::SubscriptionDiscount.new }
8
+
9
+ it 'should serializer type' do
10
+ discount.type = 'DISCOUNT_AMOUNT'
11
+
12
+ expect(subject.to_xml_params).to match %r[
13
+ <directPreApproval>
14
+ .*<type>DISCOUNT_AMOUNT
15
+ ]xm
16
+ end
17
+
18
+ it 'should serializer value' do
19
+ discount.value = 50
20
+
21
+ expect(subject.to_xml_params).to match %r[
22
+ <directPreApproval>
23
+ .*<value>50.00
24
+ ]xm
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PagSeguro::SubscriptionDiscount::Response do
4
+ subject { described_class.new(response, discount) }
5
+
6
+ let(:discount) { PagSeguro::SubscriptionDiscount.new }
7
+
8
+ context '#success?' do
9
+ let(:response) do
10
+ double(:HttpResponse, xml?: true)
11
+ end
12
+
13
+ it 'delegate to response' do
14
+ allow(response).to receive(:success?).and_return(true)
15
+ expect(subject).to be_success
16
+
17
+ allow(response).to receive(:success?).and_return(false)
18
+ expect(subject).not_to be_success
19
+ end
20
+ end
21
+
22
+ describe '#serialize' do
23
+ let(:response) do
24
+ double(:HttpResponse, xml?: true, success?: true)
25
+ end
26
+
27
+ context 'when request succeeds' do
28
+ it 'not change discount errors' do
29
+ expect { subject.serialize }.not_to change { discount.errors.empty? }
30
+ end
31
+ end
32
+
33
+ context 'when request fails' do
34
+ let(:response) do
35
+ double(
36
+ :HttpResponse,
37
+ data: parsed_xml,
38
+ error: Aitch::BadRequestError,
39
+ error?: true,
40
+ success?: false,
41
+ xml?: true
42
+ )
43
+ end
44
+
45
+ let(:raw_xml) do
46
+ File.read('./spec/fixtures/subscription_discount/fail.xml')
47
+ end
48
+
49
+ let(:parsed_xml) do
50
+ Nokogiri::XML(raw_xml)
51
+ end
52
+
53
+ it 'change discount errors' do
54
+ expect { subject.serialize }.to change { discount.errors.empty? }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionDiscount do
4
+ it_assigns_attribute :type
5
+ it_assigns_attribute :value
6
+
7
+ context 'errors attribute' do
8
+ it 'should start with errors' do
9
+ expect(subject.errors).to be_a PagSeguro::Errors
10
+ end
11
+
12
+ it 'should start with empty errors' do
13
+ expect(subject.errors).to be_empty
14
+ end
15
+ end
16
+
17
+ describe '#create' do
18
+ before do
19
+ subject.code = '1234'
20
+ subject.credentials = credentials
21
+
22
+ FakeWeb.register_uri(
23
+ :put,
24
+ 'https://ws.pagseguro.uol.com.br/pre-approvals/1234/discount?email=user@example.com&token=TOKEN',
25
+ body: ''
26
+ )
27
+ end
28
+
29
+ let(:credentials) do
30
+ PagSeguro::AccountCredentials.new('user@example.com', 'TOKEN')
31
+ end
32
+
33
+ let(:request) do
34
+ double(
35
+ :Request,
36
+ success?: true,
37
+ xml?: true,
38
+ body: '<preApprovalRequest><code>1234</code></preApprovalRequest>'
39
+ )
40
+ end
41
+
42
+ it 'sends it to correct url' do
43
+ expect(PagSeguro).to receive(:api_url).with(
44
+ 'pre-approvals/1234/discount?email=user@example.com&token=TOKEN'
45
+ ).and_return('https://ws.pagseguro.uol.com.br/pre-approvals/1234/discount?email=user@example.com&token=TOKEN')
46
+
47
+ subject.create
48
+ end
49
+
50
+ context 'when parsing' do
51
+ it 'create a discount' do
52
+ expect(PagSeguro::Request).to receive(:put_xml).with(
53
+ 'pre-approvals/1234/discount', credentials, a_string_matching(/<directPreApproval>/)
54
+ ).and_return(request)
55
+
56
+ subject.create
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionPaymentMethod do
4
+ it_assigns_attribute :token
5
+ it_ensures_type PagSeguro::Holder, :holder
6
+
7
+ it 'payment_method must be CREDITCARD' do
8
+ expect(subject.type).to eq 'CREDITCARD'
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionPaymentOrder::ResponseSerializer do
4
+ let(:xml) { Nokogiri::XML(source) }
5
+ let(:source) { File.read('./spec/fixtures/subscription_payment_order/success.xml') }
6
+
7
+ subject { described_class.new(xml) }
8
+
9
+ context '#serialize' do
10
+ let(:data) { subject.serialize }
11
+
12
+ it { expect(data[:code]).to eq 'D2579C9461BA45F880419FE535763EFE' }
13
+ it { expect(data[:status]).to eq :paid }
14
+ it { expect(data[:amount]).to eq '80.00' }
15
+ it { expect(data[:gross_amount]).to eq '230' }
16
+ it { expect(data[:last_event_date]).to eq Time.new(2016,3,30,0,50,11, '-03:00') }
17
+ it { expect(data[:discount][:type]).to eq 'DISCOUNT_PERCENT' }
18
+ it { expect(data[:discount][:value]).to eq '0' }
19
+ it { expect(data[:scheduling_date]).to eq Time.new(2016,4,14,15,14,29, '-03:00') }
20
+ it { expect(data[:transactions][0][:code]).to eq 'DBFABA621D734DCDA471F592E964A39E' }
21
+ it { expect(data[:transactions][0][:date]).to eq Time.new(2016,3,30,0,48,49, '-03:00') }
22
+ it { expect(data[:transactions][0][:status]).to eq :paid }
23
+ end
24
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagSeguro::SubscriptionPaymentOrder::Response do
4
+ subject { described_class.new(response, object) }
5
+
6
+ let(:object) { PagSeguro::SubscriptionPaymentOrder.new }
7
+
8
+ let(:response) do
9
+ double(
10
+ :HttpResponse,
11
+ xml?: true
12
+ )
13
+ end
14
+
15
+ context 'when response has errors' do
16
+ before do
17
+ allow(response).
18
+ to receive_messages(
19
+ success?: false,
20
+ error?: true,
21
+ error: Aitch::ResponseError
22
+ )
23
+ end
24
+
25
+ it 'must respond false to success?' do
26
+ expect(subject).not_to be_success
27
+ end
28
+
29
+ it 'object must have errors' do
30
+ expect{ subject.serialize }.to change{ object.errors }
31
+ end
32
+ end
33
+
34
+ context 'when response succeeds' do
35
+ before do
36
+ allow(response).
37
+ to receive_messages(
38
+ success?: true,
39
+ data: File.read('./spec/fixtures/subscription_payment_order/success.xml')
40
+ )
41
+ end
42
+
43
+ it 'must respond true to success?' do
44
+ expect(subject).to be_success
45
+ end
46
+
47
+ it 'object must not have errors' do
48
+ expect{ subject.serialize }.not_to change{ object.errors.empty? }
49
+ end
50
+
51
+ it 'object must be updated with serialized attributes' do
52
+ expect{ subject.serialize }.to change{ object.code }
53
+ end
54
+ end
55
+ end