forked from fixthestatusquo/proca-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignore option to Support.camel_case_keys
- Loading branch information
Showing
3 changed files
with
70 additions
and
7 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
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
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,52 @@ | ||
defmodule Proca.Stage.SupportTest do | ||
use Proca.DataCase | ||
|
||
import Proca.StoryFactory, only: [red_story: 0] | ||
|
||
alias Proca.Stage.Support | ||
|
||
setup do | ||
red_story() | ||
end | ||
|
||
test "camel_case_keys ignores config", %{ | ||
red_campaign: camp, | ||
red_org: org | ||
} do | ||
org_data = %{ | ||
name: org.name, | ||
title: org.title, | ||
config: %{ | ||
some_field: "value", | ||
replace: %{ | ||
"https://example.com/example-candidats" => "https://url.com/other-candidats" | ||
} | ||
} | ||
} | ||
|
||
camp_data = | ||
camp | ||
|> Map.from_struct() | ||
|> Map.replace(:config, %{some_key: "val"}) | ||
|> Map.take([:id, :name, :external_id, :title, :config, :contact_schema]) | ||
|> Map.put(:org, org_data) | ||
|
||
camelized_map = | ||
camp_data | ||
|> Support.camel_case_keys(ignore: :config) | ||
|
||
assert %{ | ||
"externalId" => _, | ||
"contactSchema" => _, | ||
"title" => _, | ||
"config" => %{"some_key" => _}, | ||
"org" => %{ | ||
"name" => _, | ||
"config" => %{ | ||
"some_field" => _, | ||
"replace" => %{"https://example.com/example-candidats" => _} | ||
} | ||
} | ||
} = camelized_map | ||
end | ||
end |