moip2 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +129 -0
- data/Rakefile +1 -0
- data/lib/moip2/api.rb +24 -0
- data/lib/moip2/auth/basic.rb +19 -0
- data/lib/moip2/auth/oauth.rb +18 -0
- data/lib/moip2/client.rb +107 -0
- data/lib/moip2/customer_api.rb +24 -0
- data/lib/moip2/exceptions/invalid_enviroment_error.rb +6 -0
- data/lib/moip2/invoice_api.rb +32 -0
- data/lib/moip2/keys_api.rb +17 -0
- data/lib/moip2/multi_order_api.rb +23 -0
- data/lib/moip2/multi_payment_api.rb +17 -0
- data/lib/moip2/order_api.rb +25 -0
- data/lib/moip2/payment_api.rb +15 -0
- data/lib/moip2/resource/customer.rb +16 -0
- data/lib/moip2/resource/invoice.rb +14 -0
- data/lib/moip2/resource/keys.rb +14 -0
- data/lib/moip2/resource/multi_order.rb +25 -0
- data/lib/moip2/resource/multi_payment.rb +11 -0
- data/lib/moip2/resource/order.rb +25 -0
- data/lib/moip2/resource/payment.rb +13 -0
- data/lib/moip2/response.rb +20 -0
- data/lib/moip2/version.rb +3 -0
- data/lib/moip2.rb +74 -0
- data/moip2.gemspec +30 -0
- data/spec/moip2/api_spec.rb +25 -0
- data/spec/moip2/auth/basic_spec.rb +9 -0
- data/spec/moip2/auth/oauth_spec.rb +9 -0
- data/spec/moip2/client_spec.rb +133 -0
- data/spec/moip2/customer_api_spec.rb +152 -0
- data/spec/moip2/invoice_spec.rb +95 -0
- data/spec/moip2/keys_spec.rb +19 -0
- data/spec/moip2/multi_order_api_spec.rb +198 -0
- data/spec/moip2/order_api_spec.rb +138 -0
- data/spec/moip2/payment_api_spec.rb +43 -0
- data/spec/moip2/resource/order_spec.rb +47 -0
- data/spec/moip2/response_spec.rb +51 -0
- data/spec/moip2_spec.rb +50 -0
- data/spec/spec_helper.rb +113 -0
- data/vcr_cassettes/create_customer.yml +43 -0
- data/vcr_cassettes/create_customer_with_funding_instrument.yml +45 -0
- data/vcr_cassettes/create_invoice.yml +42 -0
- data/vcr_cassettes/create_mulit_order_success.yml +142 -0
- data/vcr_cassettes/create_multi_order_fail.yml +43 -0
- data/vcr_cassettes/create_order_fail.yml +43 -0
- data/vcr_cassettes/create_order_success.yml +47 -0
- data/vcr_cassettes/create_payment_success.yml +39 -0
- data/vcr_cassettes/get_customer.yml +42 -0
- data/vcr_cassettes/get_invoice.yml +41 -0
- data/vcr_cassettes/get_keys.yml +42 -0
- data/vcr_cassettes/list_invoices.yml +43 -0
- data/vcr_cassettes/show_multi_order.yml +132 -0
- data/vcr_cassettes/show_multi_order_not_found.yml +40 -0
- data/vcr_cassettes/show_order.yml +43 -0
- data/vcr_cassettes/show_order_not_found.yml +38 -0
- data/vcr_cassettes/update_invoice.yml +41 -0
- data/wercker.yml +48 -0
- metadata +238 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
describe Moip2::MultiOrderApi do
|
2
|
+
|
3
|
+
let(:multi_order_api) { described_class.new(sandbox_client) }
|
4
|
+
|
5
|
+
describe "#create" do
|
6
|
+
let(:multi_order) do
|
7
|
+
{
|
8
|
+
ownId: "meu_multiorder_id",
|
9
|
+
orders: [
|
10
|
+
{
|
11
|
+
ownId: "pedido_1_id",
|
12
|
+
amount: {
|
13
|
+
currency: "BRL",
|
14
|
+
subtotals: {
|
15
|
+
shipping: 2000
|
16
|
+
}
|
17
|
+
},
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
product: "Camisa Verde e Amarelo - Brasil",
|
21
|
+
quantity: 1,
|
22
|
+
detail: "Seleção Brasileira",
|
23
|
+
price: 2000
|
24
|
+
}
|
25
|
+
],
|
26
|
+
customer: {
|
27
|
+
ownId: "customer[1234]",
|
28
|
+
fullname: "Joao Sousa",
|
29
|
+
email: "joao.sousa@email.com",
|
30
|
+
birthDate: "1988-12-30",
|
31
|
+
taxDocument: {
|
32
|
+
type: "CPF",
|
33
|
+
number: "22222222222"
|
34
|
+
},
|
35
|
+
phone: {
|
36
|
+
countryCode: "55",
|
37
|
+
areaCode: "11",
|
38
|
+
number: "66778899"
|
39
|
+
},
|
40
|
+
addresses: [
|
41
|
+
{
|
42
|
+
type: "BILLING",
|
43
|
+
street: "Avenida Faria Lima",
|
44
|
+
streetNumber: 2927,
|
45
|
+
complement: 8,
|
46
|
+
district: "Itaim",
|
47
|
+
city: "Sao Paulo",
|
48
|
+
state: "SP",
|
49
|
+
country: "BRA",
|
50
|
+
zipCode: "01234000"
|
51
|
+
}
|
52
|
+
]
|
53
|
+
},
|
54
|
+
receivers: [
|
55
|
+
{
|
56
|
+
moipAccount: {
|
57
|
+
id: "MPA-1K2R51KFL3OY"
|
58
|
+
},
|
59
|
+
type: "PRIMARY"
|
60
|
+
}
|
61
|
+
]
|
62
|
+
},
|
63
|
+
{
|
64
|
+
ownId: "pedido_2_id",
|
65
|
+
amount: {
|
66
|
+
currency: "BRL",
|
67
|
+
subtotals: {
|
68
|
+
shipping: 3000
|
69
|
+
}
|
70
|
+
},
|
71
|
+
items: [
|
72
|
+
{
|
73
|
+
product: "Camisa Preta - Alemanha",
|
74
|
+
quantity: 1,
|
75
|
+
detail: "Camiseta da Copa 2014",
|
76
|
+
price: 1000
|
77
|
+
}
|
78
|
+
],
|
79
|
+
customer: {
|
80
|
+
ownId: "customer[1234]",
|
81
|
+
fullname: "Joao Sousa",
|
82
|
+
email: "joao.sousa@email.com",
|
83
|
+
birthDate: "1988-12-30",
|
84
|
+
taxDocument: {
|
85
|
+
type: "CPF",
|
86
|
+
number: "22222222222"
|
87
|
+
},
|
88
|
+
phone: {
|
89
|
+
countryCode: "55",
|
90
|
+
areaCode: "11",
|
91
|
+
number: "66778899"
|
92
|
+
},
|
93
|
+
addresses: [
|
94
|
+
{
|
95
|
+
type: "BILLING",
|
96
|
+
street: "Avenida Faria Lima",
|
97
|
+
streetNumber: 2927,
|
98
|
+
complement: 8,
|
99
|
+
district: "Itaim",
|
100
|
+
city: "Sao Paulo",
|
101
|
+
state: "SP",
|
102
|
+
country: "BRA",
|
103
|
+
zipCode: "01234000"
|
104
|
+
}
|
105
|
+
]
|
106
|
+
},
|
107
|
+
receivers: [
|
108
|
+
{
|
109
|
+
moipAccount: {
|
110
|
+
id: "MPA-IFYRB1HBL73Z"
|
111
|
+
},
|
112
|
+
type: "PRIMARY"
|
113
|
+
},
|
114
|
+
{
|
115
|
+
moipAccount: {
|
116
|
+
id: "MPA-KQB1QFWS6QNM"
|
117
|
+
},
|
118
|
+
type: "SECONDARY",
|
119
|
+
amount: {
|
120
|
+
fixed: 55
|
121
|
+
}
|
122
|
+
}
|
123
|
+
]
|
124
|
+
}
|
125
|
+
]
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:created_multi_order) do
|
130
|
+
VCR.use_cassette("create_mulit_order_success") do
|
131
|
+
multi_order_api.create(multi_order)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "creates a multiOrder on moip" do
|
136
|
+
expect(created_multi_order.id).to eq "MOR-IVKZDU55LXJU"
|
137
|
+
expect(created_multi_order.own_id).to eq "meu_multiorder_id"
|
138
|
+
expect(created_multi_order.status).to eq "CREATED"
|
139
|
+
expect(created_multi_order.orders).to_not be_nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it "returns an MultiOrder object" do
|
143
|
+
expect(created_multi_order).to be_a(Moip2::Resource::MultiOrder)
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when validation error" do
|
147
|
+
|
148
|
+
let(:created_multi_order) do
|
149
|
+
VCR.use_cassette("create_multi_order_fail") do
|
150
|
+
multi_order_api.create({})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "returns an error" do
|
155
|
+
expect(created_multi_order).to_not be_success
|
156
|
+
expect(created_multi_order).to be_client_error
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns an error json" do
|
160
|
+
expect(created_multi_order["errors"].size).to eq(1)
|
161
|
+
expect(created_multi_order.errors[0].code).to_not be_nil
|
162
|
+
expect(created_multi_order.errors[0].path).to_not be_nil
|
163
|
+
expect(created_multi_order.errors[0].description).to_not be_nil
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "#show" do
|
171
|
+
|
172
|
+
let(:multi_order) do
|
173
|
+
VCR.use_cassette("show_multi_order") do
|
174
|
+
multi_order_api.show("MOR-IVKZDU55LXJU")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
it "returns an multi order" do
|
179
|
+
expect(multi_order["id"]).to eq("MOR-IVKZDU55LXJU")
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when multi order not found" do
|
183
|
+
|
184
|
+
let(:multi_order) do
|
185
|
+
VCR.use_cassette("show_multi_order_not_found") do
|
186
|
+
multi_order_api.show("MOR-INVALID")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "raises a NotFound" do
|
191
|
+
expect { multi_order }.to raise_error Moip2::NotFoundError
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
describe Moip2::OrderApi do
|
2
|
+
|
3
|
+
let(:order_api) { described_class.new(sandbox_client) }
|
4
|
+
|
5
|
+
describe "#create" do
|
6
|
+
|
7
|
+
let(:order) do
|
8
|
+
{
|
9
|
+
own_id: "your_own_id_1",
|
10
|
+
amount: {
|
11
|
+
currency: "BRL"
|
12
|
+
},
|
13
|
+
items: [
|
14
|
+
{
|
15
|
+
product: "Some Product",
|
16
|
+
quantity: 1,
|
17
|
+
detail: "Some Product Detail",
|
18
|
+
price: 100
|
19
|
+
}
|
20
|
+
],
|
21
|
+
customer: {
|
22
|
+
own_id: "your_customer_own_id",
|
23
|
+
fullname: "John Doe",
|
24
|
+
email: "john.doe@mailinator.com",
|
25
|
+
birthdate: "1988-11-11",
|
26
|
+
tax_document: { number: "22222222222", type: "CPF" },
|
27
|
+
phone: { country_code: "55", area_code: "11", number: "5566778899" },
|
28
|
+
shipping_address:
|
29
|
+
{
|
30
|
+
street: "Avenida Faria Lima",
|
31
|
+
street_number: 2927,
|
32
|
+
complement: 8,
|
33
|
+
district: "Itaim",
|
34
|
+
city: "Sao Paulo",
|
35
|
+
state: "SP",
|
36
|
+
country: "BRA",
|
37
|
+
zip_code: "01234000"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:created_order) do
|
44
|
+
VCR.use_cassette("create_order_success") do
|
45
|
+
order_api.create(order)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "creates an order on moip" do
|
50
|
+
expect(created_order.id).to_not be_nil
|
51
|
+
expect(created_order.own_id).to eq("your_own_id_1")
|
52
|
+
expect(created_order.status).to eq("CREATED")
|
53
|
+
expect(created_order.created_at).to eq("2015-02-27T10:23:13-0300")
|
54
|
+
expect(created_order.amount).to_not be_nil
|
55
|
+
|
56
|
+
expect(created_order.amount.total).to eq 100
|
57
|
+
expect(created_order.amount.fees).to eq(0)
|
58
|
+
expect(created_order.amount.refunds).to eq(0)
|
59
|
+
expect(created_order.amount.liquid).to eq(0)
|
60
|
+
expect(created_order.amount.other_receivers).to eq(0)
|
61
|
+
expect(created_order.amount.currency).to eq("BRL")
|
62
|
+
|
63
|
+
expect(created_order.amount.subtotals).to_not be_nil
|
64
|
+
expect(created_order.amount.subtotals.shipping).to eq(0)
|
65
|
+
expect(created_order.amount.subtotals.addition).to eq(0)
|
66
|
+
expect(created_order.amount.subtotals.discount).to eq(0)
|
67
|
+
expect(created_order.amount.subtotals.items).to eq(100)
|
68
|
+
|
69
|
+
expect(created_order.items[0].product).to eq("Some Product")
|
70
|
+
expect(created_order.items[0].price).to eq(100)
|
71
|
+
expect(created_order.items[0].detail).to eq("Some Product Detail")
|
72
|
+
expect(created_order.items[0].quantity).to eq(1)
|
73
|
+
|
74
|
+
expect(created_order.customer.id).to eq("CUS-B6LE6HLFFXKF")
|
75
|
+
|
76
|
+
expect(created_order.customer.shipping_address).to_not be_nil
|
77
|
+
|
78
|
+
expect(created_order.customer._links).to_not be_nil
|
79
|
+
expect(created_order.customer._links.self.href).to eq "https://test.moip.com.br/v2/customers/CUS-B6LE6HLFFXKF"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns an Order object" do
|
83
|
+
expect(created_order).to be_a(Moip2::Resource::Order)
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when validation error" do
|
87
|
+
|
88
|
+
let(:created_order) do
|
89
|
+
VCR.use_cassette("create_order_fail") do
|
90
|
+
order_api.create({})
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns an error" do
|
95
|
+
expect(created_order).to_not be_success
|
96
|
+
expect(created_order).to be_client_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns an error json" do
|
100
|
+
expect(created_order.errors.size).to eq(2)
|
101
|
+
expect(created_order.errors[0].code).to_not be_nil
|
102
|
+
expect(created_order.errors[0].path).to_not be_nil
|
103
|
+
expect(created_order.errors[0].description).to_not be_nil
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#show" do
|
111
|
+
|
112
|
+
let(:order) do
|
113
|
+
VCR.use_cassette("show_order") do
|
114
|
+
order_api.show("ORD-EQE16JGCM52O")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "returns an order" do
|
119
|
+
expect(order["id"]).to eq("ORD-EQE16JGCM52O")
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when order not found" do
|
123
|
+
|
124
|
+
let(:order) do
|
125
|
+
VCR.use_cassette("show_order_not_found") do
|
126
|
+
order_api.show("ORD-INVALID")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "raises a NotFound" do
|
131
|
+
expect { order }.to raise_error Moip2::NotFoundError
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe Moip2::PaymentApi do
|
2
|
+
|
3
|
+
let(:payment_api) { described_class.new(sandbox_client) }
|
4
|
+
|
5
|
+
let(:created_payment) do
|
6
|
+
VCR.use_cassette("create_payment_success") do
|
7
|
+
payment_api.create("ORD-UEK2XGEXNWL9", {
|
8
|
+
installmentCount: 1,
|
9
|
+
fundingInstrument: {
|
10
|
+
method: "CREDIT_CARD",
|
11
|
+
creditCard: {
|
12
|
+
expirationMonth: 05,
|
13
|
+
expirationYear: 18,
|
14
|
+
number: "4012001038443335",
|
15
|
+
cvc: "123",
|
16
|
+
holder: {
|
17
|
+
fullname: "Jose Portador da Silva",
|
18
|
+
birthdate: "1988-12-30",
|
19
|
+
taxDocument: {
|
20
|
+
type: "CPF",
|
21
|
+
number: "33333333333"
|
22
|
+
},
|
23
|
+
phone: {
|
24
|
+
countryCode: "55",
|
25
|
+
areaCode: "11",
|
26
|
+
number: "66778899"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates a credit card payment on moip" do
|
36
|
+
expect(created_payment.id).to eq("PAY-W3MNW718O3AI")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns a Payment object" do
|
40
|
+
expect(created_payment).to be_a(Moip2::Resource::Payment)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe Moip2::Resource::Order do
|
2
|
+
|
3
|
+
let(:order) do
|
4
|
+
described_class.new(sandbox_client, Moip2::Response.new(nil, { external_id: "ORD-UEK2XGEXNWL9" }))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#create_payment" do
|
8
|
+
let(:created_payment) do
|
9
|
+
VCR.use_cassette("create_payment_success") do
|
10
|
+
order.create_payment({
|
11
|
+
installmentCount: 1,
|
12
|
+
fundingInstrument: {
|
13
|
+
method: "CREDIT_CARD",
|
14
|
+
creditCard: {
|
15
|
+
expirationMonth: 05,
|
16
|
+
expirationYear: 18,
|
17
|
+
number: "4012001038443335",
|
18
|
+
cvc: "123",
|
19
|
+
holder: {
|
20
|
+
fullname: "Jose Portador da Silva",
|
21
|
+
birthdate: "1988-12-30",
|
22
|
+
taxDocument: {
|
23
|
+
type: "CPF",
|
24
|
+
number: "33333333333"
|
25
|
+
},
|
26
|
+
phone: {
|
27
|
+
countryCode: "55",
|
28
|
+
areaCode: "11",
|
29
|
+
number: "66778899"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a credit card payment on moip" do
|
39
|
+
expect(created_payment.id).to eq("PAY-W3MNW718O3AI")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a Payment object" do
|
43
|
+
expect(created_payment).to be_a(Moip2::Resource::Payment)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
describe Moip2::Response do
|
2
|
+
|
3
|
+
let(:parsed_json) { { "id" => "ORD-SOMETHING" } }
|
4
|
+
|
5
|
+
let(:response) { described_class.new(nil, parsed_json) }
|
6
|
+
|
7
|
+
describe "method delegation" do
|
8
|
+
|
9
|
+
it "delegates []" do
|
10
|
+
expect(response["id"]).to eq("ORD-SOMETHING")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "delegates attribute to property accessor" do
|
14
|
+
expect(response.id).to eq("ORD-SOMETHING")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#success?" do
|
20
|
+
|
21
|
+
let(:success_response) do
|
22
|
+
double("Success Response").tap do |success_response|
|
23
|
+
allow(success_response).to receive(:code).and_return(200)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:response) { described_class.new(success_response, parsed_json) }
|
28
|
+
|
29
|
+
it "returns true when response code == 2xx" do
|
30
|
+
expect(response).to be_success
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#client_error?" do
|
36
|
+
|
37
|
+
let(:error_response) do
|
38
|
+
double("Error Response").tap do |error_response|
|
39
|
+
allow(error_response).to receive(:code).and_return(400)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:response) { described_class.new(error_response, {}) }
|
44
|
+
|
45
|
+
it "returns false when response code == 4xx" do
|
46
|
+
expect(response).to be_client_error
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/moip2_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
describe Moip2 do
|
2
|
+
|
3
|
+
describe ".new" do
|
4
|
+
|
5
|
+
let(:auth) do
|
6
|
+
Moip2::Auth::Basic.new("TOKEN", "SECRET")
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
let(:moip) do
|
11
|
+
described_class.auth = auth
|
12
|
+
described_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates a new Api using default environment" do
|
16
|
+
expect(moip.client.env).to eq(:sandbox)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "creates a new Api using defined auth" do
|
20
|
+
expect(moip.client.auth).to eq(auth)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates a new Client" do
|
24
|
+
expect(moip).to be_a(Moip2::Api)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "valid_env comparision rails variable" do
|
28
|
+
expect{ Moip2.env=(:production) }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "invalid enviroment error" do
|
32
|
+
expect{ Moip2.env=("abc") }.to raise_error(Moip2::InvalidEnviromentError)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
context "when auth is not set" do
|
37
|
+
|
38
|
+
let(:moip) do
|
39
|
+
described_class.auth = nil
|
40
|
+
described_class.new
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error" do
|
44
|
+
expect { moip }.to raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "moip2"
|
2
|
+
|
3
|
+
require "vcr"
|
4
|
+
require "webmock"
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
9
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# (such as loading up an entire rails app) will add to the boot time of your
|
14
|
+
# test suite on EVERY test run, even for an individual file that may not need
|
15
|
+
# all of that loaded.
|
16
|
+
#
|
17
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
18
|
+
# users commonly want.
|
19
|
+
#
|
20
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# The settings below are suggested to provide a good initial experience
|
23
|
+
# with RSpec, but feel free to customize to your heart's content.
|
24
|
+
=begin
|
25
|
+
# These two settings work together to allow you to limit a spec run
|
26
|
+
# to individual examples or groups you care about by tagging them with
|
27
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
28
|
+
# get run.
|
29
|
+
config.filter_run :focus
|
30
|
+
config.run_all_when_everything_filtered = true
|
31
|
+
|
32
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
33
|
+
# file, and it's useful to allow more verbose output when running an
|
34
|
+
# individual spec file.
|
35
|
+
if config.files_to_run.one?
|
36
|
+
# RSpec filters the backtrace by default so as not to be so noisy.
|
37
|
+
# This causes the full backtrace to be printed when running a single
|
38
|
+
# spec file (e.g. to troubleshoot a particular spec failure).
|
39
|
+
config.full_backtrace = true
|
40
|
+
|
41
|
+
# Use the documentation formatter for detailed output,
|
42
|
+
# unless a formatter has already been configured
|
43
|
+
# (e.g. via a command-line flag).
|
44
|
+
config.formatter = 'doc' if config.formatters.none?
|
45
|
+
end
|
46
|
+
|
47
|
+
# Print the 10 slowest examples and example groups at the
|
48
|
+
# end of the spec run, to help surface which specs are running
|
49
|
+
# particularly slow.
|
50
|
+
config.profile_examples = 10
|
51
|
+
|
52
|
+
# Run specs in random order to surface order dependencies. If you find an
|
53
|
+
# order dependency and want to debug it, you can fix the order by providing
|
54
|
+
# the seed, which is printed after each run.
|
55
|
+
# --seed 1234
|
56
|
+
config.order = :random
|
57
|
+
|
58
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
59
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
60
|
+
# test failures related to randomization by passing the same `--seed` value
|
61
|
+
# as the one that triggered the failure.
|
62
|
+
Kernel.srand config.seed
|
63
|
+
|
64
|
+
# rspec-expectations config goes here. You can use an alternate
|
65
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
66
|
+
# assertions if you prefer.
|
67
|
+
config.expect_with :rspec do |expectations|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
71
|
+
expectations.syntax = :expect
|
72
|
+
end
|
73
|
+
|
74
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
75
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
76
|
+
config.mock_with :rspec do |mocks|
|
77
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
78
|
+
# For more details, see:
|
79
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
80
|
+
mocks.syntax = :expect
|
81
|
+
|
82
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
83
|
+
# a real object. This is generally recommended.
|
84
|
+
mocks.verify_partial_doubles = true
|
85
|
+
end
|
86
|
+
=end
|
87
|
+
end
|
88
|
+
|
89
|
+
VCR.configure do |c|
|
90
|
+
c.cassette_library_dir = 'vcr_cassettes'
|
91
|
+
c.hook_into :webmock # or :fakeweb
|
92
|
+
end
|
93
|
+
|
94
|
+
# Helper methods
|
95
|
+
def sandbox_auth
|
96
|
+
Moip2::Auth::Basic.new('01010101010101010101010101010101', 'ABABABABABABABABABABABABABABABABABABABAB')
|
97
|
+
end
|
98
|
+
|
99
|
+
def sandbox_oauth
|
100
|
+
Moip2::Auth::OAuth.new "d63tz2xwyu0ewrembove4j5cbv2otpd"
|
101
|
+
end
|
102
|
+
|
103
|
+
def sandbox_client
|
104
|
+
Moip2::Client.new(:sandbox, sandbox_auth)
|
105
|
+
end
|
106
|
+
|
107
|
+
def sandbox_oauth_client
|
108
|
+
Moip2::Client.new :sandbox, sandbox_oauth
|
109
|
+
end
|
110
|
+
|
111
|
+
def sanbox_client_with_header
|
112
|
+
Moip2::Client.new(:sandbox, sandbox_auth, { headers: { "Moip-Account" => "MPA-UY765TYBL912" } } )
|
113
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://01010101010101010101010101010101:ABABABABABABABABABABABABABABABABABABABAB@test.moip.com.br/v2/customers
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"ownId":"meu_id_sandbox_1231234","fullname":"Jose Silva","email":"jose_silva0@email.com","birthDate":"1988-12-30","taxDocument":{"type":"CPF","number":"22222222222"},"phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"shippingAddress":{"city":"Sao
|
9
|
+
Paulo","complement":"8","district":"Itaim","street":"Avenida Faria Lima","streetNumber":"2927","zipCode":"01234000","state":"SP","country":"BRA"}}'
|
10
|
+
headers:
|
11
|
+
Content-Type:
|
12
|
+
- application/json
|
13
|
+
response:
|
14
|
+
status:
|
15
|
+
code: 201
|
16
|
+
message: Created
|
17
|
+
headers:
|
18
|
+
Server:
|
19
|
+
- nginx
|
20
|
+
Date:
|
21
|
+
- Mon, 02 Mar 2015 13:59:31 GMT
|
22
|
+
Content-Type:
|
23
|
+
- application/json
|
24
|
+
Content-Length:
|
25
|
+
- '570'
|
26
|
+
Connection:
|
27
|
+
- keep-alive
|
28
|
+
Status:
|
29
|
+
- 201 Created
|
30
|
+
X-Newrelic-App-Data:
|
31
|
+
- PxQFUlBXAQoTV1VaDgIEV0YdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOFAVtGAURQkJcDwMRERBKaC1rbB0QH1UXUR1RHVJdAQJVVFUMHwRUWE4VBQBSUARQUFNfAAMAVQFRARpp
|
32
|
+
Vary:
|
33
|
+
- Accept-Encoding
|
34
|
+
X-Content-Type-Options:
|
35
|
+
- nosniff
|
36
|
+
body:
|
37
|
+
encoding: UTF-8
|
38
|
+
string: '{"id":"CUS-4GESZSOAH7HX","ownId":"meu_id_sandbox_1231234","fullname":"Jose
|
39
|
+
Silva","createdAt":"2015-03-02T10:59:31-0300","birthDate":"1988-12-30T00:00:00-0200","email":"jose_silva0@email.com","phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"zipCode":"01234000","street":"Avenida
|
40
|
+
Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://test.moip.com.br/v2/customers/CUS-4GESZSOAH7HX"}}}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Mon, 02 Mar 2015 13:59:16 GMT
|
43
|
+
recorded_with: VCR 2.9.3
|