Skip to content

Commit

Permalink
Add adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Oct 24, 2016
1 parent 2daad65 commit ddbaca6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/code_corps/map_utils.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CodeCorps.MapUtils do
def rename(map, old_key, new_key) do
map
|> Map.put(new_key, map |> Map.get(old_key))
|> Map.delete(old_key)
end
end
11 changes: 11 additions & 0 deletions lib/code_corps/stripe/adapters/stripe_account.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule CodeCorps.Stripe.Adapters.StripeAccount do
import CodeCorps.MapUtils, only: [rename: 3]

def params_from_stripe(%{} = stripe_map) do
stripe_map |> rename("id", "id_from_stripe")
end

def params_to_stripe(%{} = ecto_map) do
ecto_map |> rename("id_from_stripe", "id")
end
end
20 changes: 20 additions & 0 deletions test/lib/code_corps/stripe/adapters/stripe_account_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule CodeCorps.Stripe.Adapters.StripeAccountTest do
use ExUnit.Case, async: true

import CodeCorps.Stripe.Adapters.StripeAccount, only: [params_to_stripe: 1, params_from_stripe: 1]

@stripe_map %{"id" => "str_123", "foo" => "bar"}
@local_map %{"id_from_stripe" => "str_123", "foo" => "bar"}

describe "params_from_stripe/1" do
test "converts from stripe map to local properly" do
assert @stripe_map |> params_from_stripe == @local_map
end
end

describe "params_to_stripe/1" do
test "converts from local to stripe map properly" do
assert @local_map |> params_to_stripe == @stripe_map
end
end
end

0 comments on commit ddbaca6

Please sign in to comment.