Skip to content

Commit 3db9c45

Browse files
subpaloyeb
authored andcommitted
Adds authorize integration tests
1. Removed unnecessary test files. 2. Added setup for opts generation. 3. Refactored setup function in tests
1 parent 103dbf3 commit 3db9c45

File tree

4 files changed

+96
-32
lines changed

4 files changed

+96
-32
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

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
defmodule Gringotts.Integration.Gateways.MercadopagoTest do
2+
# Integration tests for the Mercadopago
3+
4+
use ExUnit.Case, async: true
5+
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
6+
7+
alias Gringotts.CreditCard
8+
alias Gringotts.Gateways.Mercadopago, as: Gateway
9+
10+
@moduletag integration: true
11+
12+
@amount Money.new(45, :BRL)
13+
@config [
14+
access_token: "TEST-2774702803649645-031303-1b9d3d63acb57cdad3458d386eee62bd-307592510",
15+
public_key: "TEST-911f45a1-0560-4c16-915e-a8833830b29a"
16+
]
17+
@good_card %CreditCard{
18+
first_name: "Hermoine",
19+
last_name: "Granger",
20+
number: "4509953566233704",
21+
year: 2030,
22+
month: 07,
23+
verification_code: "123",
24+
brand: "VISA"
25+
}
26+
27+
@bad_card %CreditCard{
28+
first_name: "Hermoine",
29+
last_name: "Granger",
30+
number: "4509953566233704",
31+
year: 2000,
32+
month: 07,
33+
verification_code: "123",
34+
brand: "VISA"
35+
}
36+
37+
@opts [
38+
39+
order_id: 123_126,
40+
customer_id: "311211654-YrXF6J0QikpIWX",
41+
config: @config,
42+
installments: 1,
43+
order_type: "mercadopago"
44+
]
45+
@new_cutomer_opts [
46+
order_id: 123_126,
47+
config: @config,
48+
installments: 1,
49+
order_type: "mercadopago"
50+
]
51+
52+
53+
describe "[authorize] old customer" do
54+
test "with good_opts and good_card" do
55+
use_cassette "mercadopago/authorize_old customer with good_opts and good_card" do
56+
assert {:ok, response} = Gateway.authorize(@amount, @good_card, @opts)
57+
assert response.success == true
58+
assert response.status_code == 201
59+
end
60+
end
61+
62+
test "with good_opts and bad_card" do
63+
use_cassette "mercadopago/authorize_old customer with good_opts and bad_card" do
64+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, @opts)
65+
assert response.success == false
66+
assert response.status_code == 400
67+
end
68+
end
69+
end
70+
71+
describe "[authorize] new customer" do
72+
setup do
73+
email = "hp#{:rand.uniform(1_000_00)}#{:rand.uniform(1_000_00)}#{:rand.uniform(1_000_00)}@potter.com"
74+
[opts: [{:email, email} | @new_cutomer_opts]]
75+
end
76+
77+
test "with good_opts and good_card", %{opts: opts} do
78+
use_cassette "mercadopago/authorize_new cutomer with good_opts and good_card" do
79+
assert {:ok, response} = Gateway.authorize(@amount, @good_card, opts)
80+
assert response.success == true
81+
assert response.status_code == 201
82+
end
83+
end
84+
85+
test "with good_opts and bad_card", %{opts: opts} do
86+
use_cassette "mercadopago/authorize_new customer with good_opts and bad_card" do
87+
assert {:error, response} = Gateway.authorize(@amount, @bad_card, opts)
88+
assert response.success == false
89+
assert response.status_code == 400
90+
end
91+
end
92+
end
93+
end

0 commit comments

Comments
 (0)