Skip to content

Commit 8980821

Browse files
committed
Authorize integration test cases created
1 parent 1fa2019 commit 8980821

File tree

5 files changed

+161
-5
lines changed

5 files changed

+161
-5
lines changed

mix.exs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ defmodule Gringotts.Mixfile do
6262
{:mock, "~> 0.3.0", only: :test},
6363
{:bypass, "~> 0.8", only: :test},
6464
{:excoveralls, "~> 0.8", only: :test},
65+
{:exvcr, "~> 0.10", only: :test},
6566

6667
# various analyses tools
6768
{:credo, "~> 0.3", only: [:dev, :test]},

mix.lock

+2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"ex_cldr_numbers": {:hex, :ex_cldr_numbers, "1.3.1", "50a117654dff8f8ee6958e68a65d0c2835a7e2f1aff94c1ea8f582c04fdf0bd4", [:mix], [{:decimal, "~> 1.4", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 1.4.0", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.1 or ~> 3.1", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
1717
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
1818
"ex_money": {:hex, :ex_money, "1.1.3", "843eed0a5673206de33be47cdc06574401abc3e2d33cbcf6d74e160226791ae4", [:mix], [{:decimal, "~> 1.4", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}, {:ex_cldr, "~> 1.0", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 1.0", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}], "hexpm"},
19+
"exactor": {:hex, :exactor, "2.2.4", "5efb4ddeb2c48d9a1d7c9b465a6fffdd82300eb9618ece5d34c3334d5d7245b1", [:mix], [], "hexpm"},
1920
"excoveralls": {:hex, :excoveralls, "0.8.1", "0bbf67f22c7dbf7503981d21a5eef5db8bbc3cb86e70d3798e8c802c74fa5e27", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
2021
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
22+
"exvcr": {:hex, :exvcr, "0.10.0", "5150808404d9f48dbda636f70f7f8fefd93e2433cd39f695f810e73b3a9d1736", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, repo: "hexpm", optional: false]}, {:exjsx, "~> 4.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:httpoison, "~> 0.13", [hex: :httpoison, repo: "hexpm", optional: true]}, {:httpotion, "~> 3.0", [hex: :httpotion, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
2123
"gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
2224
"hackney": {:hex, :hackney, "1.11.0", "4951ee019df102492dabba66a09e305f61919a8a183a7860236c0fde586134b6", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
2325
"httpoison": {:hex, :httpoison, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},

templates/test.eex

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
defmodule Gringotts.Gateways.<%= gateway_module <> "Test" %> do
22
# The file contains mocked tests for <%= gateway_module%>
3-
43
# We recommend using [mock][1] for this, you can place the mock responses from
54
# the Gateway in `test/mocks/<%= mock_response_filename %>` file, which has also been
65
# generated for you.
76
#
87
# [1]: https://github.com/jjh42/mock
9-
8+
109
# Load the mock response file before running the tests.
11-
Code.require_file "../mocks/<%= mock_response_filename %>", __DIR__
12-
10+
Code.require_file("../mocks/mercadopago_mock.exs", __DIR__)
1311
use ExUnit.Case, async: false
1412
alias Gringotts.Gateways.<%= gateway_module%>
1513
import Mock
@@ -21,7 +19,7 @@ defmodule Gringotts.Gateways.<%= gateway_module <> "Test" %> do
2119
describe "authorize" do
2220
end
2321

24-
describe "capture" do
22+
describe "capture" do
2523
end
2624

2725
describe "void" do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
defmodule Gringotts.Integration.Gateways.MercadopagoTest do
2+
# Integration tests for the Mercadopago
3+
4+
use ExUnit.Case, async: false
5+
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
6+
alias Gringotts.Gateways.Mercadopago, as: Gateway
7+
8+
@moduletag integration: true
9+
10+
@amount Money.new(45, :BRL)
11+
@sub_amount Money.new(30, :BRL)
12+
@good_card %Gringotts.CreditCard{
13+
first_name: "Hermoine",
14+
last_name: "Granger",
15+
number: "4509953566233704",
16+
year: 2030,
17+
month: 07,
18+
verification_code: "123",
19+
brand: "VISA"
20+
}
21+
22+
@bad_card %Gringotts.CreditCard{
23+
first_name: "Hermoine",
24+
last_name: "Granger",
25+
number: "4509953566233704",
26+
year: 2000,
27+
month: 07,
28+
verification_code: "123",
29+
brand: "VISA"
30+
}
31+
32+
@good_opts [
33+
34+
order_id: 123_126,
35+
customer_id: "311211654-YrXF6J0QikpIWX",
36+
config: [
37+
access_token: "TEST-2774702803649645-031303-1b9d3d63acb57cdad3458d386eee62bd-307592510",
38+
public_key: "TEST-911f45a1-0560-4c16-915e-a8833830b29a"
39+
],
40+
installments: 1,
41+
order_type: "mercadopago"
42+
]
43+
@new_cutomer_good_opts [
44+
order_id: 123_126,
45+
config: [
46+
access_token: "TEST-2774702803649645-031303-1b9d3d63acb57cdad3458d386eee62bd-307592510",
47+
public_key: "TEST-911f45a1-0560-4c16-915e-a8833830b29a"
48+
],
49+
installments: 1,
50+
order_type: "mercadopago"
51+
]
52+
@new_cutomer_bad_opts [
53+
order_id: 123_126,
54+
config: [public_key: "TEST-911f45a1-0560-4c16-915e-a8833830b29a"],
55+
installments: 1,
56+
order_type: "mercadopago"
57+
]
58+
@bad_opts [
59+
60+
order_id: 123_126,
61+
customer_id: "311211654-YrXF6J0QikpIWX",
62+
config: [public_key: "TEST-911f45a1-0560-4c16-915e-a8833830b29a"],
63+
installments: 1,
64+
order_type: "mercadopago"
65+
]
66+
67+
def new_email_opts(good) do
68+
no1 = :rand.uniform(1_000_00) |> to_string
69+
no2 = :rand.uniform(1_000_00) |> to_string
70+
no3 = :rand.uniform(1_000_00) |> to_string
71+
email = "hp" <> no1 <> no2 <> no3 <> "@potter.com"
72+
73+
case good do
74+
true -> @new_cutomer_good_opts ++ [email: email]
75+
_ -> @new_cutomer_bad_opts ++ [email: email]
76+
end
77+
end
78+
79+
describe "[authorize]" do
80+
test "old customer with good_opts and good_card" do
81+
use_cassette "mercadopago/authorize_old customer with good_opts and good_card" do
82+
assert {:ok, response} = Gateway.authorize(@amount, @good_card, @good_opts)
83+
assert response.success == true
84+
assert response.status_code == 201
85+
end
86+
end
87+
88+
test "old customer with good_opts and bad_card" do
89+
use_cassette "mercadopago/authorize_old customer with good_opts and bad_card" do
90+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, @good_opts)
91+
assert response.success == false
92+
assert response.status_code == 400
93+
end
94+
end
95+
96+
test "old customer with bad_opts and good_card" do
97+
use_cassette "mercadopago/authorize_old customer with bad_opts and good_card" do
98+
assert {:error, response} = Gateway.authorize(@amount, @good_card, @bad_opts)
99+
assert response.success == false
100+
assert response.status_code == 401
101+
end
102+
end
103+
104+
test "old customer with bad_opts and bad_opts" do
105+
use_cassette "mercadopago/authorize_old customer with bad_opts and bad_opts" do
106+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, @bad_opts)
107+
assert response.success == false
108+
assert response.status_code == 400
109+
end
110+
end
111+
112+
test "new cutomer with good_opts and good_card" do
113+
use_cassette "mercadopago/authorize_new cutomer with good_opts and good_card" do
114+
opts = new_email_opts(true)
115+
assert {:ok, response} = Gateway.authorize(@amount, @good_card, opts)
116+
assert response.success == true
117+
assert response.status_code == 201
118+
end
119+
end
120+
121+
test "new customer with good_opts and bad_card" do
122+
use_cassette "mercadopago/authorize_new customer with good_opts and bad_card" do
123+
opts = new_email_opts(true)
124+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, opts)
125+
assert response.success == false
126+
assert response.status_code == 400
127+
end
128+
end
129+
130+
test "new customer with bad_opts and good_card" do
131+
use_cassette "mercadopago/authorize_new customer with bad_opts and good_card" do
132+
opts = new_email_opts(false)
133+
assert {:error, response} = Gateway.authorize(@amount, @good_card, opts)
134+
assert response.success == false
135+
assert response.status_code == 401
136+
end
137+
end
138+
139+
test "new customer with bad_opts and bad_card" do
140+
use_cassette "mercadopago/authorize_new customer with bad_opts and bad_card" do
141+
opts = new_email_opts(false)
142+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, opts)
143+
assert response.success == false
144+
assert response.status_code == 401
145+
end
146+
end
147+
end
148+
end

test/mocks/mercadopago_mock.exs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Gringotts.Gateways.MercadopagoMock do
2+
# The module should include mock responses for test cases in mercadopago_test.exs.
3+
# e.g.
4+
# def successful_purchase do
5+
# {:ok, %HTTPoison.Response{body: ~s[{data: "successful_purchase"}]}
6+
# end
7+
end

0 commit comments

Comments
 (0)