pagseguro-oficial 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile +0 -2
  5. data/README.md +1 -1
  6. data/docs/transparent_checkout.md +3 -3
  7. data/examples/authorization/create_authorization.rb +32 -0
  8. data/examples/authorization/create_authorization_with_account.rb +56 -0
  9. data/examples/authorization/{authorization_by_code.rb → search/search_authorization_by_code.rb} +4 -4
  10. data/examples/authorization/search/search_authorization_by_date.rb +35 -0
  11. data/examples/authorization/{authorization_by_notification_code.rb → search/search_authorization_by_notification_code.rb} +4 -5
  12. data/examples/authorization/search/search_authorization_by_reference.rb +31 -0
  13. data/examples/{payment_request.rb → checkout/create_payment_request.rb} +5 -7
  14. data/examples/{transaction/abandoned_transactions.rb → checkout/search/search_abandoned_transactions.rb} +6 -3
  15. data/examples/{transaction/transaction_by_code.rb → checkout/search/search_transaction_by_code.rb} +3 -3
  16. data/examples/{transaction/transaction_by_notification_code.rb → checkout/search/search_transaction_by_notification_code.rb} +3 -3
  17. data/examples/{transaction/transaction_by_reference.rb → checkout/search/search_transaction_by_reference.rb} +3 -3
  18. data/examples/{transaction/transaction_status_history.rb → checkout/search/search_transaction_status_history.rb} +2 -2
  19. data/examples/{transaction/transactions_by_date.rb → checkout/search/search_transactions_by_date.rb} +3 -3
  20. data/examples/{transaction/boleto_transaction_request.rb → direct/create_transaction_using_boleto.rb} +1 -1
  21. data/examples/{transaction/credit_card_transaction_request.rb → direct/create_transaction_using_credit_card.rb} +1 -1
  22. data/examples/{transaction/online_debit_transaction.rb → direct/create_transaction_using_online_debit.rb} +1 -1
  23. data/examples/{installment.rb → get_installments.rb} +3 -3
  24. data/examples/{transaction/transaction_cancellation.rb → request_transaction_cancellation.rb} +2 -2
  25. data/examples/{authorization/authorization.rb → split_payment/create_authorization.rb} +5 -4
  26. data/examples/split_payment/create_payment_request.rb +71 -0
  27. data/lib/pagseguro.rb +14 -8
  28. data/lib/pagseguro/account.rb +29 -0
  29. data/lib/pagseguro/authorization.rb +10 -4
  30. data/lib/pagseguro/authorization/collection.rb +3 -1
  31. data/lib/pagseguro/authorization/request_serializer.rb +6 -6
  32. data/lib/pagseguro/authorization/response.rb +2 -2
  33. data/lib/pagseguro/authorization_request.rb +16 -4
  34. data/lib/pagseguro/authorization_request/request_serializer.rb +127 -15
  35. data/lib/pagseguro/authorization_request/response.rb +2 -2
  36. data/lib/pagseguro/company.rb +41 -0
  37. data/lib/pagseguro/document.rb +4 -0
  38. data/lib/pagseguro/documents.rb +5 -0
  39. data/lib/pagseguro/errors.rb +27 -5
  40. data/lib/pagseguro/extensions/collection_object.rb +34 -0
  41. data/lib/pagseguro/item.rb +4 -0
  42. data/lib/pagseguro/items.rb +10 -17
  43. data/lib/pagseguro/partner.rb +20 -0
  44. data/lib/pagseguro/payment_request.rb +30 -2
  45. data/lib/pagseguro/payment_request/{serializer.rb → request_serializer.rb} +86 -1
  46. data/lib/pagseguro/person.rb +40 -0
  47. data/lib/pagseguro/phone.rb +8 -0
  48. data/lib/pagseguro/phones.rb +5 -0
  49. data/lib/pagseguro/receiver.rb +17 -0
  50. data/lib/pagseguro/receiver_split.rb +15 -0
  51. data/lib/pagseguro/request.rb +25 -1
  52. data/lib/pagseguro/transaction.rb +7 -5
  53. data/lib/pagseguro/transaction_cancellation.rb +3 -6
  54. data/lib/pagseguro/transaction_cancellation/response.rb +7 -6
  55. data/lib/pagseguro/{refund.rb → transaction_refund.rb} +2 -2
  56. data/lib/pagseguro/{refund → transaction_refund}/request_serializer.rb +1 -1
  57. data/lib/pagseguro/{refund → transaction_refund}/response.rb +9 -9
  58. data/lib/pagseguro/{refund → transaction_refund}/response_serializer.rb +1 -1
  59. data/lib/pagseguro/transaction_request.rb +1 -4
  60. data/lib/pagseguro/transaction_request/response.rb +8 -7
  61. data/lib/pagseguro/version.rb +1 -1
  62. data/locales/pt-BR.yml +1 -0
  63. data/pagseguro-oficial.gemspec +13 -13
  64. data/spec/fixtures/authorization/search_authorization.xml +47 -0
  65. data/spec/fixtures/authorization_request/authorization_request.xml +11 -0
  66. data/spec/fixtures/authorization_request/authorization_request_with_account.xml +47 -0
  67. data/spec/pagseguro/account_spec.rb +27 -0
  68. data/spec/pagseguro/authorization/collection_spec.rb +3 -3
  69. data/spec/pagseguro/authorization/request_serializer_spec.rb +1 -2
  70. data/spec/pagseguro/authorization/response_spec.rb +70 -15
  71. data/spec/pagseguro/authorization_request/request_serializer_spec.rb +314 -14
  72. data/spec/pagseguro/authorization_request_spec.rb +96 -31
  73. data/spec/pagseguro/authorization_spec.rb +52 -10
  74. data/spec/pagseguro/company_spec.rb +12 -0
  75. data/spec/pagseguro/documents_spec.rb +37 -0
  76. data/spec/pagseguro/errors_spec.rb +45 -6
  77. data/spec/pagseguro/extensions/collection_object_spec.rb +77 -0
  78. data/spec/pagseguro/features/create_transaction_request_spec.rb +2 -2
  79. data/spec/pagseguro/installment/response_spec.rb +5 -3
  80. data/spec/pagseguro/installment_spec.rb +5 -2
  81. data/spec/pagseguro/items_spec.rb +104 -12
  82. data/spec/pagseguro/pagseguro_spec.rb +8 -8
  83. data/spec/pagseguro/partner_spec.rb +8 -0
  84. data/spec/pagseguro/payment_request/request_serializer_spec.rb +251 -0
  85. data/spec/pagseguro/payment_request_spec.rb +67 -11
  86. data/spec/pagseguro/person_spec.rb +10 -0
  87. data/spec/pagseguro/phones_spec.rb +38 -0
  88. data/spec/pagseguro/receiver_spec.rb +6 -0
  89. data/spec/pagseguro/receiver_split_spec.rb +7 -0
  90. data/spec/pagseguro/request_spec.rb +27 -4
  91. data/spec/pagseguro/session/response_spec.rb +6 -2
  92. data/spec/pagseguro/session_spec.rb +5 -2
  93. data/spec/pagseguro/transaction/response_spec.rb +14 -8
  94. data/spec/pagseguro/transaction/search_spec.rb +15 -8
  95. data/spec/pagseguro/transaction_cancellation/response_spec.rb +6 -3
  96. data/spec/pagseguro/transaction_cancellation_spec.rb +7 -5
  97. data/spec/pagseguro/{refund → transaction_refund}/request_serializer_spec.rb +3 -3
  98. data/spec/pagseguro/{refund → transaction_refund}/response_serializer_spec.rb +1 -1
  99. data/spec/pagseguro/{refund → transaction_refund}/response_spec.rb +3 -3
  100. data/spec/pagseguro/{refund_spec.rb → transaction_refund_spec.rb} +15 -7
  101. data/spec/pagseguro/transaction_request/request_serializer_spec.rb +9 -9
  102. data/spec/pagseguro/transaction_request/response_spec.rb +5 -2
  103. data/spec/pagseguro/transaction_request_spec.rb +14 -9
  104. data/spec/pagseguro/transaction_spec.rb +37 -30
  105. data/spec/spec_helper.rb +0 -3
  106. data/spec/support/ensure_type_macro.rb +20 -2
  107. data/{examples/refund.rb → transaction/transaction_refund.rb} +1 -1
  108. metadata +112 -96
  109. data/examples/transaction/invalid_transaction_by_notification_code.rb +0 -22
  110. data/lib/pagseguro/refund/serializer.rb +0 -24
  111. data/lib/pagseguro/transaction_cancellation/serializer.rb +0 -18
  112. data/spec/pagseguro/payment_request/serializer_spec.rb +0 -166
  113. data/spec/pagseguro/refund/serializer_spec.rb +0 -15
  114. data/spec/pagseguro/transaction_cancellation/serializer_spec.rb +0 -13
