moip2 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +644 -0
- data/.travis.yml +14 -3
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +25 -6
- data/Guardfile +1 -2
- data/README.md +373 -74
- data/Rakefile +2 -2
- data/changelog.md +36 -0
- data/lib/moip2/accounts_api.rb +27 -0
- data/lib/moip2/api.rb +25 -2
- data/lib/moip2/auth/basic.rb +2 -5
- data/lib/moip2/auth/oauth.rb +0 -3
- data/lib/moip2/client.rb +45 -31
- data/lib/moip2/connect_api.rb +41 -0
- data/lib/moip2/customer_api.rb +16 -2
- data/lib/moip2/exceptions/invalid_enviroment_error.rb +0 -2
- data/lib/moip2/invoice_api.rb +8 -3
- data/lib/moip2/keys_api.rb +14 -14
- data/lib/moip2/multi_order_api.rb +1 -3
- data/lib/moip2/multi_payment_api.rb +1 -1
- data/lib/moip2/notifications_api.rb +33 -0
- data/lib/moip2/order_api.rb +18 -3
- data/lib/moip2/payment_api.rb +11 -1
- data/lib/moip2/refund_api.rb +5 -4
- data/lib/moip2/resource/account.rb +12 -0
- data/lib/moip2/resource/connect.rb +9 -0
- data/lib/moip2/resource/credit_card.rb +12 -0
- data/lib/moip2/resource/customer.rb +0 -4
- data/lib/moip2/resource/invoice.rb +0 -2
- data/lib/moip2/resource/keys.rb +1 -3
- data/lib/moip2/resource/multi_order.rb +2 -6
- data/lib/moip2/resource/multi_payment.rb +1 -3
- data/lib/moip2/resource/notification.rb +12 -0
- data/lib/moip2/resource/order.rb +0 -4
- data/lib/moip2/resource/payment.rb +0 -4
- data/lib/moip2/resource/refund.rb +1 -2
- data/lib/moip2/resource/webhooks.rb +11 -13
- data/lib/moip2/response.rb +7 -7
- data/lib/moip2/util/filters_encoder.rb +28 -0
- data/lib/moip2/version.rb +1 -1
- data/lib/moip2/webhooks_api.rb +16 -16
- data/lib/moip2.rb +10 -5
- data/moip2.gemspec +21 -7
- data/spec/moip2/accounts_api_spec.rb +189 -0
- data/spec/moip2/api_spec.rb +22 -4
- data/spec/moip2/auth/basic_spec.rb +8 -4
- data/spec/moip2/auth/oauth_spec.rb +4 -4
- data/spec/moip2/client_spec.rb +20 -27
- data/spec/moip2/connect_api_spec.rb +68 -0
- data/spec/moip2/customer_api_spec.rb +147 -72
- data/spec/moip2/invoice_spec.rb +51 -32
- data/spec/moip2/keys_spec.rb +16 -18
- data/spec/moip2/multi_order_api_spec.rb +99 -108
- data/spec/moip2/multi_payment_api_spec.rb +8 -11
- data/spec/moip2/notifications_api_spec.rb +104 -0
- data/spec/moip2/order_api_spec.rb +100 -20
- data/spec/moip2/payment_api_spec.rb +77 -17
- data/spec/moip2/refund_api_spec.rb +2 -4
- data/spec/moip2/resource/order_spec.rb +24 -28
- data/spec/moip2/response_spec.rb +0 -8
- data/spec/moip2/webhooks_spec.rb +18 -21
- data/spec/moip2_spec.rb +6 -13
- data/spec/spec_helper.rb +24 -10
- data/vcr_cassettes/_create_invoice.yml +42 -0
- data/vcr_cassettes/_get_invoice.yml +41 -0
- data/vcr_cassettes/account_doesnt_exist.yml +44 -0
- data/vcr_cassettes/account_exists.yml +46 -0
- data/vcr_cassettes/accounts_show_existent.yml +50 -0
- data/vcr_cassettes/accounts_show_nonexistent.yml +42 -0
- data/vcr_cassettes/cancel_payment.yml +43 -0
- data/vcr_cassettes/capture_payment.yml +42 -0
- data/vcr_cassettes/create_account_success_company.yml +87 -0
- data/vcr_cassettes/create_account_success_standalone.yml +74 -0
- data/vcr_cassettes/create_credit_card_customer.yml +41 -0
- data/vcr_cassettes/create_invoice.yml +10 -16
- data/vcr_cassettes/create_notification.yml +38 -0
- data/vcr_cassettes/create_notification_app.yml +38 -0
- data/vcr_cassettes/delete_credit_card_customer.yml +40 -0
- data/vcr_cassettes/delete_nonexistent_credit_card_customer.yml +40 -0
- data/vcr_cassettes/delete_nonexistent_notification.yml +40 -0
- data/vcr_cassettes/delete_notification.yml +36 -0
- data/vcr_cassettes/find_all_orders_filters.yml +56 -0
- data/vcr_cassettes/find_all_orders_limit.yml +48 -0
- data/vcr_cassettes/find_all_orders_multi_filters.yml +57 -0
- data/vcr_cassettes/find_all_orders_no_filter.yml +56 -0
- data/vcr_cassettes/generate_oauth_token.yml +42 -0
- data/vcr_cassettes/get_invoice.yml +10 -15
- data/vcr_cassettes/get_keys.yml +1 -1
- data/vcr_cassettes/get_notification.yml +38 -0
- data/vcr_cassettes/get_notifications_list.yml +38 -0
- data/vcr_cassettes/get_payment.yml +42 -0
- data/vcr_cassettes/get_payment_not_found.yml +40 -0
- data/vcr_cassettes/get_webhooks.yml +1 -1
- data/vcr_cassettes/list_invoices.yml +2 -2
- data/vcr_cassettes/refresh_oauth_token.yml +40 -0
- data/vcr_cassettes/update_invoice.yml +1 -1
- metadata +69 -7
@@ -1,129 +1,128 @@
|
|
1
1
|
describe Moip2::MultiOrderApi do
|
2
|
-
|
3
2
|
let(:multi_order_api) { described_class.new(sandbox_client) }
|
4
|
-
|
5
|
-
describe "#create" do
|
3
|
+
|
4
|
+
describe "#create" do
|
6
5
|
let(:multi_order) do
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
{
|
7
|
+
ownId: "meu_multiorder_id",
|
8
|
+
orders: [
|
10
9
|
{
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
10
|
+
ownId: "pedido_1_id",
|
11
|
+
amount: {
|
12
|
+
currency: "BRL",
|
13
|
+
subtotals: {
|
14
|
+
shipping: 2000,
|
15
|
+
},
|
17
16
|
},
|
18
|
-
|
17
|
+
items: [
|
19
18
|
{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
19
|
+
product: "Camisa Verde e Amarelo - Brasil",
|
20
|
+
quantity: 1,
|
21
|
+
detail: "Seleção Brasileira",
|
22
|
+
price: 2000,
|
23
|
+
},
|
25
24
|
],
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
customer: {
|
26
|
+
ownId: "customer[1234]",
|
27
|
+
fullname: "Joao Sousa",
|
28
|
+
email: "joao.sousa@email.com",
|
29
|
+
birthDate: "1988-12-30",
|
30
|
+
taxDocument: {
|
31
|
+
type: "CPF",
|
32
|
+
number: "22222222222",
|
34
33
|
},
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
phone: {
|
35
|
+
countryCode: "55",
|
36
|
+
areaCode: "11",
|
37
|
+
number: "66778899",
|
39
38
|
},
|
40
|
-
|
39
|
+
addresses: [
|
41
40
|
{
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
52
|
-
]
|
41
|
+
type: "BILLING",
|
42
|
+
street: "Avenida Faria Lima",
|
43
|
+
streetNumber: 2927,
|
44
|
+
complement: 8,
|
45
|
+
district: "Itaim",
|
46
|
+
city: "Sao Paulo",
|
47
|
+
state: "SP",
|
48
|
+
country: "BRA",
|
49
|
+
zipCode: "01234000",
|
50
|
+
},
|
51
|
+
],
|
53
52
|
},
|
54
|
-
|
53
|
+
receivers: [
|
55
54
|
{
|
56
|
-
|
57
|
-
|
55
|
+
moipAccount: {
|
56
|
+
id: "MPA-1K2R51KFL3OY",
|
58
57
|
},
|
59
|
-
|
60
|
-
}
|
61
|
-
]
|
58
|
+
type: "PRIMARY",
|
59
|
+
},
|
60
|
+
],
|
62
61
|
},
|
63
62
|
{
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
63
|
+
ownId: "pedido_2_id",
|
64
|
+
amount: {
|
65
|
+
currency: "BRL",
|
66
|
+
subtotals: {
|
67
|
+
shipping: 3000,
|
68
|
+
},
|
70
69
|
},
|
71
|
-
|
70
|
+
items: [
|
72
71
|
{
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
72
|
+
product: "Camisa Preta - Alemanha",
|
73
|
+
quantity: 1,
|
74
|
+
detail: "Camiseta da Copa 2014",
|
75
|
+
price: 1000,
|
76
|
+
},
|
78
77
|
],
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
customer: {
|
79
|
+
ownId: "customer[1234]",
|
80
|
+
fullname: "Joao Sousa",
|
81
|
+
email: "joao.sousa@email.com",
|
82
|
+
birthDate: "1988-12-30",
|
83
|
+
taxDocument: {
|
84
|
+
type: "CPF",
|
85
|
+
number: "22222222222",
|
87
86
|
},
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
phone: {
|
88
|
+
countryCode: "55",
|
89
|
+
areaCode: "11",
|
90
|
+
number: "66778899",
|
92
91
|
},
|
93
|
-
|
92
|
+
addresses: [
|
94
93
|
{
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
]
|
94
|
+
type: "BILLING",
|
95
|
+
street: "Avenida Faria Lima",
|
96
|
+
streetNumber: 2927,
|
97
|
+
complement: 8,
|
98
|
+
district: "Itaim",
|
99
|
+
city: "Sao Paulo",
|
100
|
+
state: "SP",
|
101
|
+
country: "BRA",
|
102
|
+
zipCode: "01234000",
|
103
|
+
},
|
104
|
+
],
|
106
105
|
},
|
107
|
-
|
106
|
+
receivers: [
|
108
107
|
{
|
109
|
-
|
110
|
-
|
108
|
+
moipAccount: {
|
109
|
+
id: "MPA-IFYRB1HBL73Z",
|
111
110
|
},
|
112
|
-
|
111
|
+
type: "PRIMARY",
|
113
112
|
},
|
114
113
|
{
|
115
|
-
|
116
|
-
|
114
|
+
moipAccount: {
|
115
|
+
id: "MPA-KQB1QFWS6QNM",
|
116
|
+
},
|
117
|
+
type: "SECONDARY",
|
118
|
+
amount: {
|
119
|
+
fixed: 55,
|
117
120
|
},
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
]
|
124
|
-
}
|
125
|
-
]
|
126
|
-
}
|
121
|
+
},
|
122
|
+
],
|
123
|
+
},
|
124
|
+
],
|
125
|
+
}
|
127
126
|
end
|
128
127
|
|
129
128
|
let(:created_multi_order) do
|
@@ -144,7 +143,6 @@ describe Moip2::MultiOrderApi do
|
|
144
143
|
end
|
145
144
|
|
146
145
|
context "when validation error" do
|
147
|
-
|
148
146
|
let(:created_multi_order) do
|
149
147
|
VCR.use_cassette("create_multi_order_fail") do
|
150
148
|
multi_order_api.create({})
|
@@ -162,13 +160,10 @@ describe Moip2::MultiOrderApi do
|
|
162
160
|
expect(created_multi_order.errors[0].path).to_not be_nil
|
163
161
|
expect(created_multi_order.errors[0].description).to_not be_nil
|
164
162
|
end
|
165
|
-
|
166
163
|
end
|
167
|
-
|
168
164
|
end
|
169
165
|
|
170
166
|
describe "#show" do
|
171
|
-
|
172
167
|
let(:multi_order) do
|
173
168
|
VCR.use_cassette("show_multi_order") do
|
174
169
|
multi_order_api.show("MOR-IVKZDU55LXJU")
|
@@ -180,7 +175,6 @@ describe Moip2::MultiOrderApi do
|
|
180
175
|
end
|
181
176
|
|
182
177
|
context "when multi order not found" do
|
183
|
-
|
184
178
|
let(:multi_order) do
|
185
179
|
VCR.use_cassette("show_multi_order_not_found") do
|
186
180
|
multi_order_api.show("MOR-INVALID")
|
@@ -190,9 +184,6 @@ describe Moip2::MultiOrderApi do
|
|
190
184
|
it "raises a NotFound" do
|
191
185
|
expect { multi_order }.to raise_error Moip2::NotFoundError
|
192
186
|
end
|
193
|
-
|
194
187
|
end
|
195
|
-
|
196
188
|
end
|
197
|
-
|
198
|
-
end
|
189
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Moip2::MultiPaymentApi do
|
2
2
|
let(:multi_payment_api) { described_class.new(sandbox_client) }
|
3
3
|
|
4
|
-
describe "#create" do
|
4
|
+
describe "#create" do
|
5
5
|
let(:multi_payment) do
|
6
6
|
{
|
7
7
|
installmentCount: 1,
|
@@ -17,16 +17,16 @@ describe Moip2::MultiPaymentApi do
|
|
17
17
|
birthdate: "1988-12-30",
|
18
18
|
taxDocument: {
|
19
19
|
type: "CPF",
|
20
|
-
number: "33333333333"
|
20
|
+
number: "33333333333",
|
21
21
|
},
|
22
22
|
phone: {
|
23
23
|
countryCode: "55",
|
24
24
|
areaCode: "11",
|
25
|
-
number: "66778899"
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
}
|
25
|
+
number: "66778899",
|
26
|
+
},
|
27
|
+
},
|
28
|
+
},
|
29
|
+
},
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
@@ -41,7 +41,6 @@ describe Moip2::MultiPaymentApi do
|
|
41
41
|
expect(created_multi_payment.payments).to_not be_nil
|
42
42
|
expect(created_multi_payment.status).to eq "WAITING"
|
43
43
|
end
|
44
|
-
|
45
44
|
end
|
46
45
|
|
47
46
|
describe "#show" do
|
@@ -56,7 +55,5 @@ describe Moip2::MultiPaymentApi do
|
|
56
55
|
expect(multi_payment.payments).to_not be_nil
|
57
56
|
expect(multi_payment.status).to eq "AUTHORIZED"
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
61
|
-
|
62
|
-
end
|
59
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
describe Moip2::NotificationsApi do
|
2
|
+
let(:notifications_api) { described_class.new(sandbox_client) }
|
3
|
+
|
4
|
+
describe "#create" do
|
5
|
+
let (:notification) do
|
6
|
+
{
|
7
|
+
events: ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"],
|
8
|
+
target: "http://requestb.in/1dhjesw1",
|
9
|
+
media: "WEBHOOK",
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:notification_created) do
|
14
|
+
VCR.use_cassette("create_notification") do
|
15
|
+
notifications_api.create(notification)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect(notification_created.id).to_not be_nil }
|
20
|
+
it { expect(notification_created.media).to eq "WEBHOOK" }
|
21
|
+
it { expect(notification_created.target).to eq "http://requestb.in/1dhjesw1" }
|
22
|
+
it {
|
23
|
+
expect(notification_created.events).to (
|
24
|
+
eq ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"]
|
25
|
+
)
|
26
|
+
}
|
27
|
+
it { expect(notification_created.token).to_not be_nil }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#create to apps" do
|
31
|
+
let (:notification) do
|
32
|
+
{
|
33
|
+
events: ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"],
|
34
|
+
target: "http://requestb.in/1dhjesw1",
|
35
|
+
media: "WEBHOOK",
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:notification_created) do
|
40
|
+
VCR.use_cassette("create_notification_app") do
|
41
|
+
notifications_api.create(notification, "APP-Y0YCCJ5P603B")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it { expect(notification_created.id).to_not be_nil }
|
46
|
+
it { expect(notification_created.media).to eq "WEBHOOK" }
|
47
|
+
it { expect(notification_created.target).to eq "http://requestb.in/1dhjesw1" }
|
48
|
+
it {
|
49
|
+
expect(notification_created.events).to (
|
50
|
+
eq ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"]
|
51
|
+
)
|
52
|
+
}
|
53
|
+
it { expect(notification_created.token).to_not be_nil }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#show" do
|
57
|
+
let(:notification_id) { "NPR-1EICPJBCFS4J" }
|
58
|
+
|
59
|
+
let(:notification) do
|
60
|
+
VCR.use_cassette("get_notification") do
|
61
|
+
notifications_api.show(notification_id)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it { expect(notification.id).to eq notification_id }
|
66
|
+
it { expect(notification.media).to eq "WEBHOOK" }
|
67
|
+
it { expect(notification.target).to eq "http://requestb.in/1dhjesw1" }
|
68
|
+
it { expect(notification.events).to eq ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"] }
|
69
|
+
it { expect(notification.token).to eq "5877e87109cc4ef6ae9b1a181cf8a276" }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#find all" do
|
73
|
+
let(:notifications) do
|
74
|
+
VCR.use_cassette("get_notifications_list") do
|
75
|
+
notifications_api.find_all
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it { expect(notifications).to be_a(Moip2::Resource::Notification) }
|
80
|
+
it { expect(notifications).to_not be_nil }
|
81
|
+
it { expect(notifications[0]["media"]).to eq "WEBHOOK" }
|
82
|
+
it { expect(notifications[0]["target"]).to eq "pandaofertas.com/receive/receiver.php" }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#delete" do
|
86
|
+
let(:response) do
|
87
|
+
VCR.use_cassette("delete_notification") do
|
88
|
+
notifications_api.delete("NPR-NI9P75W67ZK7")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it { expect(response).to eq true }
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#delete nonexistent notification" do
|
96
|
+
let(:response) do
|
97
|
+
VCR.use_cassette("delete_nonexistent_notification") do
|
98
|
+
notifications_api.delete("NPR-NI9P75W68ZK7")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it { expect { response }.to raise_error(Moip2::NotFoundError) }
|
103
|
+
end
|
104
|
+
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
describe Moip2::OrderApi do
|
2
|
-
|
3
|
-
let(:order_api) { described_class.new(sandbox_client) }
|
2
|
+
let(:order_api) { described_class.new(sandbox_client) }
|
4
3
|
|
5
4
|
describe "#create" do
|
6
|
-
|
7
5
|
let(:order) do
|
8
6
|
{
|
9
7
|
own_id: "your_own_id_1",
|
10
8
|
amount: {
|
11
|
-
currency: "BRL"
|
9
|
+
currency: "BRL",
|
12
10
|
},
|
13
11
|
items: [
|
14
12
|
{
|
15
13
|
product: "Some Product",
|
16
14
|
quantity: 1,
|
17
15
|
detail: "Some Product Detail",
|
18
|
-
price: 100
|
19
|
-
}
|
16
|
+
price: 100,
|
17
|
+
},
|
20
18
|
],
|
21
19
|
customer: {
|
22
20
|
own_id: "your_customer_own_id",
|
@@ -25,7 +23,7 @@ describe Moip2::OrderApi do
|
|
25
23
|
birthdate: "1988-11-11",
|
26
24
|
tax_document: { number: "22222222222", type: "CPF" },
|
27
25
|
phone: { country_code: "55", area_code: "11", number: "5566778899" },
|
28
|
-
shipping_address:
|
26
|
+
shipping_address:
|
29
27
|
{
|
30
28
|
street: "Avenida Faria Lima",
|
31
29
|
street_number: 2927,
|
@@ -34,9 +32,9 @@ describe Moip2::OrderApi do
|
|
34
32
|
city: "Sao Paulo",
|
35
33
|
state: "SP",
|
36
34
|
country: "BRA",
|
37
|
-
zip_code: "01234000"
|
38
|
-
}
|
39
|
-
}
|
35
|
+
zip_code: "01234000",
|
36
|
+
},
|
37
|
+
},
|
40
38
|
}
|
41
39
|
end
|
42
40
|
|
@@ -66,17 +64,19 @@ describe Moip2::OrderApi do
|
|
66
64
|
expect(created_order.amount.subtotals.discount).to eq(0)
|
67
65
|
expect(created_order.amount.subtotals.items).to eq(100)
|
68
66
|
|
69
|
-
expect(created_order.items[0].product).to eq("Some Product")
|
70
|
-
expect(created_order.items[0].price).to eq(100)
|
67
|
+
expect(created_order.items[0].product).to eq("Some Product")
|
68
|
+
expect(created_order.items[0].price).to eq(100)
|
71
69
|
expect(created_order.items[0].detail).to eq("Some Product Detail")
|
72
70
|
expect(created_order.items[0].quantity).to eq(1)
|
73
|
-
|
71
|
+
|
74
72
|
expect(created_order.customer.id).to eq("CUS-B6LE6HLFFXKF")
|
75
73
|
|
76
74
|
expect(created_order.customer.shipping_address).to_not be_nil
|
77
75
|
|
78
76
|
expect(created_order.customer._links).to_not be_nil
|
79
|
-
expect(
|
77
|
+
expect(
|
78
|
+
created_order.customer._links.self.href,
|
79
|
+
).to eq "#{ENV['sandbox_url']}/v2/customers/CUS-B6LE6HLFFXKF"
|
80
80
|
end
|
81
81
|
|
82
82
|
it "returns an Order object" do
|
@@ -84,7 +84,6 @@ describe Moip2::OrderApi do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
context "when validation error" do
|
87
|
-
|
88
87
|
let(:created_order) do
|
89
88
|
VCR.use_cassette("create_order_fail") do
|
90
89
|
order_api.create({})
|
@@ -102,13 +101,10 @@ describe Moip2::OrderApi do
|
|
102
101
|
expect(created_order.errors[0].path).to_not be_nil
|
103
102
|
expect(created_order.errors[0].description).to_not be_nil
|
104
103
|
end
|
105
|
-
|
106
104
|
end
|
107
|
-
|
108
105
|
end
|
109
106
|
|
110
107
|
describe "#show" do
|
111
|
-
|
112
108
|
let(:order) do
|
113
109
|
VCR.use_cassette("show_order") do
|
114
110
|
order_api.show("ORD-EQE16JGCM52O")
|
@@ -120,7 +116,6 @@ describe Moip2::OrderApi do
|
|
120
116
|
end
|
121
117
|
|
122
118
|
context "when order not found" do
|
123
|
-
|
124
119
|
let(:order) do
|
125
120
|
VCR.use_cassette("show_order_not_found") do
|
126
121
|
order_api.show("ORD-INVALID")
|
@@ -130,9 +125,94 @@ describe Moip2::OrderApi do
|
|
130
125
|
it "raises a NotFound" do
|
131
126
|
expect { order }.to raise_error Moip2::NotFoundError
|
132
127
|
end
|
128
|
+
end
|
129
|
+
end
|
133
130
|
|
131
|
+
describe "#find_all" do
|
132
|
+
context "when passing no filters" do
|
133
|
+
subject(:response) do
|
134
|
+
VCR.use_cassette("find_all_orders_no_filter") do
|
135
|
+
order_api.find_all
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it { expect(response).to be_a(Moip2::Resource::Order) }
|
140
|
+
it { expect(response._links).not_to be_nil }
|
141
|
+
it { expect(response.summary).not_to be_nil }
|
142
|
+
it { expect(response.orders.size).to eq(20) }
|
143
|
+
it { expect(response.orders.first).to be_a(Moip2::Resource::Order) }
|
134
144
|
end
|
135
145
|
|
136
|
-
|
146
|
+
context "when passing limit" do
|
147
|
+
subject(:response) do
|
148
|
+
VCR.use_cassette("find_all_orders_limit") do
|
149
|
+
order_api.find_all(limit: 10)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it { expect(response).to be_a(Moip2::Resource::Order) }
|
154
|
+
it { expect(response._links).not_to be_nil }
|
155
|
+
it { expect(response.summary).not_to be_nil }
|
156
|
+
it { expect(response.orders.size).to eq(10) }
|
157
|
+
it { expect(response.orders.first).to be_a(Moip2::Resource::Order) }
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when passing filters" do
|
161
|
+
subject(:response) do
|
162
|
+
VCR.use_cassette("find_all_orders_filters") do
|
163
|
+
order_api.find_all(filters: { status: { in: ["PAID", "WAITING"] } })
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it { expect(response).to be_a(Moip2::Resource::Order) }
|
168
|
+
it { expect(response._links).not_to be_nil }
|
169
|
+
it { expect(response.summary).not_to be_nil }
|
170
|
+
|
171
|
+
it "_links.next has the right filters" do
|
172
|
+
expect(response._links.next.href).to eq(
|
173
|
+
"https://test.moip.com.br/v2/orders?filters=status::in(PAID,WAITING)&limit=0&offset=0",
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "all orders satisfy the filter constraint" do
|
178
|
+
expect(response.orders).to satisfy do |orders|
|
179
|
+
orders.all? { |order| ["PAID", "WAITING"].include?(order.status) }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when passing multiple filters" do
|
185
|
+
subject(:response) do
|
186
|
+
VCR.use_cassette("find_all_orders_multi_filters") do
|
187
|
+
order_api.find_all(filters: {
|
188
|
+
status: { in: ["PAID", "WAITING"] },
|
189
|
+
amount: { bt: [500, 1000] },
|
190
|
+
})
|
191
|
+
end
|
192
|
+
end
|
137
193
|
|
194
|
+
it { expect(response).to be_a(Moip2::Resource::Order) }
|
195
|
+
it { expect(response._links).not_to be_nil }
|
196
|
+
it { expect(response.summary).not_to be_nil }
|
197
|
+
|
198
|
+
it "_links.next has the right filters" do
|
199
|
+
expect(response._links.next.href).to eq(
|
200
|
+
"https://test.moip.com.br/v2/orders?filters=" \
|
201
|
+
"status::in(PAID,WAITING)|amount::bt(500,1000)&limit=0&offset=0",
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "all orders satisfy the status constraint" do
|
206
|
+
expect(response.orders).to satisfy do |orders|
|
207
|
+
orders.all? { |order| ["PAID", "WAITING"].include?(order.status) }
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "all orders satisfy the amount constraint" do
|
212
|
+
expect(response.orders).to satisfy do |orders|
|
213
|
+
orders.all? { |order| order.amount.total.between?(500, 1000) }
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
138
218
|
end
|