rename ammo groups to packs
This commit is contained in:
@ -15,20 +15,20 @@ defmodule Cannery.ActivityLogTest do
|
||||
container = container_fixture(current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
|
||||
{1, [%{id: ammo_group_id} = ammo_group]} =
|
||||
ammo_group_fixture(%{count: 25}, ammo_type, container, current_user)
|
||||
{1, [%{id: pack_id} = pack]} =
|
||||
pack_fixture(%{count: 25}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, ammo_group)
|
||||
|> shot_group_fixture(current_user, pack)
|
||||
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
[
|
||||
current_user: current_user,
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
]
|
||||
end
|
||||
@ -48,11 +48,11 @@ defmodule Cannery.ActivityLogTest do
|
||||
end
|
||||
|
||||
test "create_shot_group/3 with valid data creates a shot_group",
|
||||
%{current_user: current_user, ammo_group: ammo_group} do
|
||||
%{current_user: current_user, pack: pack} do
|
||||
valid_attrs = %{count: 10, date: ~D[2022-02-13], notes: "some notes"}
|
||||
|
||||
assert {:ok, %ShotGroup{} = shot_group} =
|
||||
ActivityLog.create_shot_group(valid_attrs, current_user, ammo_group)
|
||||
ActivityLog.create_shot_group(valid_attrs, current_user, pack)
|
||||
|
||||
assert shot_group.count == 10
|
||||
assert shot_group.date == ~D[2022-02-13]
|
||||
@ -62,46 +62,45 @@ defmodule Cannery.ActivityLogTest do
|
||||
test "create_shot_group/3 removes corresponding count from ammo group",
|
||||
%{
|
||||
current_user: current_user,
|
||||
ammo_group: %{id: ammo_group_id, count: org_count} = ammo_group
|
||||
pack: %{id: pack_id, count: org_count} = pack
|
||||
} do
|
||||
valid_attrs = %{count: 10, date: ~D[2022-02-13], notes: "some notes"}
|
||||
|
||||
assert {:ok, %ShotGroup{} = shot_group} =
|
||||
ActivityLog.create_shot_group(valid_attrs, current_user, ammo_group)
|
||||
ActivityLog.create_shot_group(valid_attrs, current_user, pack)
|
||||
|
||||
%{count: new_count} = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
%{count: new_count} = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert org_count - shot_group.count == new_count
|
||||
assert new_count == 10
|
||||
end
|
||||
|
||||
test "create_shot_group/3 does not remove more than ammo group amount",
|
||||
%{current_user: current_user, ammo_group: %{id: ammo_group_id} = ammo_group} do
|
||||
%{current_user: current_user, pack: %{id: pack_id} = pack} do
|
||||
valid_attrs = %{count: 20, date: ~D[2022-02-13], notes: "some notes"}
|
||||
|
||||
assert {:ok, %ShotGroup{}} =
|
||||
ActivityLog.create_shot_group(valid_attrs, current_user, ammo_group)
|
||||
assert {:ok, %ShotGroup{}} = ActivityLog.create_shot_group(valid_attrs, current_user, pack)
|
||||
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert ammo_group.count == 0
|
||||
assert pack.count == 0
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
ActivityLog.create_shot_group(%{count: 1}, current_user, ammo_group)
|
||||
ActivityLog.create_shot_group(%{count: 1}, current_user, pack)
|
||||
end
|
||||
|
||||
test "create_shot_group/3 with invalid data returns error changeset",
|
||||
%{current_user: current_user, ammo_group: ammo_group} do
|
||||
%{current_user: current_user, pack: pack} do
|
||||
invalid_params = %{count: nil, date: nil, notes: nil}
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
ActivityLog.create_shot_group(invalid_params, current_user, ammo_group)
|
||||
ActivityLog.create_shot_group(invalid_params, current_user, pack)
|
||||
end
|
||||
|
||||
test "update_shot_group/3 with valid data updates the shot_group and ammo_group",
|
||||
test "update_shot_group/3 with valid data updates the shot_group and pack",
|
||||
%{
|
||||
shot_group: shot_group,
|
||||
ammo_group: %{id: ammo_group_id},
|
||||
pack: %{id: pack_id},
|
||||
current_user: current_user
|
||||
} do
|
||||
assert {:ok, %ShotGroup{} = shot_group} =
|
||||
@ -115,10 +114,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
current_user
|
||||
)
|
||||
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert shot_group.count == 10
|
||||
assert ammo_group.count == 15
|
||||
assert pack.count == 15
|
||||
assert shot_group.date == ~D[2022-02-13]
|
||||
assert shot_group.notes == "some updated notes"
|
||||
|
||||
@ -133,10 +132,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
current_user
|
||||
)
|
||||
|
||||
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert shot_group.count == 25
|
||||
assert ammo_group.count == 0
|
||||
assert pack.count == 0
|
||||
end
|
||||
|
||||
test "update_shot_group/3 with invalid data returns error changeset",
|
||||
@ -159,10 +158,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
end
|
||||
|
||||
test "delete_shot_group/2 deletes the shot_group and adds value back",
|
||||
%{shot_group: shot_group, current_user: current_user, ammo_group: %{id: ammo_group_id}} do
|
||||
%{shot_group: shot_group, current_user: current_user, pack: %{id: pack_id}} do
|
||||
assert {:ok, %ShotGroup{}} = ActivityLog.delete_shot_group(shot_group, current_user)
|
||||
|
||||
assert %{count: 25} = ammo_group_id |> Ammo.get_ammo_group!(current_user)
|
||||
assert %{count: 25} = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
ActivityLog.get_shot_group!(shot_group.id, current_user)
|
||||
@ -170,123 +169,123 @@ defmodule Cannery.ActivityLogTest do
|
||||
end
|
||||
|
||||
test "get_used_count/2 returns accurate used count", %{
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [another_ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
|
||||
assert 0 = another_ammo_group |> ActivityLog.get_used_count(current_user)
|
||||
assert 5 = ammo_group |> ActivityLog.get_used_count(current_user)
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
|
||||
assert 5 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 15}, current_user, ammo_group)
|
||||
assert 20 = ammo_group |> ActivityLog.get_used_count(current_user)
|
||||
shot_group_fixture(%{count: 15}, current_user, pack)
|
||||
assert 20 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 10}, current_user, ammo_group)
|
||||
assert 30 = ammo_group |> ActivityLog.get_used_count(current_user)
|
||||
shot_group_fixture(%{count: 10}, current_user, pack)
|
||||
assert 30 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
{1, [another_ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
|
||||
assert 0 = another_ammo_group |> ActivityLog.get_used_count(current_user)
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
|
||||
end
|
||||
|
||||
test "get_used_counts/2 returns accurate used counts", %{
|
||||
ammo_group: %{id: ammo_group_id} = ammo_group,
|
||||
pack: %{id: pack_id} = pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [%{id: another_ammo_group_id} = another_ammo_group]} =
|
||||
ammo_group_fixture(ammo_type, container, current_user)
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
pack_fixture(ammo_type, container, current_user)
|
||||
|
||||
assert %{ammo_group_id => 5} ==
|
||||
[ammo_group, another_ammo_group] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{pack_id => 5} ==
|
||||
[pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, another_ammo_group)
|
||||
used_counts = [ammo_group, another_ammo_group] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^ammo_group_id => 5} = used_counts
|
||||
assert %{^another_ammo_group_id => 5} = used_counts
|
||||
shot_group_fixture(%{count: 5}, current_user, another_pack)
|
||||
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^pack_id => 5} = used_counts
|
||||
assert %{^another_pack_id => 5} = used_counts
|
||||
|
||||
shot_group_fixture(%{count: 15}, current_user, ammo_group)
|
||||
used_counts = [ammo_group, another_ammo_group] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^ammo_group_id => 20} = used_counts
|
||||
assert %{^another_ammo_group_id => 5} = used_counts
|
||||
shot_group_fixture(%{count: 15}, current_user, pack)
|
||||
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^pack_id => 20} = used_counts
|
||||
assert %{^another_pack_id => 5} = used_counts
|
||||
|
||||
shot_group_fixture(%{count: 10}, current_user, ammo_group)
|
||||
used_counts = [ammo_group, another_ammo_group] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^ammo_group_id => 30} = used_counts
|
||||
assert %{^another_ammo_group_id => 5} = used_counts
|
||||
shot_group_fixture(%{count: 10}, current_user, pack)
|
||||
used_counts = [pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
assert %{^pack_id => 30} = used_counts
|
||||
assert %{^another_pack_id => 5} = used_counts
|
||||
end
|
||||
|
||||
test "get_last_used_date/2 returns accurate used count", %{
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
shot_group: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [another_ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
|
||||
assert another_ammo_group |> ActivityLog.get_last_used_date(current_user) |> is_nil()
|
||||
assert ^date = ammo_group |> ActivityLog.get_last_used_date(current_user)
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
assert another_pack |> ActivityLog.get_last_used_date(current_user) |> is_nil()
|
||||
assert ^date = pack |> ActivityLog.get_last_used_date(current_user)
|
||||
|
||||
%{date: date} = shot_group_fixture(%{date: ~D[2022-11-10]}, current_user, ammo_group)
|
||||
assert ^date = ammo_group |> ActivityLog.get_last_used_date(current_user)
|
||||
%{date: date} = shot_group_fixture(%{date: ~D[2022-11-10]}, current_user, pack)
|
||||
assert ^date = pack |> ActivityLog.get_last_used_date(current_user)
|
||||
|
||||
%{date: date} = shot_group_fixture(%{date: ~D[2022-11-11]}, current_user, ammo_group)
|
||||
assert ^date = ammo_group |> ActivityLog.get_last_used_date(current_user)
|
||||
%{date: date} = shot_group_fixture(%{date: ~D[2022-11-11]}, current_user, pack)
|
||||
assert ^date = pack |> ActivityLog.get_last_used_date(current_user)
|
||||
end
|
||||
|
||||
test "get_last_used_dates/2 returns accurate used counts", %{
|
||||
ammo_group: %{id: ammo_group_id} = ammo_group,
|
||||
pack: %{id: pack_id} = pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
shot_group: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [%{id: another_ammo_group_id} = another_ammo_group]} =
|
||||
ammo_group_fixture(ammo_type, container, current_user)
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
pack_fixture(ammo_type, container, current_user)
|
||||
|
||||
# unset date
|
||||
assert %{ammo_group_id => date} ==
|
||||
[ammo_group, another_ammo_group] |> ActivityLog.get_last_used_dates(current_user)
|
||||
assert %{pack_id => date} ==
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
shot_group_fixture(%{date: ~D[2022-11-09]}, current_user, another_ammo_group)
|
||||
shot_group_fixture(%{date: ~D[2022-11-09]}, current_user, another_pack)
|
||||
|
||||
# setting initial date
|
||||
last_used_shot_groups =
|
||||
[ammo_group, another_ammo_group] |> ActivityLog.get_last_used_dates(current_user)
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^ammo_group_id => ^date} = last_used_shot_groups
|
||||
assert %{^another_ammo_group_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ^date} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
|
||||
# setting another date
|
||||
shot_group_fixture(%{date: ~D[2022-11-10]}, current_user, ammo_group)
|
||||
shot_group_fixture(%{date: ~D[2022-11-10]}, current_user, pack)
|
||||
|
||||
last_used_shot_groups =
|
||||
[ammo_group, another_ammo_group] |> ActivityLog.get_last_used_dates(current_user)
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^ammo_group_id => ~D[2022-11-10]} = last_used_shot_groups
|
||||
assert %{^another_ammo_group_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ~D[2022-11-10]} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
|
||||
# setting yet another date
|
||||
shot_group_fixture(%{date: ~D[2022-11-11]}, current_user, ammo_group)
|
||||
shot_group_fixture(%{date: ~D[2022-11-11]}, current_user, pack)
|
||||
|
||||
last_used_shot_groups =
|
||||
[ammo_group, another_ammo_group] |> ActivityLog.get_last_used_dates(current_user)
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^ammo_group_id => ~D[2022-11-11]} = last_used_shot_groups
|
||||
assert %{^another_ammo_group_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ~D[2022-11-11]} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
end
|
||||
|
||||
test "get_used_count_for_ammo_type/2 gets accurate used round count for ammo type",
|
||||
%{ammo_type: ammo_type, ammo_group: ammo_group, current_user: current_user} do
|
||||
%{ammo_type: ammo_type, pack: pack, current_user: current_user} do
|
||||
another_ammo_type = ammo_type_fixture(current_user)
|
||||
assert 0 = another_ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
assert 5 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
assert 10 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 1}, current_user, pack)
|
||||
assert 11 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
end
|
||||
|
||||
@ -297,14 +296,14 @@ defmodule Cannery.ActivityLogTest do
|
||||
} do
|
||||
# testing unused ammo type
|
||||
%{id: another_ammo_type_id} = another_ammo_type = ammo_type_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(another_ammo_type, container, current_user)
|
||||
{1, [pack]} = pack_fixture(another_ammo_type, container, current_user)
|
||||
|
||||
assert %{ammo_type_id => 5} ==
|
||||
[ammo_type, another_ammo_type]
|
||||
|> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
|
||||
# use generated ammo group
|
||||
shot_group_fixture(%{count: 5}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
@ -313,7 +312,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
assert %{^another_ammo_type_id => 5} = used_counts
|
||||
|
||||
# use generated ammo group again
|
||||
shot_group_fixture(%{count: 1}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 1}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
@ -328,13 +327,13 @@ defmodule Cannery.ActivityLogTest do
|
||||
current_user = user_fixture()
|
||||
container = container_fixture(current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
|
||||
[
|
||||
current_user: current_user,
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group
|
||||
pack: pack
|
||||
]
|
||||
end
|
||||
|
||||
@ -345,21 +344,21 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
for class <- ["rifle", "shotgun", "pistol"] do
|
||||
other_ammo_type = ammo_type_fixture(%{class: class}, other_user)
|
||||
{1, [other_ammo_group]} = ammo_group_fixture(other_ammo_type, other_container, other_user)
|
||||
shot_group_fixture(other_user, other_ammo_group)
|
||||
{1, [other_pack]} = pack_fixture(other_ammo_type, other_container, other_user)
|
||||
shot_group_fixture(other_user, other_pack)
|
||||
end
|
||||
|
||||
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_ammo_type, container, current_user)
|
||||
rifle_shot_group = shot_group_fixture(current_user, rifle_ammo_group)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_ammo_type, container, current_user)
|
||||
rifle_shot_group = shot_group_fixture(current_user, rifle_pack)
|
||||
|
||||
shotgun_ammo_type = ammo_type_fixture(%{class: :shotgun}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_ammo_type, container, current_user)
|
||||
shotgun_shot_group = shot_group_fixture(current_user, shotgun_ammo_group)
|
||||
{1, [shotgun_pack]} = pack_fixture(shotgun_ammo_type, container, current_user)
|
||||
shotgun_shot_group = shot_group_fixture(current_user, shotgun_pack)
|
||||
|
||||
pistol_ammo_type = ammo_type_fixture(%{class: :pistol}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_ammo_type, container, current_user)
|
||||
pistol_shot_group = shot_group_fixture(current_user, pistol_ammo_group)
|
||||
{1, [pistol_pack]} = pack_fixture(pistol_ammo_type, container, current_user)
|
||||
pistol_shot_group = shot_group_fixture(current_user, pistol_pack)
|
||||
|
||||
assert [^rifle_shot_group] = ActivityLog.list_shot_groups(:rifle, current_user)
|
||||
assert [^shotgun_shot_group] = ActivityLog.list_shot_groups(:shotgun, current_user)
|
||||
@ -380,32 +379,30 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
test "list_shot_groups/3 returns relevant shot_groups for a search", %{
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
shot_group_a = shot_group_fixture(%{notes: "amazing"}, current_user, ammo_group)
|
||||
shot_group_a = shot_group_fixture(%{notes: "amazing"}, current_user, pack)
|
||||
|
||||
{1, [another_ammo_group]} =
|
||||
ammo_group_fixture(%{notes: "stupendous"}, ammo_type, container, current_user)
|
||||
{1, [another_pack]} =
|
||||
pack_fixture(%{notes: "stupendous"}, ammo_type, container, current_user)
|
||||
|
||||
shot_group_b = shot_group_fixture(current_user, another_ammo_group)
|
||||
shot_group_b = shot_group_fixture(current_user, another_pack)
|
||||
|
||||
another_ammo_type = ammo_type_fixture(%{name: "fabulous ammo"}, current_user)
|
||||
|
||||
{1, [yet_another_ammo_group]} =
|
||||
ammo_group_fixture(another_ammo_type, container, current_user)
|
||||
{1, [yet_another_pack]} = pack_fixture(another_ammo_type, container, current_user)
|
||||
|
||||
shot_group_c = shot_group_fixture(current_user, yet_another_ammo_group)
|
||||
shot_group_c = shot_group_fixture(current_user, yet_another_pack)
|
||||
|
||||
another_user = user_fixture()
|
||||
another_container = container_fixture(another_user)
|
||||
another_ammo_type = ammo_type_fixture(another_user)
|
||||
|
||||
{1, [another_ammo_group]} =
|
||||
ammo_group_fixture(another_ammo_type, another_container, another_user)
|
||||
{1, [another_pack]} = pack_fixture(another_ammo_type, another_container, another_user)
|
||||
|
||||
_shouldnt_return = shot_group_fixture(another_user, another_ammo_group)
|
||||
_shouldnt_return = shot_group_fixture(another_user, another_pack)
|
||||
|
||||
# notes
|
||||
assert ActivityLog.list_shot_groups("amazing", :all, current_user) == [shot_group_a]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,13 +15,13 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
container = container_fixture(current_user)
|
||||
tag = tag_fixture(current_user)
|
||||
Containers.add_tag!(container, tag, current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
|
||||
%{
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
container: container,
|
||||
shot_group: shot_group,
|
||||
tag: tag
|
||||
@ -36,24 +36,24 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
current_user: current_user,
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
shot_group: shot_group,
|
||||
tag: tag
|
||||
} do
|
||||
conn = get(conn, Routes.export_path(conn, :export, :json))
|
||||
|
||||
ideal_ammo_group = %{
|
||||
"ammo_type_id" => ammo_group.ammo_type_id,
|
||||
"container_id" => ammo_group.container_id,
|
||||
"count" => ammo_group.count,
|
||||
"id" => ammo_group.id,
|
||||
"notes" => ammo_group.notes,
|
||||
"price_paid" => ammo_group.price_paid,
|
||||
"staged" => ammo_group.staged,
|
||||
"used_count" => ammo_group |> ActivityLog.get_used_count(current_user),
|
||||
"original_count" => ammo_group |> Ammo.get_original_count(current_user),
|
||||
"cpr" => ammo_group |> Ammo.get_cpr(current_user),
|
||||
"percentage_remaining" => ammo_group |> Ammo.get_percentage_remaining(current_user)
|
||||
ideal_pack = %{
|
||||
"ammo_type_id" => pack.ammo_type_id,
|
||||
"container_id" => pack.container_id,
|
||||
"count" => pack.count,
|
||||
"id" => pack.id,
|
||||
"notes" => pack.notes,
|
||||
"price_paid" => pack.price_paid,
|
||||
"staged" => pack.staged,
|
||||
"used_count" => pack |> ActivityLog.get_used_count(current_user),
|
||||
"original_count" => pack |> Ammo.get_original_count(current_user),
|
||||
"cpr" => pack |> Ammo.get_cpr(current_user),
|
||||
"percentage_remaining" => pack |> Ammo.get_percentage_remaining(current_user)
|
||||
}
|
||||
|
||||
ideal_ammo_type = %{
|
||||
@ -82,9 +82,8 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
"average_cost" => ammo_type |> Ammo.get_average_cost_for_ammo_type(current_user),
|
||||
"round_count" => ammo_type |> Ammo.get_round_count_for_ammo_type(current_user),
|
||||
"used_count" => ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user),
|
||||
"ammo_group_count" => ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user),
|
||||
"total_ammo_group_count" =>
|
||||
ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user, true)
|
||||
"pack_count" => ammo_type |> Ammo.get_packs_count_for_type(current_user),
|
||||
"total_pack_count" => ammo_type |> Ammo.get_packs_count_for_type(current_user, true)
|
||||
}
|
||||
|
||||
ideal_container = %{
|
||||
@ -101,13 +100,12 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
}
|
||||
],
|
||||
"type" => container.type,
|
||||
"ammo_group_count" =>
|
||||
container |> Ammo.get_ammo_groups_count_for_container!(current_user),
|
||||
"pack_count" => container |> Ammo.get_packs_count_for_container!(current_user),
|
||||
"round_count" => container |> Ammo.get_round_count_for_container!(current_user)
|
||||
}
|
||||
|
||||
ideal_shot_group = %{
|
||||
"ammo_group_id" => shot_group.ammo_group_id,
|
||||
"pack_id" => shot_group.pack_id,
|
||||
"count" => shot_group.count,
|
||||
"date" => to_string(shot_group.date),
|
||||
"id" => shot_group.id,
|
||||
@ -126,7 +124,7 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
}
|
||||
|
||||
json_resp = conn |> json_response(200)
|
||||
assert %{"ammo_groups" => [^ideal_ammo_group]} = json_resp
|
||||
assert %{"packs" => [^ideal_pack]} = json_resp
|
||||
assert %{"ammo_types" => [^ideal_ammo_type]} = json_resp
|
||||
assert %{"containers" => [^ideal_container]} = json_resp
|
||||
assert %{"shot_groups" => [^ideal_shot_group]} = json_resp
|
||||
|
@ -1,4 +1,4 @@
|
||||
defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
defmodule CanneryWeb.PackLiveTest do
|
||||
@moduledoc """
|
||||
Tests ammo group live pages
|
||||
"""
|
||||
@ -7,11 +7,11 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
import Phoenix.LiveViewTest
|
||||
alias Cannery.{Ammo, Repo}
|
||||
|
||||
@moduletag :ammo_group_live_test
|
||||
@moduletag :pack_live_test
|
||||
@create_attrs %{count: 42, notes: "some notes", price_paid: 120.5}
|
||||
@update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7}
|
||||
@invalid_attrs %{count: nil, notes: nil, price_paid: nil}
|
||||
@ammo_group_create_limit 10_000
|
||||
@pack_create_limit 10_000
|
||||
@shot_group_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_group_update_attrs %{
|
||||
count: 5,
|
||||
@ -28,296 +28,294 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
count: 20
|
||||
}
|
||||
|
||||
defp create_ammo_group(%{current_user: current_user}) do
|
||||
defp create_pack(%{current_user: current_user}) do
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
container = container_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@create_attrs, ammo_type, container, current_user)
|
||||
[ammo_type: ammo_type, ammo_group: ammo_group, container: container]
|
||||
{1, [pack]} = pack_fixture(@create_attrs, ammo_type, container, current_user)
|
||||
[ammo_type: ammo_type, pack: pack, container: container]
|
||||
end
|
||||
|
||||
defp create_shot_group(%{current_user: current_user, ammo_group: ammo_group}) do
|
||||
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
[ammo_group: ammo_group, shot_group: shot_group]
|
||||
defp create_shot_group(%{current_user: current_user, pack: pack}) do
|
||||
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, shot_group: shot_group]
|
||||
end
|
||||
|
||||
defp create_empty_ammo_group(%{
|
||||
defp create_empty_pack(%{
|
||||
current_user: current_user,
|
||||
ammo_type: ammo_type,
|
||||
container: container
|
||||
}) do
|
||||
{1, [ammo_group]} = ammo_group_fixture(@empty_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
[empty_ammo_group: ammo_group, shot_group: shot_group]
|
||||
{1, [pack]} = pack_fixture(@empty_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[empty_pack: pack, shot_group: shot_group]
|
||||
end
|
||||
|
||||
describe "Index of ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_pack]
|
||||
|
||||
test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
ammo_group = ammo_group |> Repo.preload(:ammo_type)
|
||||
test "lists all packs", %{conn: conn, pack: pack} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
pack = pack |> Repo.preload(:ammo_type)
|
||||
assert html =~ "Ammo"
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
assert html =~ pack.ammo_type.name
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
|
||||
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
|
||||
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_type, container, current_user)
|
||||
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "All"
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :rifle})
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
refute html =~ shotgun_ammo_group.ammo_type.name
|
||||
refute html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
refute html =~ shotgun_pack.ammo_type.name
|
||||
refute html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :shotgun})
|
||||
|
||||
refute html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
refute html =~ pistol_ammo_group.ammo_type.name
|
||||
refute html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
refute html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :pistol})
|
||||
|
||||
refute html =~ rifle_ammo_group.ammo_type.name
|
||||
refute html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
refute html =~ rifle_pack.ammo_type.name
|
||||
refute html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :all})
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
end
|
||||
|
||||
test "can search for ammo_groups", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "can search for packs", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
ammo_group = ammo_group |> Repo.preload(:ammo_type)
|
||||
pack = pack |> Repo.preload(:ammo_type)
|
||||
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
assert html =~ pack.ammo_type.name
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ammo_group.ammo_type.name}) =~
|
||||
ammo_group.ammo_type.name
|
||||
|> render_change(search: %{search_term: pack.ammo_type.name}) =~
|
||||
pack.ammo_type.name
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
Routes.ammo_group_index_path(conn, :search, ammo_group.ammo_type.name)
|
||||
Routes.pack_index_path(conn, :search, pack.ammo_type.name)
|
||||
)
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: "something_else"}) =~
|
||||
ammo_group.ammo_type.name
|
||||
pack.ammo_type.name
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :search, "something_else"))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ ammo_group.ammo_type.name
|
||||
|> render_change(search: %{search_term: ""}) =~ pack.ammo_type.name
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :index))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :index))
|
||||
end
|
||||
|
||||
test "saves a single new ammo_group", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "saves a single new pack", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n42\n"
|
||||
end
|
||||
|
||||
test "saves multiple new ammo_groups", %{conn: conn, current_user: current_user} do
|
||||
test "saves multiple new packs", %{conn: conn, current_user: current_user} do
|
||||
multiplier = 25
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:multiplier, multiplier))
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, multiplier))
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert Ammo.list_ammo_groups(nil, :all, current_user) |> Enum.count() == multiplier + 1
|
||||
assert Ammo.list_packs(nil, :all, current_user) |> Enum.count() == multiplier + 1
|
||||
end
|
||||
|
||||
test "does not save invalid number of new ammo_groups", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "does not save invalid number of new packs", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:multiplier, "0")) =~
|
||||
"Invalid number of copies, must be between 1 and #{@ammo_group_create_limit}. Was 0"
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, "0")) =~
|
||||
"Invalid number of copies, must be between 1 and #{@pack_create_limit}. Was 0"
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(
|
||||
ammo_group: @create_attrs |> Map.put(:multiplier, @ammo_group_create_limit + 1)
|
||||
) =~
|
||||
"Invalid number of copies, must be between 1 and #{@ammo_group_create_limit}. Was #{@ammo_group_create_limit + 1}"
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, @pack_create_limit + 1)) =~
|
||||
"Invalid number of copies, must be between 1 and #{@pack_create_limit}. Was #{@pack_create_limit + 1}"
|
||||
end
|
||||
|
||||
test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "updates pack in listing", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click() =~ "Edit ammo"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :edit, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :edit, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Ammo updated successfully"
|
||||
assert html =~ "\n43\n"
|
||||
end
|
||||
|
||||
test "clones ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "clones pack in listing", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
|
||||
|
||||
{:ok, _index_live, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> form("#pack-form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n42\n"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
end
|
||||
|
||||
test "checks validity when cloning", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "checks validity when cloning", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
end
|
||||
|
||||
test "clones ammo_group in listing with updates", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "clones pack in listing with updates", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Add Ammo"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :clone, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @create_attrs |> Map.put(:count, 43))
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @create_attrs |> Map.put(:count, 43))
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Ammo added successfully"
|
||||
assert html =~ "\n43\n"
|
||||
assert html =~ "$#{display_currency(120.5)}"
|
||||
end
|
||||
|
||||
test "deletes ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "deletes pack in listing", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Delete ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click()
|
||||
|
||||
refute has_element?(index_live, "#ammo_group-#{ammo_group.id}")
|
||||
refute has_element?(index_live, "#pack-#{pack.id}")
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.ammo_group_index_path(conn, :add_shot_group, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_group, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
@ -327,7 +325,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
@ -337,19 +335,19 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
end
|
||||
|
||||
describe "Index of empty ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_group, :create_empty_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_pack, :create_empty_pack]
|
||||
|
||||
test "hides empty ammo groups by default", %{
|
||||
conn: conn,
|
||||
empty_ammo_group: ammo_group,
|
||||
empty_pack: pack,
|
||||
current_user: current_user
|
||||
} do
|
||||
{:ok, show_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
|
||||
{:ok, show_live, html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Show used"
|
||||
refute html =~ "$#{display_currency(50.00)}"
|
||||
|
||||
percentage = ammo_group |> Ammo.get_percentage_remaining(current_user)
|
||||
percentage = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
refute html =~ "\n#{"#{percentage}%"}\n"
|
||||
|
||||
html =
|
||||
@ -358,49 +356,49 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "$#{display_currency(50.00)}"
|
||||
percentage = ammo_group |> Ammo.get_percentage_remaining(current_user)
|
||||
percentage = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
assert html =~ "\n#{"#{percentage}%"}\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_pack]
|
||||
|
||||
test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
ammo_group = ammo_group |> Repo.preload(:ammo_type)
|
||||
test "displays pack", %{conn: conn, pack: pack} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
pack = pack |> Repo.preload(:ammo_type)
|
||||
assert html =~ "Show Ammo"
|
||||
assert html =~ ammo_group.ammo_type.name
|
||||
assert html =~ pack.ammo_type.name
|
||||
end
|
||||
|
||||
test "updates ammo_group within modal", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
test "updates pack within modal", %{conn: conn, pack: pack} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert show_live
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{ammo_group.count} bullets"]/)
|
||||
|> element(~s/a[aria-label="Edit ammo group of #{pack.count} bullets"]/)
|
||||
|> render_click() =~ "Edit Ammo"
|
||||
|
||||
assert_patch(show_live, Routes.ammo_group_show_path(conn, :edit, ammo_group))
|
||||
assert_patch(show_live, Routes.pack_show_path(conn, :edit, pack))
|
||||
|
||||
assert show_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_change(ammo_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> form("#pack-form")
|
||||
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
show_live
|
||||
|> form("#ammo_group-form")
|
||||
|> render_submit(ammo_group: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|> form("#pack-form")
|
||||
|> render_submit(pack: @update_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Ammo updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.ammo_group_show_path(conn, :add_shot_group, ammo_group))
|
||||
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_group, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
@ -410,18 +408,18 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show ammo group with shot group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_group, :create_shot_group]
|
||||
setup [:register_and_log_in_user, :create_pack, :create_shot_group]
|
||||
|
||||
test "updates shot_group in listing",
|
||||
%{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :edit, ammo_group))
|
||||
%{conn: conn, pack: pack, shot_group: shot_group} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :edit, pack))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot group of #{shot_group.count} shots"]/)
|
||||
@ -429,7 +427,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
Routes.ammo_group_show_path(conn, :edit_shot_group, ammo_group, shot_group)
|
||||
Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group)
|
||||
)
|
||||
|
||||
assert index_live
|
||||
@ -440,16 +438,16 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_update_attrs)
|
||||
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Shot records updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "deletes shot_group in listing",
|
||||
%{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do
|
||||
%{conn: conn, pack: pack, shot_group: shot_group} do
|
||||
{:ok, index_live, _html} =
|
||||
live(conn, Routes.ammo_group_show_path(conn, :edit_shot_group, ammo_group, shot_group))
|
||||
live(conn, Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
||||
|
@ -33,7 +33,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
name: nil,
|
||||
grains: nil
|
||||
}
|
||||
@ammo_group_attrs %{
|
||||
@pack_attrs %{
|
||||
notes: "some ammo group",
|
||||
count: 20
|
||||
}
|
||||
@ -46,18 +46,18 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
[ammo_type: ammo_type_fixture(@create_attrs, current_user)]
|
||||
end
|
||||
|
||||
defp create_ammo_group(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
defp create_pack(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
container = container_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
[ammo_group: ammo_group, container: container]
|
||||
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
|
||||
[pack: pack, container: container]
|
||||
end
|
||||
|
||||
defp create_empty_ammo_group(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
defp create_empty_pack(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
container = container_fixture(current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
|
||||
ammo_group = ammo_group |> Repo.reload!()
|
||||
[ammo_group: ammo_group, container: container, shot_group: shot_group]
|
||||
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, container: container, shot_group: shot_group]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -249,10 +249,10 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
end
|
||||
|
||||
describe "Index with ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_pack]
|
||||
|
||||
test "shows used ammo groups on toggle",
|
||||
%{conn: conn, ammo_group: ammo_group, current_user: current_user} do
|
||||
%{conn: conn, pack: pack, current_user: current_user} do
|
||||
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Show used"
|
||||
@ -275,7 +275,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
assert html =~ "\n0\n"
|
||||
assert html =~ "\n1\n"
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, ammo_group)
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
@ -328,7 +328,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
end
|
||||
|
||||
describe "Show ammo type with ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_pack]
|
||||
|
||||
test "displays ammo group", %{
|
||||
conn: conn,
|
||||
@ -357,7 +357,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
end
|
||||
|
||||
describe "Show ammo type with empty ammo group" do
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_empty_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_ammo_type, :create_empty_pack]
|
||||
|
||||
test "displays empty ammo groups on toggle",
|
||||
%{conn: conn, ammo_type: ammo_type, container: %{name: container_name}} do
|
||||
|
@ -30,7 +30,7 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
name: "some name",
|
||||
grains: 120
|
||||
}
|
||||
@ammo_group_attrs %{
|
||||
@pack_attrs %{
|
||||
notes: "some ammo group",
|
||||
count: 20
|
||||
}
|
||||
@ -40,11 +40,11 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
[container: container]
|
||||
end
|
||||
|
||||
defp create_ammo_group(%{container: container, current_user: current_user}) do
|
||||
defp create_pack(%{container: container, current_user: current_user}) do
|
||||
ammo_type = ammo_type_fixture(@ammo_type_attrs, current_user)
|
||||
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
|
||||
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
|
||||
|
||||
[ammo_type: ammo_type, ammo_group: ammo_group]
|
||||
[ammo_type: ammo_type, pack: pack]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -246,60 +246,60 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
|
||||
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
|
||||
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
|
||||
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_type, container, current_user)
|
||||
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
|
||||
|
||||
assert html =~ "All"
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :rifle})
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
refute html =~ shotgun_ammo_group.ammo_type.name
|
||||
refute html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
refute html =~ shotgun_pack.ammo_type.name
|
||||
refute html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :shotgun})
|
||||
|
||||
refute html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
refute html =~ pistol_ammo_group.ammo_type.name
|
||||
refute html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
refute html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :pistol})
|
||||
|
||||
refute html =~ rifle_ammo_group.ammo_type.name
|
||||
refute html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
refute html =~ rifle_pack.ammo_type.name
|
||||
refute html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :all})
|
||||
|
||||
assert html =~ rifle_ammo_group.ammo_type.name
|
||||
assert html =~ shotgun_ammo_group.ammo_type.name
|
||||
assert html =~ pistol_ammo_group.ammo_type.name
|
||||
assert html =~ rifle_pack.ammo_type.name
|
||||
assert html =~ shotgun_pack.ammo_type.name
|
||||
assert html =~ pistol_pack.ammo_type.name
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show with ammo group" do
|
||||
setup [:register_and_log_in_user, :create_container, :create_ammo_group]
|
||||
setup [:register_and_log_in_user, :create_container, :create_pack]
|
||||
|
||||
test "displays ammo group",
|
||||
%{conn: conn, ammo_type: %{name: ammo_type_name}, container: container} do
|
||||
|
@ -16,16 +16,16 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
container = container_fixture(%{staged: true}, current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
|
||||
{1, [ammo_group]} = ammo_group_fixture(%{staged: true}, ammo_type, container, current_user)
|
||||
{1, [pack]} = pack_fixture(%{staged: true}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, ammo_group)
|
||||
|> shot_group_fixture(current_user, pack)
|
||||
|
||||
[
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
ammo_group: ammo_group,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
]
|
||||
end
|
||||
@ -43,21 +43,19 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
test "can sort by type",
|
||||
%{conn: conn, container: container, current_user: current_user} do
|
||||
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_ammo_group]} = ammo_group_fixture(rifle_ammo_type, container, current_user)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_ammo_type, container, current_user)
|
||||
|
||||
rifle_shot_group = shot_group_fixture(%{notes: "group_one"}, current_user, rifle_ammo_group)
|
||||
rifle_shot_group = shot_group_fixture(%{notes: "group_one"}, current_user, rifle_pack)
|
||||
|
||||
shotgun_ammo_type = ammo_type_fixture(%{class: :shotgun}, current_user)
|
||||
{1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_ammo_type, container, current_user)
|
||||
{1, [shotgun_pack]} = pack_fixture(shotgun_ammo_type, container, current_user)
|
||||
|
||||
shotgun_shot_group =
|
||||
shot_group_fixture(%{notes: "group_two"}, current_user, shotgun_ammo_group)
|
||||
shotgun_shot_group = shot_group_fixture(%{notes: "group_two"}, current_user, shotgun_pack)
|
||||
|
||||
pistol_ammo_type = ammo_type_fixture(%{class: :pistol}, current_user)
|
||||
{1, [pistol_ammo_group]} = ammo_group_fixture(pistol_ammo_type, container, current_user)
|
||||
{1, [pistol_pack]} = pack_fixture(pistol_ammo_type, container, current_user)
|
||||
|
||||
pistol_shot_group =
|
||||
shot_group_fixture(%{notes: "group_three"}, current_user, pistol_ammo_group)
|
||||
pistol_shot_group = shot_group_fixture(%{notes: "group_three"}, current_user, pistol_pack)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
@ -128,11 +126,11 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :index))
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_group, ammo_group))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_group, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|
@ -10,7 +10,7 @@ defmodule Cannery.Fixtures do
|
||||
Accounts.User,
|
||||
ActivityLog.ShotGroup,
|
||||
Ammo,
|
||||
Ammo.AmmoGroup,
|
||||
Ammo.Pack,
|
||||
Ammo.AmmoType,
|
||||
Containers,
|
||||
Containers.Container,
|
||||
@ -71,16 +71,16 @@ defmodule Cannery.Fixtures do
|
||||
@doc """
|
||||
Generate a ShotGroup
|
||||
"""
|
||||
@spec shot_group_fixture(User.t(), AmmoGroup.t()) :: ShotGroup.t()
|
||||
@spec shot_group_fixture(attrs :: map(), User.t(), AmmoGroup.t()) :: ShotGroup.t()
|
||||
def shot_group_fixture(attrs \\ %{}, %User{} = user, %AmmoGroup{} = ammo_group) do
|
||||
@spec shot_group_fixture(User.t(), Pack.t()) :: ShotGroup.t()
|
||||
@spec shot_group_fixture(attrs :: map(), User.t(), Pack.t()) :: ShotGroup.t()
|
||||
def shot_group_fixture(attrs \\ %{}, %User{} = user, %Pack{} = pack) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
count: 20,
|
||||
date: ~N[2022-02-13 03:17:00],
|
||||
notes: random_string()
|
||||
})
|
||||
|> Cannery.ActivityLog.create_shot_group(user, ammo_group)
|
||||
|> Cannery.ActivityLog.create_shot_group(user, pack)
|
||||
|> unwrap_ok_tuple()
|
||||
end
|
||||
|
||||
@ -109,20 +109,20 @@ defmodule Cannery.Fixtures do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a AmmoGroup
|
||||
Generate a Pack
|
||||
"""
|
||||
@spec ammo_group_fixture(AmmoType.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [AmmoGroup.t()]}
|
||||
@spec ammo_group_fixture(attrs :: map(), AmmoType.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [AmmoGroup.t()]}
|
||||
@spec ammo_group_fixture(
|
||||
@spec pack_fixture(AmmoType.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [Pack.t()]}
|
||||
@spec pack_fixture(attrs :: map(), AmmoType.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [Pack.t()]}
|
||||
@spec pack_fixture(
|
||||
attrs :: map(),
|
||||
multiplier :: non_neg_integer(),
|
||||
AmmoType.t(),
|
||||
Container.t(),
|
||||
User.t()
|
||||
) :: {count :: non_neg_integer(), [AmmoGroup.t()]}
|
||||
def ammo_group_fixture(
|
||||
) :: {count :: non_neg_integer(), [Pack.t()]}
|
||||
def pack_fixture(
|
||||
attrs \\ %{},
|
||||
multiplier \\ 1,
|
||||
%AmmoType{id: ammo_type_id},
|
||||
@ -136,7 +136,7 @@ defmodule Cannery.Fixtures do
|
||||
count: 20,
|
||||
purchased_on: Date.utc_today()
|
||||
})
|
||||
|> Ammo.create_ammo_groups(multiplier, user)
|
||||
|> Ammo.create_packs(multiplier, user)
|
||||
|> unwrap_ok_tuple()
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user