-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
test/lib/code_corps/stripe/adapters/stripe_account_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |