Hi, I am having some difficulty understanding how Jason and ex_money_sql can come together.
Basically my tests look a little weird: (but it is the only way I could make the tests work)
test "this is a test", %{conn: conn} do
assert json == %{
...
"balance" => Money.new(:USD, "0.00") |> Jason.encode |> elem(1) |> Jason.decode |> elem(1),
"escrow" => Money.new(:USD, "0.00") |> Jason.encode |> elem(1) |> Jason.decode |> elem(1),
...
end
The factory is as follows:
def account_factory do
%{
...
balance: Money.new(:USD, "0.00"),
escrow: Money.new(:USD, "0.00"),
...
}
end
The above values are stored correctly in the database as:
balance: (USD,0.00)
escrow: (USD,0.00)
Upon retrieval via JSON in my view:
balance: %{“amount” => “0.00”, “currency” => “USD”}
escrow: %{“amount” => “0.00”, “currency” => “USD”}
Which is as expected.
In my initial test, I assert it against the values of
"balance" => Money.new(:USD, "0.00"),
"escrow" => Money.new(:USD, "0.00"),
Which does not work. It only works if i write the assertion as above but I sense something is clearly wrong here. Will appreciate any directions.
Thank you.
PS: Is my usage of elem(1) correct or is it an antipattern to obtain the value of the second element of a {:ok, _} or {:error, _} tuple.