@@ -0,0 +1,47 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <authorizationRequest>
3
+ <reference>123</reference>
4
+ <redirectURL>http://seusite.com.br/redirect</redirectURL>
5
+ <notificationURL>http://seusite.com.br/notification</notificationURL>
6
+ <permissions>
7
+ <code>CREATE_CHECKOUTS</code>
8
+ <code>SEARCH_TRANSACTIONS</code>
9
+ <code>RECEIVE_TRANSACTION_NOTIFICATIONS</code>
10
+ </permissions>
11
+ <account>
12
+ <email>usuario@seusite.com.br</email>
13
+ <type>SELLER</type>
14
+ <person>
15
+ <name>Antonio Carlos</name>
16
+ <birthDate>05/02/1982</birthDate>
17
+ <address>
18
+ <postalCode>414722</postalCode>
19
+ <street>Av. Brig. Faria Lima</street>
20
+ <number>1384</number>
21
+ <complement>5o andar</complement>
22
+ <district>Jardim Paulistano</district>
23
+ <city>Sao Paulo</city>
24
+ <state>SP</state>
25
+ <country>BRA</country>
26
+ </address>
27
+ <documents>
28
+ <document>
29
+ <type>CPF</type>
30
+ <value>99988877766</value>
31
+ </document>
32
+ </documents>
33
+ <phones>
34
+ <phone>
35
+ <type>HOME</type>
36
+ <areaCode>11</areaCode>
37
+ <number>30302323</number>
38
+ </phone>
39
+ <phone>
40
+ <type>MOBILE</type>
41
+ <areaCode>11</areaCode>
42
+ <number>976302323</number>
43
+ </phone>
44
+ </phones>
45
+ </person>
46
+ </account>
47
+ </authorizationRequest>
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PagSeguro::Account do
4
+ it_assigns_attribute :email
5
+ it_assigns_attribute :type
6
+
7
+ it_ensures_type PagSeguro::Company, :company
8
+ it_ensures_type PagSeguro::Person, :person
9
+
10
+ context 'only person or company should be assigned' do
11
+ it "with company assigned, person can't be assigned too" do
12
+ subject.company = PagSeguro::Company.new
13
+ subject.person = PagSeguro::Person.new
14
+
15
+ expect(subject.company).to be_a PagSeguro::Company
16
+ expect(subject.person).to be_nil
17
+ end
18
+
19
+ it "with person assigned, company can't be assigned too" do
20
+ subject.person = PagSeguro::Person.new
21
+ subject.company = PagSeguro::Company.new
22
+
23
+ expect(subject.person).to be_a PagSeguro::Person
24
+ expect(subject.company).to be_nil
25
+ end
26
+ end
27
+ end
@@ -42,8 +42,8 @@ describe PagSeguro::Authorization::Collection do
42
42
  end
