mymoip 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,114 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCreditCardPayment < Test::Unit::TestCase
4
- def test_initialization_and_getters
5
- credit_card = Fixture.credit_card
6
- subject = MyMoip::CreditCardPayment.new(credit_card, 1)
7
- assert_equal credit_card, subject.credit_card
8
- assert_equal 1, subject.installments
9
- end
10
-
11
- def test_allow_initialization_with_a_hash_of_options
12
- credit_card = Fixture.credit_card
13
- subject = MyMoip::CreditCardPayment.new(credit_card, installments: 2)
14
- assert_equal credit_card, subject.credit_card
15
- assert_equal 2, subject.installments
16
- end
17
-
18
- def test_cash_method_with_one_tranch
19
- credit_card = Fixture.credit_card
20
- subject = MyMoip::CreditCardPayment.new(credit_card, 1)
21
- assert_equal true, subject.cash?
22
- end
23
-
24
- def test_cash_method_with_more_than_one_installments
25
- credit_card = Fixture.credit_card
26
- subject = MyMoip::CreditCardPayment.new(credit_card, 3)
27
- assert_equal false, subject.cash?
28
- end
29
-
30
- def test_default_initialization_with_one_tranch
31
- credit_card = Fixture.credit_card
32
- subject = MyMoip::CreditCardPayment.new(credit_card)
33
- assert_equal 1, subject.installments
34
- end
35
-
36
- def test_json_format
37
- payment = MyMoip::CreditCardPayment.new(Fixture.credit_card)
38
- assert_equal "CartaoCredito", payment.to_json[:Forma]
39
- assert payment.to_json[:Parcelas].kind_of?(Integer), "'Parcelas' must be a kind of integer."
40
- end
41
-
42
- def test_json_credit_card_format
43
- payment = MyMoip::CreditCardPayment.new(Fixture.credit_card)
44
- assert_match /\A\d+\z/, payment.to_json[:CartaoCredito][:Numero]
45
- assert_match /\A((0[1-9])|(1[02]))\/\d{2}\z/, payment.to_json[:CartaoCredito][:Expiracao]
46
- assert_match /\A\d{3}\z/, payment.to_json[:CartaoCredito][:CodigoSeguranca]
47
- original_date = Date.new(1980, 11, 3)
48
- MyMoip::Formatter.stubs(:date).returns('03/11/1980')
49
- assert_equal '03/11/1980', payment.to_json[:CartaoCredito][:Portador][:DataNascimento]
50
- assert_match /\A\(\d{2}\)\d{4,5}-\d{4}/, payment.to_json[:CartaoCredito][:Portador][:Telefone]
51
- assert_match /\A\d{3}\.\d{3}\.\d{3}\-\d{2}\z/, payment.to_json[:CartaoCredito][:Portador][:Identidade]
52
- end
53
-
54
- def test_to_json_should_accept_any_creditcard_from_available_logos_constant
55
- MyMoip::CreditCard::AVAILABLE_LOGOS.each do |logo|
56
- payment = MyMoip::CreditCardPayment.new(Fixture.credit_card(logo: logo))
57
- assert_nothing_raised(KeyError) { payment.to_json }
58
- end
59
- end
60
-
61
- def test_to_json_method_uses_the_formatted_version_of_the_credit_cards_owner_birthday
62
- date = Date.new(2040, 10, 30)
63
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card(owner_birthday: date))
64
- formatter = stub_everything('formatter')
65
- formatter.expects(:date).with(date)
66
- subject.to_json(formatter)
67
- end
68
-
69
- def test_to_json_method_skip_formatting_when_credit_cards_owner_birthday_is_nil
70
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card(owner_birthday: nil))
71
- formatter = stub_everything('formatter')
72
- formatter.stubs(:date).with(nil).returns('should not be here')
73
- json = subject.to_json(formatter)
74
- assert_nil json[:CartaoCredito][:Portador][:DataNascimento]
75
- end
76
-
77
- def test_to_json_method_uses_the_formatted_version_of_the_credit_cards_owner_phone
78
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card(owner_phone: '5130405060'))
79
- formatter = stub_everything('formatter')
80
- formatter.expects(:phone).with('5130405060')
81
- subject.to_json(formatter)
82
- end
83
-
84
- def test_to_json_method_skip_formatting_when_credit_cards_owner_phone_is_nil
85
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card(owner_phone: nil))
86
- formatter = stub_everything('formatter')
87
- formatter.stubs(:phone).with(nil).returns('should not be here')
88
- json = subject.to_json(formatter)
89
- assert_nil json[:CartaoCredito][:Portador][:Telefone]
90
- end
91
-
92
- def test_to_json_method_raises_an_exception_when_called_without_a_credit_card
93
- subject = MyMoip::CreditCardPayment.new(nil)
94
- assert_raise MyMoip::InvalidCreditCard do
95
- subject.to_json
96
- end
97
- end
98
-
99
- def test_to_json_method_skip_formatting_when_credit_cards_owner_cpf_is_nil
100
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card(owner_cpf: nil))
101
- formatter = stub_everything('formatter')
102
- formatter.stubs(:cpf).with(nil).returns('should not be here')
103
- json = subject.to_json(formatter)
104
- assert_nil json[:CartaoCredito][:Portador][:Identidade]
105
- end
106
-
107
- def test_to_json_method_raises_an_exception_when_called_with_a_invalid_credit_card
108
- subject = MyMoip::CreditCardPayment.new(Fixture.credit_card)
109
- MyMoip::CreditCard.any_instance.stubs(:invalid?).returns(true)
110
- assert_raise MyMoip::InvalidCreditCard do
111
- subject.to_json
112
- end
113
- end
114
- end
@@ -1,150 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCreditCard < Test::Unit::TestCase
4
- def test_initialization_and_setters
5
- subject = MyMoip::CreditCard.new(
6
- logo: :visa,
7
- card_number: "4916654211627608",
8
- expiration_date: "06/15",
9
- security_code: "000",
10
- owner_name: "Juquinha da Rocha",
11
- owner_birthday: Date.new(1984, 11, 3),
12
- owner_phone: "5130405060",
13
- owner_cpf: "522.116.706-95"
14
- )
15
-
16
- assert_equal :visa, subject.logo
17
- assert_equal "4916654211627608", subject.card_number
18
- assert_equal "06/15", subject.expiration_date
19
- assert_equal "000", subject.security_code
20
- assert_equal "Juquinha da Rocha", subject.owner_name
21
- assert_equal Date.new(1984, 11, 3), subject.owner_birthday
22
- assert_equal "5130405060", subject.owner_phone
23
- assert_equal "52211670695", subject.owner_cpf
24
- end
25
-
26
- def test_validate_presence_of_logo_attribute
27
- subject = Fixture.credit_card
28
- subject.logo = nil
29
- assert subject.invalid? && subject.errors[:logo].present?,
30
- 'should be invalid without a logo'
31
- end
32
-
33
- def test_owner_birthday_accepts_string_version_of_dates
34
- subject = Fixture.credit_card
35
- subject.owner_birthday = '20/12/1980'
36
- assert_equal Date.new(1980, 12, 20), subject.owner_birthday
37
- end
38
-
39
- def test_validate_presence_of_security_code_attribute
40
- subject = Fixture.credit_card
41
- subject.security_code = nil
42
- assert subject.invalid? && subject.errors[:security_code].present?,
43
- 'should be invalid without an security_code'
44
- end
45
-
46
- def test_accept_nil_owner_phone
47
- subject = Fixture.credit_card(owner_phone: nil)
48
- assert subject.valid?, 'should be valid'
49
- end
50
-
51
- def test_validate_length_of_owner_phone_attribute_in_10_or_11_chars
52
- subject = Fixture.credit_card
53
- subject.owner_phone = '5130405060'
54
- assert subject.valid?, 'should accept 10 chars'
55
- subject.owner_phone = '51930405060'
56
- assert subject.valid?, 'should accept 11 chars'
57
- subject.owner_phone = '215130405060'
58
- assert subject.invalid? && subject.errors[:owner_phone].present?,
59
- 'should not accept strings with other than 10 or 11 chars'
60
- end
61
-
62
- def test_remove_left_zeros_from_owner_phone
63
- subject = Fixture.credit_card
64
- subject.owner_phone = '05130405060'
65
- assert_equal '5130405060', subject.owner_phone
66
- end
67
-
68
- def test_remove_dashes_from_owner_phone
69
- subject = Fixture.credit_card
70
- subject.owner_phone = '513040-5060'
71
- assert_equal '5130405060', subject.owner_phone
72
- subject.owner_phone = '5193040-5060'
73
- assert_equal '51930405060', subject.owner_phone
74
- end
75
-
76
- def test_remove_parenthesis_from_owner_phone
77
- subject = Fixture.credit_card
78
- subject.owner_phone = '(51)30405060'
79
- assert_equal '5130405060', subject.owner_phone
80
- subject.owner_phone = '(51)930405060'
81
- assert_equal '51930405060', subject.owner_phone
82
- end
83
-
84
- def test_remove_dashes_from_owner_cpf
85
- subject = Fixture.credit_card
86
- subject.owner_cpf = '522116706-95'
87
- assert_equal '52211670695', subject.owner_cpf
88
- end
89
-
90
- def test_remove_dots_from_owner_cpf
91
- subject = Fixture.credit_card
92
- subject.owner_cpf = '522.116.70695'
93
- assert_equal '52211670695', subject.owner_cpf
94
- end
95
-
96
- def test_accept_nil_owner_cpf
97
- subject = Fixture.credit_card(owner_cpf: nil)
98
- assert subject.valid?, 'should be valid'
99
- end
100
-
101
- def test_warns_about_owner_rg_attribute_deprecation_on_initialization
102
- MyMoip::CreditCard.any_instance.expects(:warn).with(regexp_matches(/is deprecated/))
103
- subject = Fixture.credit_card(owner_rg: '1010202030')
104
- end
105
-
106
- def test_warns_about_owner_rg_attribute_deprecation_on_setter
107
- subject = Fixture.credit_card
108
- subject.expects(:warn).with(regexp_matches(/is deprecated/))
109
- subject.owner_rg = '1010202030'
110
- end
111
-
112
- def test_accepts_security_codes_of_3_digits
113
- subject = Fixture.credit_card(security_code: "180")
114
- assert subject.valid?, 'should be valid'
115
- end
116
-
117
- def test_accepts_security_codes_of_4_digits
118
- subject = Fixture.credit_card(security_code: "1809")
119
- assert subject.valid?, 'should be valid'
120
- end
121
-
122
- def test_dont_accept_security_codes_of_neither_3_or_4_digits
123
- subject = Fixture.credit_card(security_code: "1")
124
- assert subject.invalid? && subject.errors[:security_code].present?, 'should not be valid'
125
- end
126
-
127
- def test_validate_format_of_expiration_date
128
- subject = Fixture.credit_card(expiration_date: "12/2018")
129
- assert subject.invalid? && subject.errors[:expiration_date].present?, 'should not accept other formats'
130
- subject = Fixture.credit_card(expiration_date: "12/18")
131
- assert subject.valid? && subject.errors[:expiration_date].empty?, 'should accept "%m/%y" format'
132
- end
133
-
134
- def test_converts_creditcard_string_logos_to_symbol
135
- subject = Fixture.credit_card(logo: "visa")
136
- assert_equal :visa, subject.logo
137
- end
138
-
139
- def test_accepts_any_creditcard_from_available_logos_constant
140
- MyMoip::CreditCard::AVAILABLE_LOGOS.each do |logo|
141
- subject = Fixture.credit_card(logo: logo)
142
- assert subject.valid?, 'should be valid'
143
- end
144
- end
145
-
146
- def test_dont_accept_logos_out_of_available_logos_constant
147
- subject = Fixture.credit_card(logo: :unavailable_card)
148
- assert subject.invalid? && subject.errors[:logo].present?, 'should not be valid'
149
- end
150
- end
@@ -1,49 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFormatter < Test::Unit::TestCase
4
- def test_cep_method_returns_the_given_cep_with_section_separator
5
- assert_equal '92400-123', MyMoip::Formatter.cep('92400123')
6
- end
7
-
8
- def test_cep_method_raises_exception_with_nil_cep_given
9
- assert_raise ArgumentError do
10
- MyMoip::Formatter.cep(nil)
11
- end
12
- end
13
-
14
- def test_phone_method_returns_the_given_8_digit_phone_with_section_separators
15
- assert_equal '(51)3040-5060', MyMoip::Formatter.phone('5130405060')
16
- end
17
-
18
- def test_phone_method_returns_the_given_9_digit_phone_with_section_separators
19
- assert_equal '(51)93040-5060', MyMoip::Formatter.phone('51930405060')
20
- end
21
-
22
- def test_phone_method_raises_exception_with_nil_phone_given
23
- assert_raise ArgumentError do
24
- MyMoip::Formatter.phone(nil)
25
- end
26
- end
27
-
28
- def test_date_method_returns_the_given_date_in_the_format_expected
29
- date = Date.new(2040, 10, 30)
30
- assert_equal '30/10/2040', MyMoip::Formatter.date(date)
31
- end
32
-
33
- def test_date_method_raises_exception_with_nil_date_given
34
- assert_raise ArgumentError do
35
- MyMoip::Formatter.date(nil)
36
- end
37
- end
38
-
39
- def test_cpf_method_returns_the_given_number_with_section_separators
40
- cpf = '522.116.706-95'
41
- assert_equal '522.116.706-95', MyMoip::Formatter.cpf('52211670695')
42
- end
43
-
44
- def test_cpf_method_raises_exception_with_nil_cpf_given
45
- assert_raise ArgumentError do
46
- MyMoip::Formatter.cpf(nil)
47
- end
48
- end
49
- end
@@ -1,217 +0,0 @@
1
- require 'helper'
2
-
3
- class TestInstruction < Test::Unit::TestCase
4
- def test_getters_for_attributes
5
- payer = Fixture.payer
6
- commissions = [Fixture.commission]
7
- installments = [{min: 2, max: 12, forward_taxes: true, fee: 1.99}]
8
- instruction = MyMoip::Instruction.new(
9
- id: "some id",
10
- payment_reason: "some payment_reason",
11
- values: [100.0, 200.0],
12
- payer: payer,
13
- commissions: commissions,
14
- fee_payer_login: "fee_payer_login",
15
- payment_receiver_login: "payment_receiver_login",
16
- payment_receiver_name: "nick_fury",
17
- installments: installments
18
- )
19
-
20
- assert_equal "some id", instruction.id
21
- assert_equal "some payment_reason", instruction.payment_reason
22
- assert_equal [100.0, 200.0], instruction.values
23
- assert_equal payer, instruction.payer
24
- assert_equal commissions, instruction.commissions
25
- assert_equal installments, instruction.installments
26
- assert_equal "fee_payer_login", instruction.fee_payer_login
27
- assert_equal "payment_receiver_login", instruction.payment_receiver_login
28
- assert_equal "nick_fury", instruction.payment_receiver_name
29
- end
30
-
31
- def test_should_generate_a_string_when_converting_to_xml
32
- payer = Fixture.payer
33
- instruction = Fixture.instruction(payer: payer)
34
-
35
- assert_equal String, instruction.to_xml.class
36
- end
37
-
38
- def test_xml_format
39
- payer = Fixture.payer
40
- instruction = Fixture.instruction(payer: payer)
41
-
42
- expected_format = <<XML
43
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Parcelamentos><Parcelamento><MinimoParcelas>2</MinimoParcelas><MaximoParcelas>12</MaximoParcelas><Repassar>true</Repassar><Juros>1.99</Juros></Parcelamento></Parcelamentos><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
44
- XML
45
- assert_equal expected_format.rstrip, instruction.to_xml
46
- end
47
-
48
- def test_xml_format_with_installments
49
- payer = Fixture.payer
50
- installments = [
51
- {min: 5, max: 10, fee: 2.99}
52
- ]
53
- instruction = Fixture.instruction(payer: payer, installments: installments)
54
-
55
- expected_format = <<XML
56
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Parcelamentos><Parcelamento><MinimoParcelas>5</MinimoParcelas><MaximoParcelas>10</MaximoParcelas><Juros>2.99</Juros></Parcelamento></Parcelamentos><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
57
- XML
58
- assert_equal expected_format.rstrip, instruction.to_xml
59
- end
60
-
61
- def test_xml_format_with_mutiple_installments
62
- payer = Fixture.payer
63
- installments = [
64
- {min: 2, max: 6, fee: 1.99},
65
- {min: 7, max: 12, fee: 2.99}
66
- ]
67
- instruction = Fixture.instruction(payer: payer, installments: installments)
68
-
69
- expected_format = <<XML
70
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Parcelamentos><Parcelamento><MinimoParcelas>2</MinimoParcelas><MaximoParcelas>6</MaximoParcelas><Juros>1.99</Juros></Parcelamento><Parcelamento><MinimoParcelas>7</MinimoParcelas><MaximoParcelas>12</MaximoParcelas><Juros>2.99</Juros></Parcelamento></Parcelamentos><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
71
- XML
72
- assert_equal expected_format.rstrip, instruction.to_xml
73
- end
74
-
75
- def test_xml_format_with_commissions
76
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(percentage_value: 0.15, fixed_value: nil)]
77
- payer = Fixture.payer
78
- instruction = Fixture.instruction(payer: payer, commissions: commissions, installments: nil)
79
- expected_format = <<XML
80
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Comissoes><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorFixo>5</ValorFixo></Comissionamento><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorPercentual>0.15</ValorPercentual></Comissionamento></Comissoes><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
81
- XML
82
- assert_equal expected_format.rstrip, instruction.to_xml
83
- end
84
-
85
- def test_xml_format_with_commissions_and_fee_payer
86
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(percentage_value: 0.15,fixed_value: nil)]
87
- payer = Fixture.payer
88
- instruction = Fixture.instruction(payer: payer, commissions: commissions, fee_payer_login: 'fee_payer_indentifier', installments: nil)
89
- expected_format = <<XML
90
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Comissoes><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorFixo>5</ValorFixo></Comissionamento><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorPercentual>0.15</ValorPercentual></Comissionamento><PagadorTaxa><LoginMoIP>fee_payer_indentifier</LoginMoIP></PagadorTaxa></Comissoes><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
91
- XML
92
- assert_equal expected_format.rstrip, instruction.to_xml
93
- end
94
-
95
- def test_xml_format_with_commissions_and_payment_receiver
96
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(percentage_value: 0.15, fixed_value: nil)]
97
- payer = Fixture.payer
98
- instruction = Fixture.instruction(payer: payer, commissions: commissions,
99
- payment_receiver_login:'payment_receiver_indentifier',
100
- payment_receiver_name: 'nick_fury', installments: nil)
101
- expected_format = <<XML
102
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Comissoes><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorFixo>5</ValorFixo></Comissionamento><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorPercentual>0.15</ValorPercentual></Comissionamento></Comissoes><Recebedor><LoginMoIP>payment_receiver_indentifier</LoginMoIP><Apelido>nick_fury</Apelido></Recebedor><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
103
- XML
104
- assert_equal expected_format.rstrip, instruction.to_xml
105
- end
106
-
107
- def test_xml_format_with_commissions_and_payment_receiver_and_fee_payer
108
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(percentage_value: 0.15, fixed_value: nil)]
109
- payer = Fixture.payer
110
- instruction = Fixture.instruction(payer: payer, commissions: commissions,
111
- payment_receiver_login:'payment_receiver_indentifier',
112
- payment_receiver_name: 'nick_fury',
113
- fee_payer_login: 'fee_payer_indentifier',
114
- installments: nil)
115
- expected_format = <<XML
116
- <EnviarInstrucao><InstrucaoUnica TipoValidacao=\"Transparente\"><Razao>some payment_reason</Razao><Valores><Valor moeda=\"BRL\">100.00</Valor><Valor moeda=\"BRL\">200.00</Valor></Valores><IdProprio>your_own_instruction_id</IdProprio><Comissoes><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorFixo>5</ValorFixo></Comissionamento><Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorPercentual>0.15</ValorPercentual></Comissionamento><PagadorTaxa><LoginMoIP>fee_payer_indentifier</LoginMoIP></PagadorTaxa></Comissoes><Recebedor><LoginMoIP>payment_receiver_indentifier</LoginMoIP><Apelido>nick_fury</Apelido></Recebedor><Pagador><Nome>Juquinha da Rocha</Nome><Email>juquinha@rocha.com</Email><IdPagador>your_own_payer_id</IdPagador><EnderecoCobranca><Logradouro>Felipe Neri</Logradouro><Numero>406</Numero><Complemento>Sala 501</Complemento><Bairro>Auxiliadora</Bairro><Cidade>Porto Alegre</Cidade><Estado>RS</Estado><Pais>BRA</Pais><CEP>90440-150</CEP><TelefoneFixo>(51)3040-5060</TelefoneFixo></EnderecoCobranca></Pagador></InstrucaoUnica></EnviarInstrucao>
117
- XML
118
- assert_equal expected_format.rstrip, instruction.to_xml
119
- end
120
-
121
- def test_to_xml_method_raises_exception_when_called_with_some_invalid_comission
122
- invalid_commission = Fixture.commission
123
- invalid_commission.stubs(:invalid?).returns(true)
124
- subject = Fixture.instruction(commissions: [Fixture.commission, invalid_commission])
125
- assert_raise MyMoip::InvalidComission do
126
- subject.to_xml
127
- end
128
- end
129
-
130
- def test_to_xml_method_raises_exception_when_called_with_invalid_payer
131
- subject = Fixture.instruction
132
- MyMoip::Payer.any_instance.stubs(:invalid?).returns(true)
133
- assert_raise MyMoip::InvalidPayer do
134
- subject.to_xml
135
- end
136
- end
137
-
138
- def test_to_xml_method_dont_raises_exception_when_called_with_valid_payer
139
- subject = Fixture.instruction
140
- MyMoip::Payer.any_instance.stubs(:invalid?).returns(false)
141
- assert_nothing_raised MyMoip::InvalidPayer do
142
- subject.to_xml
143
- end
144
- end
145
-
146
- def test_to_xml_method_raises_exception_when_called_with_invalid_params
147
- subject = Fixture.instruction
148
- MyMoip::Instruction.any_instance.stubs(:invalid?).returns(true)
149
- assert_raise MyMoip::InvalidInstruction do
150
- subject.to_xml
151
- end
152
- end
153
-
154
- def test_to_xml_method_dont_raises_exception_when_called_with_valid_params
155
- subject = Fixture.instruction
156
- MyMoip::Instruction.any_instance.stubs(:invalid?).returns(false)
157
- assert_nothing_raised MyMoip::InvalidInstruction do
158
- subject.to_xml
159
- end
160
- end
161
-
162
- def test_validate_no_presence_of_payment_receiver_in_commissions
163
- commissions = [Fixture.commission(receiver_login: 'payment_receiver_id')]
164
- subject = Fixture.instruction(payment_receiver_login: 'payment_receiver_id', commissions: commissions)
165
- assert subject.invalid? && subject.errors[:payment_receiver_login].present?,
166
- "should be invalid with receiver present on commissions"
167
- end
168
-
169
- def test_gross_amount
170
- subject = Fixture.instruction(values: [6, 5])
171
- assert_equal 11, subject.gross_amount
172
- end
173
-
174
- def test_commissions_sum
175
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(percentage_value: 0.1, fixed_value: nil)]
176
- subject = Fixture.instruction(commissions: commissions, values: [10])
177
- assert_equal 6, subject.commissions_sum
178
- end
179
-
180
- def test_validate_commissions_sum
181
- commissions = [Fixture.commission(fixed_value: 5), Fixture.commission(fixed_value: 5)]
182
- subject = Fixture.instruction(commissions: commissions, values: [6])
183
- assert subject.invalid? && subject.errors[:commissions].present?,
184
- "should be invalid with commissions sum greater than values sum"
185
- end
186
-
187
- def test_validate_presence_of_id_attribute
188
- subject = Fixture.instruction
189
- subject.id = nil
190
- assert subject.invalid? && subject.errors[:id].present?,
191
- 'should be invalid without an id'
192
- end
193
-
194
- def test_validate_presence_of_payment_reason_attribute
195
- subject = Fixture.instruction
196
- subject.payment_reason = nil
197
- assert subject.invalid? && subject.errors[:payment_reason].present?,
198
- 'should be invalid without a payment_reason'
199
- subject.payment_reason = ''
200
- assert subject.invalid? && subject.errors[:payment_reason].present?,
201
- 'should be invalid without a payment_reason'
202
- end
203
-
204
- def test_validate_presence_of_values_attribute
205
- subject = Fixture.instruction
206
- subject.values = nil
207
- assert subject.invalid? && subject.errors[:values].present?,
208
- 'should be invalid without values'
209
- end
210
-
211
- def test_validate_presence_of_payer_attribute
212
- subject = Fixture.instruction
213
- subject.payer = nil
214
- assert subject.invalid? && subject.errors[:payer].present?,
215
- 'should be invalid without a payer'
216
- end
217
- end
data/test/test_mymoip.rb DELETED
@@ -1,81 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMymoip < 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_default_environment_is_sandbox
19
- MyMoip.environment = 'sandbox'
20
- assert_equal "sandbox", MyMoip.environment
21
- end
22
-
23
- def test_key_setter_updates_sandbox_and_production_keys
24
- MyMoip.key = "my_key"
25
- assert_equal "my_key", MyMoip.production_key
26
- assert_equal "my_key", MyMoip.sandbox_key
27
- end
28
-
29
- def test_token_setter_updates_sandbox_and_production_tokens
30
- MyMoip.token = "my_token"
31
- assert_equal "my_token", MyMoip.production_token
32
- assert_equal "my_token", MyMoip.sandbox_token
33
- end
34
-
35
- def test_current_auth_when_in_sandbox
36
- MyMoip.sandbox_key = "sandbox_key"
37
- MyMoip.sandbox_token = "sandbox_token"
38
- MyMoip.environment = "sandbox"
39
- assert_equal "sandbox_key", MyMoip.key
40
- assert_equal "sandbox_token", MyMoip.token
41
- end
42
-
43
- def test_current_auth_when_in_production
44
- MyMoip.production_key = "production_key"
45
- MyMoip.production_token = "production_token"
46
- MyMoip.environment = "production"
47
- assert_equal "production_key", MyMoip.key
48
- assert_equal "production_token", MyMoip.token
49
- end
50
-
51
- def test_default_referer_url_setter
52
- MyMoip.default_referer_url = "http://localhost"
53
- assert_equal "http://localhost", MyMoip.default_referer_url
54
- end
55
-
56
- def test_environment_setter
57
- MyMoip.environment = "production"
58
- assert_equal "production", MyMoip.environment
59
- end
60
-
61
- def test_choose_right_api_url_by_sandbox_environment
62
- MyMoip.environment = "sandbox"
63
- assert_equal "https://desenvolvedor.moip.com.br/sandbox", MyMoip.api_url
64
- end
65
-
66
- def test_choose_right_api_url_by_production_environment
67
- default_env = MyMoip.environment
68
- MyMoip.environment = "production"
69
- assert_equal "https://www.moip.com.br", MyMoip.api_url
70
- end
71
-
72
- def test_logger_initialization
73
- assert MyMoip.logger.instance_of?(Logger)
74
- end
75
-
76
- def test_attribution_of_new_logger
77
- default_logger = MyMoip.logger
78
- MyMoip.logger = my_string = ""
79
- assert_equal my_string, MyMoip.logger
80
- end
81
- end