File size: 1,282 Bytes
c9c49ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | defmodule Plausible.Billing.PaddleApiTest do
use Plausible.DataCase
import Mox
setup :verify_on_exit!
@success "fixture/paddle_prices_success_response.json" |> File.read!() |> Jason.decode!()
describe "fetch_prices/1" do
test "returns %Money{} structs per product_id when given a list of product_ids" do
expect(
Plausible.HTTPClient.Mock,
:get,
fn "https://checkout.paddle.com/api/2.0/prices" <> query,
[{"content-type", "application/json"}, {"accept", "application/json"}],
_ ->
assert query =~ "product_ids=#{URI.encode_www_form("19878,20127,20657,20658")}"
{:ok,
%Finch.Response{
status: 200,
headers: [{"content-type", "application/json"}],
body: @success
}}
end
)
assert Plausible.Billing.PaddleApi.fetch_prices(
["19878", "20127", "20657", "20658"],
"127.0.0.1"
) ==
{:ok,
%{
"19878" => Money.new(:EUR, "6.0"),
"20127" => Money.new(:EUR, "60.0"),
"20657" => Money.new(:EUR, "12.34"),
"20658" => Money.new(:EUR, "120.34")
}}
end
end
end
|