43
43
 
44
44
  describe "method delegation" do
45
- it { subject.respond_to? (:each) }
46
- it { subject.respond_to? (:empty?) }
47
- it { subject.respond_to? (:any?) }
45
+ it { is_expected.to respond_to(:each) }
46
+ it { is_expected.to respond_to(:empty?) }
47
+ it { is_expected.to respond_to(:any?) }
48
48
  end
49
49
  end
@@ -3,8 +3,7 @@ require "spec_helper"
3
3
  describe PagSeguro::Authorization::RequestSerializer do
4
4
  let(:credentials) { PagSeguro::ApplicationCredentials.new('app11', 'sada') }
5
5
  let(:options) { { credentials: credentials } }
6
- let(:authorization) { PagSeguro::Authorization.new(options) }
7
- let(:serializer) { described_class.new(authorization) }
6
+ let(:serializer) { described_class.new(options) }
8
7
  let(:params) { serializer.to_params }
9
8
 
10
9
  it{ expect(params).to include(credentials: credentials) }
@@ -1,35 +1,90 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe PagSeguro::Authorization::Response do
4
- let(:xml) { File.read("./spec/fixtures/authorization/find_authorization.xml") }
5
- let(:http_response) do
6
- response = double(body: xml, code: 200, content_type: "text/xml", "[]" => nil)
7
- Aitch::Response.new({xml_parser: Aitch::XMLParser}, response)
8
- end
4
+ subject { described_class.new(response, object) }
5
+
6
+ describe "#serialize_collection" do
7
+ let(:xml) { File.read("./spec/fixtures/authorization/search_authorization.xml") }
8
+ let(:object) { PagSeguro::Authorization::Collection.new }
9
+ let(:response) do
10
+ double(
11
+ :Response,
12
+ body: xml,
13
+ code: 200,
14
+ success?: true,
15
+ xml?: true
16
+ )
17
+ end
18
+
19
+ context "when request succeeds" do
20
+ it "does not return a empty collection" do
21
+ expect { subject.serialize_collection }.not_to change { object.errors.empty? }
22
+ end
23
+
24
+ it "must have only PagSeguro::Authorization" do
25
+ subject.serialize_collection
26
+
27
+ object.each do |authorization|
28
+ expect(authorization).to be_a_kind_of PagSeguro::Authorization
29
+ end
30
+ end
31
+ end
9
32
 
