fix tests

This commit is contained in:
shibao 2022-04-19 20:08:10 -04:00
parent 9e754fe630
commit 7f9e6f9eff
2 changed files with 51 additions and 56 deletions

View File

@ -5,8 +5,8 @@ defmodule Cannery.Ammo do
import Ecto.Query, warn: false
alias Cannery.{Accounts.User, Containers, Repo}
alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Cannery.ActivityLog.ShotGroup
alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Ecto.Changeset
@ammo_group_create_limit 10_000
@ -45,8 +45,6 @@ defmodule Cannery.Ammo do
@doc """
Gets the average cost of a single ammo type
Raises `Ecto.NoResultsError` if the Ammo type does not exist.
## Examples
iex> get_average_cost_for_ammo_type!(%AmmoType{id: 123}, %User{id: 123})

View File

@ -96,26 +96,28 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
end
defp get_ammo_type_values(ammo_type, columns, current_user) do
assigns = %{ammo_type: ammo_type}
columns
|> Enum.into(%{}, fn %{key: key, type: type} ->
value =
case type do
:boolean ->
ammo_type |> Map.get(key |> String.to_existing_atom()) |> humanize()
{key, get_ammo_type_value(type, key, ammo_type, current_user)}
end)
end
:round_count ->
ammo_type |> Ammo.get_round_count_for_ammo_type(current_user)
defp get_ammo_type_value(:boolean, key, ammo_type, _current_user),
do: ammo_type |> Map.get(key |> String.to_existing_atom()) |> humanize()
:avg_price_paid ->
defp get_ammo_type_value(:round_count, _key, ammo_type, current_user),
do: ammo_type |> Ammo.get_round_count_for_ammo_type(current_user)
defp get_ammo_type_value(:avg_price_paid, _key, ammo_type, current_user) do
case ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user) do
nil -> gettext("No cost information")
count -> gettext("$%{amount}", amount: count |> :erlang.float_to_binary(decimals: 2))
end
end
defp get_ammo_type_value(:actions, _key, ammo_type, _current_user) do
assigns = %{ammo_type: ammo_type}
:actions ->
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
@ -142,15 +144,10 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
<% end %>
</div>
"""
nil ->
nil
_other ->
ammo_type |> Map.get(key |> String.to_existing_atom())
end
{key, value}
end)
end
defp get_ammo_type_value(nil, _key, _ammo_type, _current_user), do: nil
defp get_ammo_type_value(_other, key, ammo_type, _current_user),
do: ammo_type |> Map.get(key |> String.to_existing_atom())
end