|
| 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 |
0 commit comments