33
+ context "when request fails" do
34
+ let(:response) do
35
+ double(
36
+ :Response,
37
+ body: xml,
38
+ code: 403,
39
+ xml?: true,
40
+ success?: false,
41
+ error?: true,
42
+ error: Aitch::ForbiddenError
43
+ )
44
+ end
45
+
46
+ it "serialize errors" do
47
+ expect { subject.serialize_collection }.to change { object.errors.empty? }
48
+ end
49
+ end
50
+ end
10
51
 
11
52
  describe "#serialize" do
12
- subject { described_class.new(http_response, authorization) }
13
- let(:authorization) { PagSeguro::Authorization.new }
53
+ let(:xml) { File.read("./spec/fixtures/authorization/find_authorization.xml") }
54
+ let(:object) { PagSeguro::Authorization.new }
14
55
 
15
56
  context "when request succeeds" do
16
- let(:serializer) { double(:serializer) }
17
- let(:serialized_data) { { code: "1234"} }
57
+ let(:response) do
58
+ double(
59
+ :Response,
60
+ body: xml,
61
+ code: 200,
62
+ xml?: true,
63
+ success?: true,
64
+ )
65
+ end
18
66
 
19
67
  it "returns a hash with serialized response data" do
20
- expect(subject.serialize).to eq(authorization)
68
+ expect { subject.serialize }.to change { object.code }.to('9D7FF2E921216F1334EE9FBEB7B4EBBC')
21
69
  end
22
70
  end
23
71
 
24
72
  context "when request fails" do
25
- before do
26
- expect(http_response).to receive(:success?).and_return(false)
73
+ let(:response) do
74
+ double(
75
+ :Response,
76
+ body: xml,
77
+ code: 404,
78
+ xml?: true,
79
+ success?: false,
80
+ error?: true,
81
+ error: Aitch::NotFoundError
82
+ )
27
83
  end
28
84
 
29
- it "returns a hash with an errors object" do
30
- expect(subject.serialize.errors).to be_a(PagSeguro::Errors)
85
+ it "serialize errors" do
86
+ expect { subject.serialize }.to change { object.errors.empty? }
31
87
  end
32
88
  end
33
89
  end
34
90
  end
