mymoip 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,249 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestPayer < Test::Unit::TestCase
4
+ def test_getters_for_attributes
5
+ payer = MyMoip::Payer.new(
6
+ id: "some id",
7
+ name: "some name",
8
+ email: "some email",
9
+ address_street: "some address_street",
10
+ address_street_number: "some address_street_number",
11
+ address_street_extra: "some address_street_extra",
12
+ address_neighbourhood: "some address_neighbourhood",
13
+ address_city: "some address_city",
14
+ address_state: "RS",
15
+ address_country: "BRA",
16
+ address_cep: "92123456",
17
+ address_phone: "5130405060"
18
+ )
19
+
20
+ assert_equal "some id", payer.id
21
+ assert_equal "some name", payer.name
22
+ assert_equal "some email", payer.email
23
+ assert_equal "some address_street", payer.address_street
24
+ assert_equal "some address_street_number", payer.address_street_number
25
+ assert_equal "some address_street_extra", payer.address_street_extra
26
+ assert_equal "some address_neighbourhood", payer.address_neighbourhood
27
+ assert_equal "some address_city", payer.address_city
28
+ assert_equal "RS", payer.address_state
29
+ assert_equal "BRA", payer.address_country
30
+ assert_equal "92123456", payer.address_cep
31
+ assert_equal "5130405060", payer.address_phone
32
+ end
33
+
34
+ def test_initialization_and_setters_with_string_keys
35
+ payer = MyMoip::Payer.new(
36
+ 'id' => 'some id',
37
+ 'name' => 'some name',
38
+ 'email' => 'some email',
39
+ 'address_street' => 'some address_street',
40
+ 'address_street_number' => 'some address_street_number',
41
+ 'address_street_extra' => 'some address_street_extra',
42
+ 'address_neighbourhood' => 'some address_neighbourhood',
43
+ 'address_city' => 'some address_city',
44
+ 'address_state' => 'RS',
45
+ 'address_country' => 'BRA',
46
+ 'address_cep' => '92123456',
47
+ 'address_phone' => '5130405060'
48
+ )
49
+
50
+ assert_equal "some id", payer.id
51
+ assert_equal "some name", payer.name
52
+ assert_equal "some email", payer.email
53
+ assert_equal "some address_street", payer.address_street
54
+ assert_equal "some address_street_number", payer.address_street_number
55
+ assert_equal "some address_street_extra", payer.address_street_extra
56
+ assert_equal "some address_neighbourhood", payer.address_neighbourhood
57
+ assert_equal "some address_city", payer.address_city
58
+ assert_equal "RS", payer.address_state
59
+ assert_equal "BRA", payer.address_country
60
+ assert_equal "92123456", payer.address_cep
61
+ assert_equal "5130405060", payer.address_phone
62
+ end
63
+
64
+ def test_validate_presence_of_id_attribute
65
+ subject = Fixture.payer
66
+ subject.id = nil
67
+ assert subject.invalid?, 'should be invalid without an id'
68
+ subject.id = ''
69
+ assert subject.invalid?, 'should be invalid without an id'
70
+ end
71
+
72
+ def test_validate_presence_of_name_attribute
73
+ subject = Fixture.payer
74
+ subject.name = nil
75
+ assert subject.invalid?, 'should be invalid without an name'
76
+ subject.name = ''
77
+ assert subject.invalid?, 'should be invalid without an name'
78
+ end
79
+
80
+ def test_validate_presence_of_email_attribute
81
+ subject = Fixture.payer
82
+ subject.email = nil
83
+ assert subject.invalid?, 'should be invalid without an email'
84
+ subject.email = ''
85
+ assert subject.invalid?, 'should be invalid without an email'
86
+ end
87
+
88
+ def test_validate_presence_of_address_street_attribute
89
+ subject = Fixture.payer
90
+ subject.address_street = nil
91
+ assert subject.invalid?, 'should be invalid without an address_street'
92
+ subject.address_street = ''
93
+ assert subject.invalid?, 'should be invalid without an address_street'
94
+ end
95
+
96
+ def test_validate_presence_of_address_street_number_attribute
97
+ subject = Fixture.payer
98
+ subject.address_street_number = nil
99
+ assert subject.invalid?, 'should be invalid without an address_street_number'
100
+ subject.address_street_number = ''
101
+ assert subject.invalid?, 'should be invalid without an address_street_number'
102
+ end
103
+
104
+ def test_validate_presence_of_address_neighbourhood_attribute
105
+ subject = Fixture.payer
106
+ subject.address_neighbourhood = nil
107
+ assert subject.invalid?, 'should be invalid without an address_neighbourhood'
108
+ subject.address_neighbourhood = ''
109
+ assert subject.invalid?, 'should be invalid without an address_neighbourhood'
110
+ end
111
+
112
+ def test_validate_presence_of_address_city_attribute
113
+ subject = Fixture.payer
114
+ subject.address_city = nil
115
+ assert subject.invalid?, 'should be invalid without an address_city'
116
+ subject.address_city = ''
117
+ assert subject.invalid?, 'should be invalid without an address_city'
118
+ end
119
+
120
+ def test_validate_presence_of_address_state_attribute
121
+ subject = Fixture.payer
122
+ subject.address_state = nil
123
+ assert subject.invalid?, 'should be invalid without an address_state'
124
+ subject.address_state = ''
125
+ assert subject.invalid?, 'should be invalid without an address_state'
126
+ end
127
+
128
+ def test_validate_length_of_address_state_attribute_in_2_chars
129
+ subject = Fixture.payer
130
+ subject.address_state = 'RS'
131
+ assert subject.valid?, 'should accept 2 chars'
132
+ subject.address_state = 'RSS'
133
+ assert subject.invalid? && subject.errors[:address_state].present?,
134
+ 'should not accept strings with other than 2 chars'
135
+ end
136
+
137
+ def test_upcase_assigned_address_state
138
+ subject = Fixture.payer
139
+ subject.address_state = 'rs'
140
+ assert_equal 'RS', subject.address_state
141
+ end
142
+
143
+ def test_validate_presence_of_address_country_attribute
144
+ subject = Fixture.payer
145
+ subject.address_country = nil
146
+ assert subject.invalid?, 'should be invalid without an address_country'
147
+ subject.address_country = ''
148
+ assert subject.invalid?, 'should be invalid without an address_country'
149
+ end
150
+
151
+ def test_validate_length_of_address_country_attribute_in_3_chars
152
+ subject = Fixture.payer
153
+ subject.address_country = 'BRA'
154
+ assert subject.valid?, 'should accept 3 chars'
155
+ subject.address_country = 'BR'
156
+ assert subject.invalid? && subject.errors[:address_country].present?,
157
+ 'should not accept strings with other than 3 chars'
158
+ end
159
+
160
+ def test_upcase_assigned_address_country
161
+ subject = Fixture.payer
162
+ subject.address_country = 'bra'
163
+ assert_equal 'BRA', subject.address_country
164
+ end
165
+
166
+ def test_validate_presence_of_address_cep_attribute
167
+ subject = Fixture.payer
168
+ subject.address_cep = nil
169
+ assert subject.invalid?, 'should be invalid without an address_cep'
170
+ subject.address_cep = ''
171
+ assert subject.invalid?, 'should be invalid without an address_cep'
172
+ end
173
+
174
+ def test_validate_length_of_address_cep_attribute_in_2_chars
175
+ subject = Fixture.payer
176
+ subject.address_cep = '92123456'
177
+ assert subject.valid?, 'should accept 8 chars'
178
+ subject.address_cep = '921234560000'
179
+ assert subject.invalid? && subject.errors[:address_cep].present?,
180
+ 'should not accept strings with other than 8 chars'
181
+ end
182
+
183
+ def test_dont_count_dashes_in_the_address_cep_length_validation
184
+ subject = Fixture.payer
185
+ subject.address_cep = '92123-456'
186
+ assert subject.valid?
187
+ end
188
+
189
+ def test_remove_dashes_from_address_cep
190
+ subject = Fixture.payer
191
+ subject.address_cep = '92123-456'
192
+ assert_equal '92123456', subject.address_cep
193
+ end
194
+
195
+ def test_validate_presence_of_address_phone_attribute
196
+ subject = Fixture.payer
197
+ subject.address_phone = nil
198
+ assert subject.invalid?, 'should be invalid without an address_phone'
199
+ subject.address_phone = ''
200
+ assert subject.invalid?, 'should be invalid without an address_phone'
201
+ end
202
+
203
+ def test_validate_length_of_address_phone_attribute_in_10_or_11_chars
204
+ subject = Fixture.payer
205
+ subject.address_phone = '5130405060'
206
+ assert subject.valid?, 'should accept 10 chars'
207
+ subject.address_phone = '51930405060'
208
+ assert subject.valid?, 'should accept 11 chars'
209
+ subject.address_phone = '215130405060'
210
+ assert subject.invalid? && subject.errors[:address_phone].present?,
211
+ 'should not accept strings with other than 10 or 11 chars'
212
+ end
213
+
214
+ def test_remove_left_zeros_from_address_phone
215
+ subject = Fixture.payer
216
+ subject.address_phone = '05130405060'
217
+ assert_equal '5130405060', subject.address_phone
218
+ end
219
+
220
+ def test_remove_dashes_from_address_phone
221
+ subject = Fixture.payer
222
+ subject.address_phone = '513040-5060'
223
+ assert_equal '5130405060', subject.address_phone
224
+ subject.address_phone = '5193040-5060'
225
+ assert_equal '51930405060', subject.address_phone
226
+ end
227
+
228
+ def test_remove_parenthesis_from_address_phone
229
+ subject = Fixture.payer
230
+ subject.address_phone = '(51)30405060'
231
+ assert_equal '5130405060', subject.address_phone
232
+ subject.address_phone = '(51)930405060'
233
+ assert_equal '51930405060', subject.address_phone
234
+ end
235
+
236
+ def test_to_xml_method_uses_the_formatted_version_of_the_address_cep
237
+ subject = Fixture.payer(address_cep: '92000123')
238
+ formatter = stub_everything('formatter')
239
+ formatter.expects(:cep).with('92000123')
240
+ subject.to_xml(nil, formatter)
241
+ end
242
+
243
+ def test_to_xml_method_uses_the_formatted_version_of_the_address_phone
244
+ subject = Fixture.payer(address_phone: '5130405060')
245
+ formatter = stub_everything('formatter')
246
+ formatter.expects(:phone).with('5130405060')
247
+ subject.to_xml(nil, formatter)
248
+ end
249
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: UTF-8
2
+ require_relative '../test_helper'
3
+
4
+ class TestPaymentRequest < Test::Unit::TestCase
5
+ def test_http_method_as_get
6
+ assert_equal :get, MyMoip::PaymentRequest::HTTP_METHOD
7
+ end
8
+
9
+ def test_path
10
+ assert_equal "/rest/pagamento?callback=?", MyMoip::PaymentRequest::PATH
11
+ end
12
+
13
+ def test_non_auth_requirement
14
+ assert_equal false, MyMoip::PaymentRequest::REQUIRES_AUTH
15
+ end
16
+
17
+ def test_generate_json
18
+ HTTParty.stubs(:send).returns("<html>some_result</html>")
19
+ request = MyMoip::PaymentRequest.new("id")
20
+
21
+ JSON.expects(:generate).with(
22
+ pagamentoWidget: {
23
+ referer: "http://localhost",
24
+ token: "big_transparent_token",
25
+ dadosPagamento: {payment: "attributes"}
26
+ }
27
+ )
28
+ request_data = stub(to_json: {payment: "attributes"})
29
+ request.api_call(request_data, token: "big_transparent_token", referer_url: "http://localhost")
30
+ end
31
+
32
+ def test_gets_default_referer_if_another_isnt_passed
33
+ MyMoip.default_referer_url = "http://localhost/default"
34
+ HTTParty.stubs(:send).returns("<html>some_result</html>")
35
+ request = MyMoip::PaymentRequest.new("id")
36
+
37
+ JSON.expects(:generate).with(
38
+ pagamentoWidget: {
39
+ referer: MyMoip.default_referer_url,
40
+ token: "big_transparent_token",
41
+ dadosPagamento: {payment: "attributes"}
42
+ }
43
+ )
44
+ request_data = stub(to_json: {payment: "attributes"})
45
+ request.api_call(request_data, token: "big_transparent_token")
46
+ end
47
+
48
+ def test_successful_status
49
+ MyMoip.default_referer_url = "http://localhost/default"
50
+ HTTParty.stubs(:send).returns(
51
+ JSON.parse '{"Status":"EmAnalise","Codigo":0,"CodigoRetorno":"","TaxaMoIP":"7.79","StatusPagamento":"Sucesso","Classificacao":{"Codigo":999,"Descricao":"Não suportado no ambiente Sandbox"},"CodigoMoIP":77316,"Mensagem":"Requisição processada com sucesso","TotalPago":"100.00"}'
52
+ )
53
+ request = MyMoip::PaymentRequest.new("id")
54
+
55
+ request_data = stub(to_json: {payment: "attributes"})
56
+ request.api_call(request_data, token: "big_transparent_token")
57
+ assert request.success?
58
+ end
59
+
60
+ def test_success_method_returns_false_in_payments_already_made
61
+ MyMoip.default_referer_url = "http://localhost/default"
62
+ HTTParty.stubs(:send).returns(
63
+ JSON.parse '{"Codigo":236,"StatusPagamento":"Falha","Mensagem":"Pagamento já foi realizado"}'
64
+ )
65
+ request = MyMoip::PaymentRequest.new("id")
66
+
67
+ request_data = stub(to_json: {payment: "attributes"})
68
+ request.api_call(request_data, token: "big_transparent_token")
69
+ assert !request.success?
70
+ end
71
+
72
+ def test_method_to_get_moip_code
73
+ instruction = Fixture.instruction(payer: Fixture.payer)
74
+ transparent_request = MyMoip::TransparentRequest.new("your_own_id")
75
+ VCR.use_cassette('transparent_request') do
76
+ transparent_request.api_call(instruction)
77
+ end
78
+ credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, 1)
79
+ payment_request = MyMoip::PaymentRequest.new("your_own_id")
80
+ VCR.use_cassette('payment_request') do
81
+ payment_request.api_call(credit_card_payment, token: transparent_request.token)
82
+ end
83
+ assert_equal 102596, payment_request.code
84
+ end
85
+
86
+ def test_code_method_should_return_nil_with_blank_response
87
+ instruction = Fixture.instruction(payer: Fixture.payer)
88
+ transparent_request = MyMoip::TransparentRequest.new("your_own_id")
89
+ VCR.use_cassette('transparent_request') do
90
+ transparent_request.api_call(instruction)
91
+ end
92
+ credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, 1)
93
+ payment_request = MyMoip::PaymentRequest.new("your_own_id")
94
+ assert_nil payment_request.code
95
+ end
96
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../test_helper'
2
+
3
+ def cc_attrs(attrs = {})
4
+ {
5
+ logo: :visa,
6
+ card_number: '4916654211627608',
7
+ expiration_date: '06/15',
8
+ security_code: '000',
9
+ owner_name: 'Juquinha da Rocha',
10
+ owner_birthday: '03/11/1980',
11
+ owner_phone: '5130405060',
12
+ owner_cpf: '52211670695'
13
+ }.merge(attrs)
14
+ end
15
+
16
+ def payer_attrs(attrs = {})
17
+ {
18
+ id: rand,
19
+ name: 'Juquinha da Rocha',
20
+ email: 'juquinha@rocha.com',
21
+ address_street: 'Felipe Neri',
22
+ address_street_number: '406',
23
+ address_street_extra: 'Sala 501',
24
+ address_neighbourhood: 'Auxiliadora',
25
+ address_city: 'Porto Alegre',
26
+ address_state: 'RS',
27
+ address_country: 'BRA',
28
+ address_cep: '90440150',
29
+ address_phone: '5130405060'
30
+ }.merge(attrs)
31
+ end
32
+
33
+ class TestPurchase < Test::Unit::TestCase
34
+ def setup
35
+ MyMoip::Request.any_instance.stubs(:api_call)
36
+ MyMoip::PaymentRequest.any_instance.stubs(:api_call)
37
+ MyMoip::TransparentRequest.any_instance.stubs(:api_call)
38
+ end
39
+
40
+ def subject
41
+ MyMoip::Purchase.new(id: '42',
42
+ price: 400,
43
+ reason: 'Payment of my product',
44
+ credit_card: cc_attrs,
45
+ payer: payer_attrs)
46
+ end
47
+
48
+ def test_new_objects_stores_already_initialized_instance_of_credit_ard
49
+ assert subject.credit_card.kind_of?(MyMoip::CreditCard)
50
+ end
51
+
52
+ def test_new_objects_stores_already_initialized_instance_of_payer
53
+ assert subject.payer.kind_of?(MyMoip::Payer)
54
+ end
55
+
56
+ def test_checkout_uses_initialized_id_for_logging
57
+ MyMoip::PaymentRequest.expects(:new).
58
+ with('42').
59
+ returns(stub_everything)
60
+ subject.checkout!
61
+ end
62
+
63
+ def test_checkout_instruction_uses_a_generated_id_for_instruction
64
+ MyMoip::Instruction.expects(:new).
65
+ with(has_entry(id: subject.id)).
66
+ returns(stub_everything)
67
+ subject.checkout!
68
+ end
69
+
70
+ def test_checkout_instruction_uses_initialized_reason
71
+ MyMoip::Instruction.expects(:new).
72
+ with(has_entry(payment_reason: 'Payment of my product')).
73
+ returns(stub_everything)
74
+ subject.checkout!
75
+ end
76
+
77
+ def test_checkout_instruction_uses_initialized_price
78
+ MyMoip::Instruction.expects(:new).
79
+ with(has_entry(values: [400.0])).
80
+ returns(stub_everything)
81
+ subject.checkout!
82
+ end
83
+
84
+ def test_checkouts_transparent_request_uses_initialized_id_for_payment_request_logging
85
+ MyMoip::TransparentRequest.expects(:new).
86
+ with('42').
87
+ returns(stub_everything)
88
+ subject.checkout!
89
+ end
90
+
91
+ def test_checkouts_transparent_request_confirm_request_with_authorized_token
92
+ MyMoip::Purchase.any_instance.stubs(:get_authorization!).
93
+ returns(stub('MyMoip request', token: 'abc'))
94
+
95
+ MyMoip::PaymentRequest.any_instance.expects(:api_call).
96
+ with(anything, has_entry(token: 'abc')).
97
+ returns(stub_everything)
98
+ subject.checkout!
99
+ end
100
+
101
+ def test_checkouts_transparent_request_assigns_its_code
102
+ MyMoip::PaymentRequest.any_instance.stubs(:success?).returns(true)
103
+ MyMoip::PaymentRequest.any_instance.stubs(:code).returns('foo_bar')
104
+ purchase = subject
105
+ purchase.checkout!
106
+
107
+ assert_equal 'foo_bar', purchase.code
108
+ end
109
+ end
@@ -0,0 +1,88 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestRequest < Test::Unit::TestCase
4
+ def setup
5
+ @default_environment = MyMoip.environment
6
+ @default_key = MyMoip.key
7
+ @default_token = MyMoip.token
8
+ @default_logger = MyMoip.logger
9
+ end
10
+
11
+ def teardown
12
+ MyMoip.environment = @default_environment
13
+ MyMoip.key = @default_key
14
+ MyMoip.token = @default_token
15
+ MyMoip.logger = @default_logger
16
+ end
17
+
18
+ def test_initializes_receiving_data_and_optional_id
19
+ request = MyMoip::Request.new("request_id")
20
+ assert_equal "request_id", request.id
21
+ end
22
+
23
+ def test_logs_api_call_method_in_info_level
24
+ logger = stub_everything
25
+ request = MyMoip::Request.new("request_id")
26
+ params = {
27
+ http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
28
+ }
29
+
30
+ HTTParty.stubs(:send).returns("<html>some_result</html>")
31
+ logger.expects(:info).at_least_once.
32
+ with(regexp_matches(/being sent to MoIP/))
33
+
34
+ request.api_call(params, logger: logger)
35
+ end
36
+
37
+ def test_logs_api_call_method_parameters_in_debug_level
38
+ logger = stub_everything
39
+ request = MyMoip::Request.new("request_id")
40
+ params = {
41
+ http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
42
+ }
43
+
44
+ HTTParty.stubs(:send).returns("<html>some_result</html>")
45
+ logger.expects(:debug).at_least_once.
46
+ with(regexp_matches(/request_id.+<pretty><xml><\/xml><\/pretty>/))
47
+
48
+ request.api_call(params, logger: logger)
49
+ end
50
+
51
+ def test_logs_api_call_response_in_debug_level
52
+ logger = stub_everything
53
+ request = MyMoip::Request.new("request_id")
54
+ params = {
55
+ http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
56
+ }
57
+
58
+ HTTParty.stubs(:send).returns("<html>some_result</html>")
59
+ logger.expects(:debug).at_least_once.
60
+ with(regexp_matches(/request_id.+<html>some_result<\/html>/))
61
+
62
+ request.api_call(params, logger: logger)
63
+ end
64
+
65
+ def test_raises_error_before_api_calls_without_a_key_set
66
+ subject = MyMoip::Request.new('request_id')
67
+ MyMoip.sandbox_key = nil
68
+ assert_raises StandardError do
69
+ subject.api_call({})
70
+ end
71
+ MyMoip.sandbox_key = ''
72
+ assert_raises StandardError do
73
+ subject.api_call({})
74
+ end
75
+ end
76
+
77
+ def test_raises_error_before_api_calls_without_a_token_set
78
+ subject = MyMoip::Request.new('request_id')
79
+ MyMoip.sandbox_token = nil
80
+ assert_raises StandardError do
81
+ subject.api_call({})
82
+ end
83
+ MyMoip.sandbox_token = ''
84
+ assert_raises StandardError do
85
+ subject.api_call({})
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,71 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestTransparentRequest < Test::Unit::TestCase
4
+ def test_http_method_as_post
5
+ assert_equal :post, MyMoip::TransparentRequest::HTTP_METHOD
6
+ end
7
+
8
+ def test_path
9
+ assert_equal "/ws/alpha/EnviarInstrucao/Unica", MyMoip::TransparentRequest::PATH
10
+ end
11
+
12
+ def test_auth_requirement
13
+ assert_equal true, MyMoip::TransparentRequest::REQUIRES_AUTH
14
+ end
15
+
16
+ def test_success_method_with_valid_json
17
+ HTTParty.stubs(:send).returns(
18
+ {"EnviarInstrucaoUnicaResponse"=>{"xmlns:ns1"=>"http://www.moip.com.br/ws/alpha/", "Resposta"=>{"ID"=>"201208081614306080000000928569", "Status"=>"Sucesso", "Token"=>"G290E1H230N8L0M8J1K6F1F4B3T0N610K8B0S0H0I0T0T0E029Y2R8H5Y6H9"}}}
19
+ )
20
+ request = MyMoip::TransparentRequest.new("some_id")
21
+ request_data = stub(to_xml: "<anydata></anydata>")
22
+ request.api_call request_data
23
+ assert request.success?
24
+ end
25
+
26
+ def test_success_method_with_failed_response
27
+ HTTParty.stubs(:send).returns(
28
+ {"EnviarInstrucaoUnicaResponse"=>{"xmlns:ns1"=>"http://www.moip.com.br/ws/alpha/", "Resposta"=>{"Status"=>"Falha"}}}
29
+ )
30
+ request = MyMoip::TransparentRequest.new("some_id")
31
+ request_data = stub(to_xml: "<anydata></anydata>")
32
+ request.api_call request_data
33
+ assert !request.success?
34
+ end
35
+
36
+ def test_success_method_with_requests_that_hasnt_be_made
37
+ request = MyMoip::TransparentRequest.new("some_id")
38
+ assert !request.success?
39
+ end
40
+
41
+ def test_provides_token_when_has_a_valid_response
42
+ HTTParty.stubs(:send).returns(
43
+ {"EnviarInstrucaoUnicaResponse"=>{"xmlns:ns1"=>"http://www.moip.com.br/ws/alpha/", "Resposta"=>{"ID"=>"201208081614306080000000928569", "Status"=>"Sucesso", "Token"=>"token"}}}
44
+ )
45
+ request = MyMoip::TransparentRequest.new("some_id")
46
+ request_data = stub(to_xml: "<anydata></anydata>")
47
+ request.api_call request_data
48
+ assert_equal "token", request.token
49
+ end
50
+
51
+ def test_provides_token_with_requests_that_hasnt_be_made
52
+ request = MyMoip::TransparentRequest.new("some_id")
53
+ assert_equal nil, request.token
54
+ end
55
+
56
+ def test_should_provide_the_transaction_id_get_by_the_request
57
+ request = MyMoip::TransparentRequest.new("some_id")
58
+ VCR.use_cassette('transparent_request') do
59
+ request.api_call(Fixture.instruction(payer: Fixture.payer))
60
+ end
61
+ assert_equal "201210171118501100000001102691", request.id
62
+ end
63
+
64
+ def test_should_provide_the_transaction_id_get_by_the_request_with_commissions_feature
65
+ request = MyMoip::TransparentRequest.new("some_id")
66
+ VCR.use_cassette('transparent_request_with_commissions') do
67
+ request.api_call Fixture.instruction(commissions: [Fixture.commission])
68
+ end
69
+ assert_equal "YOUR_REQUEST_ID", request.id
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'mocha/setup'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ require_relative 'live_test'
11
+ require_relative 'fixtures/fixture'
12
+ Dir[File.dirname(__FILE__) + "/lib/*.rb"].each { |file| require file }
13
+
14
+ MyMoip.sandbox_key = 'YOUR_MOIP_KEY'
15
+ MyMoip.sandbox_token = 'YOUR_MOIP_TOKEN'
16
+ MyMoip.logger = Logger.new('/dev/null')
17
+ $VERBOSE = nil