35
-
@@ -1,23 +1,323 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'when address is assigned' do
4
+ it 'can have a postal code' do
5
+ address[:postal_code] = '01452002'
6
+
7
+ postal_code_parsed = node.at_css('> postalCode').text
8
+ expect(postal_code_parsed).to eq '01452002'
9
+ end
10
+
11
+ it 'can have a street' do
12
+ address[:street] = 'Av. Brig. Faria Lima'
13
+
14
+ street_parsed = node.at_css('> street').text
15
+ expect(street_parsed).to eq 'Av. Brig. Faria Lima'
16
+ end
17
+
18
+ it 'can have a number' do
19
+ address[:number] = '1384'
20
+
21
+ number_parsed = node.at_css('> number').text
22
+ expect(number_parsed).to eq '1384'
23
+ end
24
+
25
+ it 'can have a complement' do
26
+ address[:complement] = '5o andar'
27
+
28
+ complement_parsed = node.at_css('> complement').text
29
+ expect(complement_parsed).to eq '5o andar'
30
+ end
31
+
32
+ it 'can have a district' do
33
+ address[:district] = 'Jardim Paulistano'
34
+
35
+ district_parsed = node.at_css('> district').text
36
+ expect(district_parsed).to eq 'Jardim Paulistano'
37
+ end
38
+
39
+ it 'can have a city' do
40
+ address[:city] = 'Sao Paulo'
41
+
42
+ city_parsed = node.at_css('> city').text
43
+ expect(city_parsed).to eq 'Sao Paulo'
44
+ end
45
+
46
+ it 'can have a state' do
47
+ address[:state] = 'SP'
48
+
49
+ state_parsed = node.at_css('> state').text
50
+ expect(state_parsed).to eq 'SP'
51
+ end
52
+
53
+ it 'can have a country' do
54
+ address[:country] = 'BRA'
55
+
56
+ country_parsed = node.at_css('> country').text
57
+ expect(country_parsed).to eq 'BRA'
58
+ end
59
+ end
60
+
61
+ shared_examples 'when documents is assigned' do
62
+ context 'when one document is given' do
63
+ before do
64
+ documents << { type: 'CPF', value: '99988877766' }
65
+ end
66
+
67
+ let(:documents_parsed) { node.css('> document') }
68
+
69
+ it 'must have the correct type' do
70
+ expect( documents_parsed.at_css('> type').text ).to eq 'CPF'
71
+ end
72
+
73
+ it 'must have the correct value' do
74
+ expect( documents_parsed.at_css('> value').text ).to eq '99988877766'
75
+ end
76
+ end
77
+
78
+ context 'when multiple documents is given' do
79
+ before do
80
+ documents << { type: 'CPF', value: '99988877766' }
81
+ documents << { type: 'CNPJ', value: '17302417000101' }
82
+ end
83
+
84
+ let(:documents_parsed) do
85
+ node.css('> document').map do |node|
86
+ {
87
+ type: node.at_css('> type').text,
88
+ value: node.at_css('> value').text
89
+ }
90
+ end
91
+ end
92
+
93
+ it 'must have the correct number of documents' do
94
+ expect(documents_parsed.size).to eq 2
95
+ end
96
+
97
+ it 'must have the correct documents' do
98
+ expect(documents_parsed).to contain_exactly(
99
+ { type: 'CPF', value: '99988877766' },
100
+ { type: 'CNPJ', value: '17302417000101' }
101
+ )
102
+ end
103
+ end
104
+ end
105
+
106
+ shared_examples 'when phones is assigned' do
107
+ context 'when one phone is given' do
108
+ before do
109
+ phones << { type: 'HOME', area_code: '11', number: '30302323' }
110
+ end
111
+
112
+ let(:phone_parsed) { node.at_css('> phone') }
113
+
114
+ it 'must have a type' do
115
+ expect( phone_parsed.at_css('> type').text ).to eq 'HOME'
116
+ end
117
+
118
+ it 'must have an area code' do
119
+ expect( phone_parsed.at_css('> areaCode').text ).to eq '11'
120
+ end
121
+
122
+ it 'must have a number' do
123
+ expect( phone_parsed.at_css('> number').text ).to eq '30302323'
124
+ end
125
+ end
126
+
127
+ context 'can have multiple phones' do
128
+ before do
129
+ phones << { type: 'HOME', area_code: '11', number: '30302323' }
130
+ phones << { type: 'MOBILE', area_code: '11', number: '976302323' }
131
+ end
132
+
133
+ let(:phones_parsed) do
134
+ node.css('> phone').map do |phone|
135
+ {
136
+ type: phone.at_css('> type').text,
137
+ area_code: phone.at_css('> areaCode').text,
138
+ number: phone.at_css('> number').text
139
+ }
140
+ end
141
+ end
142
+
143
+ it 'must have the correct number of phones' do
144
+ expect(phones_parsed.size).to eq 2
145
+ end
146
+
147
+ it 'must have the correct phones' do
148
+ expect(phones_parsed).to contain_exactly(
149
+ { type: 'HOME', area_code: '11', number: '30302323' },
150
+ { type: 'MOBILE', area_code: '11', number: '976302323' }
151
+ )
152
+ end
153
+ end
154
+ end
2
155
 
3
156
  describe PagSeguro::AuthorizationRequest::RequestSerializer do
4
- let(:credentials) { PagSeguro::ApplicationCredentials.new('app11', 'sada') }
157
+ let(:credentials) { PagSeguro::ApplicationCredentials.new('app123', 'key123') }
5
158
  let(:options) do
6
159
  {
7
160
  credentials: credentials,
8
- permissions: [:checkouts, :notifications],
9
- notification_url: 'foo.com',
10
- redirect_url: 'bar.com',
11
- reference: 'ref1234'
161
+ permissions: [:checkouts, :searches, :notifications],
162
+ notification_url: 'http://seusite.com.br/redirect',
163
+ redirect_url: 'http://seusite.com.br/notification'
12
164
  }
13
165
  end
14
- let(:authorization) { PagSeguro::AuthorizationRequest.new(options) }
15
- let(:serializer) { described_class.new(authorization) }
16
- let(:params) { serializer.to_params }
17
166
 
18
- it{ expect(params).to include(credentials: credentials) }
19
- it{ expect(params).to include(permissions: 'CREATE_CHECKOUTS,RECEIVE_TRANSACTION_NOTIFICATIONS') }
20
- it{ expect(params).to include(notificationURL: 'foo.com') }
21
- it{ expect(params).to include(redirectURL: 'bar.com') }
22
- it{ expect(params).to include(reference: 'ref1234') }
167
+ let(:authorization_request) { PagSeguro::AuthorizationRequest.new(options) }
168
+ let(:serializer) { described_class.new(authorization_request) }
169
+ let(:xml) { serializer.build_xml }
170
+ let(:xml_parsed) { Nokogiri::XML(xml) }
171
+ let(:node) { xml_parsed.at_css('authorizationRequest') }
172
+
173
+ it 'encoding should be equal to application encoding' do
174
+ encoding = xml_parsed.encoding
175
+ expect(encoding).to eq PagSeguro.encoding
176
+ end
177
+
178
+ it 'must have a authorizationRequest' do
179
+ expect(node).to be_a_instance_of Nokogiri::XML::Element
180
+ end
181
+
182
+ it 'must have the correct permissions' do
183
+ permissions = options[:permissions].map{|value| PagSeguro::AuthorizationRequest::PERMISSIONS[value] }
184
+ permissions_code_parsed = xml_parsed.css('authorizationRequest > permissions > code').map(&:text)
185
+
186
+ expect(permissions).to eq permissions_code_parsed
187
+ end
188
+
189
+ it 'must have a redirect URL' do
190
+ redirect_url_parsed = xml_parsed.at_css('authorizationRequest > redirectURL').text
191
+ expect(redirect_url_parsed).to eq options[:redirect_url]
192
+ end
193
+
194
+ it 'must have a notification URL' do
195
+ notification_url = xml_parsed.at_css('authorizationRequest > notificationURL').text
196
+ expect(notification_url).to eq options[:notification_url]
197
+ end
198
+
199
+ context 'when an account is assigned' do
200
+ let(:account) { {} }
201
+ let(:options) { super().merge(account: account) }
202
+ let(:node) { super().at_css('> account') }
203
+
204
+ it 'can have an email' do
205
+ account[:email] = 'usuario@seusite.com.br'
206
+ expect( node.at_css('> email').text ).to eq 'usuario@seusite.com.br'
207
+ end
208
+
209
+ it 'can have a type' do
210
+ account[:type] = 'SELLER'
211
+ expect( node.at_css('> type').text ).to eq 'SELLER'
212
+ end
213
+
214
+ context 'when a person is assigned' do
215
+ let(:person) { {} }
216
+ let(:account) { super().merge(person: person) }
217
+ let(:node) { super().at_css('> person') }
218
+
219
+ it 'can have name' do
220
+ person[:name] = 'Antonio Carlos'
221
+ expect( node.at_css('> name').text ).to eq 'Antonio Carlos'
222
+ end
223
+
224
+ it 'can have birth date' do
225
+ person[:birth_date] = Date.new(1982, 2, 5)
226
+ expect( node.at_css('> birthDate').text ).to eq '1982-02-05'
227
+ end
228
+
229
+ context 'when the address is assigned' do
230
+ let(:address) { {} }
231
+ let(:person) { super().merge(address: address) }
232
+ let(:node) { super().at_css('> address') }
233
+
234
+ include_examples 'when address is assigned'
235
+ end
236
+
237
+ context 'when the documents is assigned' do
238
+ let(:documents) { [] }
239
+ let(:person) { super().merge({ documents: documents }) }
240
+ let(:node) { super().at_css('> documents') }
241
+
242
+ include_examples 'when documents is assigned'
243
+ end
244
+
245
+ context 'when the phones' do
246
+ let(:phones) { [] }
247
+ let(:person) { super().merge({ phones: phones }) }
248
+ let(:node) { super().at_css('> phones') }
249
+
250
+ include_examples 'when phones is assigned'
251
+ end
252
+ end
253
+
254
+ context 'when the company is assigned' do
255
+ let(:company) { {} }
256
+ let(:account) { super().merge({ company: company }) }
257
+ let(:node) { super().at_css('> company') }
258
+
259
+ it 'can have a name' do
260
+ company[:name] = 'Seu Site'
261
+ expect( node.at_css('> name').text ).to eq 'Seu Site'
262
+ end
263
+
264
+ it 'can have a display name' do
265
+ company[:display_name] = 'Seu Site'
266
+ expect( node.at_css('> displayName').text ).to eq 'Seu Site'
267
+ end
268
+
269
+ it 'can have a website url' do
270
+ company[:website_url] = 'http://www.seusite.com.br'
271
+ expect( node.at_css('> websiteURL').text ).to eq 'http://www.seusite.com.br'
272
+ end
273
+
274
+ context 'when the address is assigned' do
275
+ let(:address) { {} }
276
+ let(:company) { super().merge(address: address) }
277
+ let(:node) { super().at_css('> address') }
278
+
279
+ include_examples 'when address is assigned'
280
+ end
281
+
282
+ context 'when the documents is assigned' do
283
+ let(:documents) { [] }
284
+ let(:company) { super().merge({ documents: documents }) }
285
+ let(:node) { super().at_css('> documents') }
286
+
287
+ include_examples 'when documents is assigned'
288
+ end
289
+
290
+ context 'when the phones is assigned' do
291
+ let(:phones) { [] }
292
+ let(:company) { super().merge({ phones: phones }) }
293
+ let(:node) { super().at_css('> phones') }
294
+
295
+ include_examples 'when phones is assigned'
296
+ end
297
+
298
+ context 'when the partner is assigned' do
299
+ let(:partner) { {} }
300
+ let(:company) { super().merge({ partner: partner }) }
301
+ let(:node) { super().at_css('> partner') }
302
+
303
+ it 'can have a name' do
304
+ partner[:name] = 'Antonio Carlos'
305
+ expect( node.at_css('> name').text ).to eq 'Antonio Carlos'
306
+ end
307
+
308
+ it 'can have a birth date' do
309
+ partner[:birth_date] = Date.new(1982, 2, 5)
310
+ expect( node.at_css('> birthDate').text ).to eq '1982-02-05'
311
+ end
312
+
313
+ context 'when the documents is assigned' do
314
+ let(:documents) { [] }
315
+ let(:partner) { super().merge({ documents: documents }) }
316
+ let(:node) { super().at_css('> documents') }
317
+
318
+ include_examples 'when documents is assigned'
319
+ end
320
+ end
321
+ end
322
+ end
23
323
  end