shot groups to shot records
This commit is contained in:
@ -5,11 +5,11 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
use Cannery.DataCase
|
||||
import Cannery.Fixtures
|
||||
alias Cannery.{ActivityLog, ActivityLog.ShotGroup, Ammo}
|
||||
alias Cannery.{ActivityLog, ActivityLog.ShotRecord, Ammo}
|
||||
|
||||
@moduletag :activity_log_test
|
||||
|
||||
describe "shot_groups" do
|
||||
describe "shot_records" do
|
||||
setup do
|
||||
current_user = user_fixture()
|
||||
container = container_fixture(current_user)
|
||||
@ -18,9 +18,9 @@ defmodule Cannery.ActivityLogTest do
|
||||
{1, [%{id: pack_id} = pack]} =
|
||||
pack_fixture(%{count: 25}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
shot_record =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, pack)
|
||||
|> shot_record_fixture(current_user, pack)
|
||||
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
@ -29,7 +29,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
shot_record: shot_record
|
||||
]
|
||||
end
|
||||
|
||||
@ -37,10 +37,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
%{pack: pack, current_user: current_user} do
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 1
|
||||
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
shot_record_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 2
|
||||
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
shot_record_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, current_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(current_user) == 3
|
||||
|
||||
other_user = user_fixture()
|
||||
@ -49,83 +49,84 @@ defmodule Cannery.ActivityLogTest do
|
||||
container = container_fixture(other_user)
|
||||
ammo_type = ammo_type_fixture(other_user)
|
||||
{1, [pack]} = pack_fixture(%{count: 25}, ammo_type, container, other_user)
|
||||
shot_group_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, other_user, pack)
|
||||
shot_record_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, other_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(other_user) == 1
|
||||
end
|
||||
|
||||
test "get_shot_group!/2 returns the shot_group with given id",
|
||||
%{shot_group: shot_group, current_user: current_user} do
|
||||
assert ActivityLog.get_shot_group!(shot_group.id, current_user) == shot_group
|
||||
test "get_shot_record!/2 returns the shot_record with given id",
|
||||
%{shot_record: shot_record, current_user: current_user} do
|
||||
assert ActivityLog.get_shot_record!(shot_record.id, current_user) == shot_record
|
||||
end
|
||||
|
||||
test "get_shot_group!/2 does not return a shot_group of another user",
|
||||
%{shot_group: shot_group} do
|
||||
test "get_shot_record!/2 does not return a shot_record of another user",
|
||||
%{shot_record: shot_record} do
|
||||
another_user = user_fixture()
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
ActivityLog.get_shot_group!(shot_group.id, another_user)
|
||||
ActivityLog.get_shot_record!(shot_record.id, another_user)
|
||||
end
|
||||
end
|
||||
|
||||
test "create_shot_group/3 with valid data creates a shot_group",
|
||||
test "create_shot_record/3 with valid data creates a shot_record",
|
||||
%{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, pack)
|
||||
assert {:ok, %ShotRecord{} = shot_record} =
|
||||
ActivityLog.create_shot_record(valid_attrs, current_user, pack)
|
||||
|
||||
assert shot_group.count == 10
|
||||
assert shot_group.date == ~D[2022-02-13]
|
||||
assert shot_group.notes == "some notes"
|
||||
assert shot_record.count == 10
|
||||
assert shot_record.date == ~D[2022-02-13]
|
||||
assert shot_record.notes == "some notes"
|
||||
end
|
||||
|
||||
test "create_shot_group/3 removes corresponding count from pack",
|
||||
test "create_shot_record/3 removes corresponding count from pack",
|
||||
%{
|
||||
current_user: current_user,
|
||||
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, pack)
|
||||
assert {:ok, %ShotRecord{} = shot_record} =
|
||||
ActivityLog.create_shot_record(valid_attrs, current_user, pack)
|
||||
|
||||
%{count: new_count} = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert org_count - shot_group.count == new_count
|
||||
assert org_count - shot_record.count == new_count
|
||||
assert new_count == 10
|
||||
end
|
||||
|
||||
test "create_shot_group/3 does not remove more tha pack amount",
|
||||
test "create_shot_record/3 does not remove more tha pack amount",
|
||||
%{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, pack)
|
||||
assert {:ok, %ShotRecord{}} =
|
||||
ActivityLog.create_shot_record(valid_attrs, current_user, pack)
|
||||
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert pack.count == 0
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
ActivityLog.create_shot_group(%{count: 1}, current_user, pack)
|
||||
ActivityLog.create_shot_record(%{count: 1}, current_user, pack)
|
||||
end
|
||||
|
||||
test "create_shot_group/3 with invalid data returns error changeset",
|
||||
test "create_shot_record/3 with invalid data returns error changeset",
|
||||
%{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, pack)
|
||||
ActivityLog.create_shot_record(invalid_params, current_user, pack)
|
||||
end
|
||||
|
||||
test "update_shot_group/3 with valid data updates the shot_group and pack",
|
||||
test "update_shot_record/3 with valid data updates the shot_record and pack",
|
||||
%{
|
||||
shot_group: shot_group,
|
||||
shot_record: shot_record,
|
||||
pack: %{id: pack_id},
|
||||
current_user: current_user
|
||||
} do
|
||||
assert {:ok, %ShotGroup{} = shot_group} =
|
||||
ActivityLog.update_shot_group(
|
||||
shot_group,
|
||||
assert {:ok, %ShotRecord{} = shot_record} =
|
||||
ActivityLog.update_shot_record(
|
||||
shot_record,
|
||||
%{
|
||||
count: 10,
|
||||
date: ~D[2022-02-13],
|
||||
@ -136,14 +137,14 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert shot_group.count == 10
|
||||
assert shot_record.count == 10
|
||||
assert pack.count == 15
|
||||
assert shot_group.date == ~D[2022-02-13]
|
||||
assert shot_group.notes == "some updated notes"
|
||||
assert shot_record.date == ~D[2022-02-13]
|
||||
assert shot_record.notes == "some updated notes"
|
||||
|
||||
assert {:ok, %ShotGroup{} = shot_group} =
|
||||
ActivityLog.update_shot_group(
|
||||
shot_group,
|
||||
assert {:ok, %ShotRecord{} = shot_record} =
|
||||
ActivityLog.update_shot_record(
|
||||
shot_record,
|
||||
%{
|
||||
count: 25,
|
||||
date: ~D[2022-02-13],
|
||||
@ -154,37 +155,37 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
pack = pack_id |> Ammo.get_pack!(current_user)
|
||||
|
||||
assert shot_group.count == 25
|
||||
assert shot_record.count == 25
|
||||
assert pack.count == 0
|
||||
end
|
||||
|
||||
test "update_shot_group/3 with invalid data returns error changeset",
|
||||
%{shot_group: shot_group, current_user: current_user} do
|
||||
test "update_shot_record/3 with invalid data returns error changeset",
|
||||
%{shot_record: shot_record, current_user: current_user} do
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
ActivityLog.update_shot_group(
|
||||
shot_group,
|
||||
ActivityLog.update_shot_record(
|
||||
shot_record,
|
||||
%{count: 26, date: nil, notes: nil},
|
||||
current_user
|
||||
)
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
ActivityLog.update_shot_group(
|
||||
shot_group,
|
||||
ActivityLog.update_shot_record(
|
||||
shot_record,
|
||||
%{count: -1, date: nil, notes: nil},
|
||||
current_user
|
||||
)
|
||||
|
||||
assert shot_group == ActivityLog.get_shot_group!(shot_group.id, current_user)
|
||||
assert shot_record == ActivityLog.get_shot_record!(shot_record.id, current_user)
|
||||
end
|
||||
|
||||
test "delete_shot_group/2 deletes the shot_group and adds value back",
|
||||
%{shot_group: shot_group, current_user: current_user, pack: %{id: pack_id}} do
|
||||
assert {:ok, %ShotGroup{}} = ActivityLog.delete_shot_group(shot_group, current_user)
|
||||
test "delete_shot_record/2 deletes the shot_record and adds value back",
|
||||
%{shot_record: shot_record, current_user: current_user, pack: %{id: pack_id}} do
|
||||
assert {:ok, %ShotRecord{}} = ActivityLog.delete_shot_record(shot_record, 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)
|
||||
ActivityLog.get_shot_record!(shot_record.id, current_user)
|
||||
end
|
||||
end
|
||||
|
||||
@ -198,10 +199,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
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, pack)
|
||||
shot_record_fixture(%{count: 15}, current_user, pack)
|
||||
assert 20 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 10}, current_user, pack)
|
||||
shot_record_fixture(%{count: 10}, current_user, pack)
|
||||
assert 30 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
@ -220,17 +221,17 @@ defmodule Cannery.ActivityLogTest do
|
||||
assert %{pack_id => 5} ==
|
||||
[pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, another_pack)
|
||||
shot_record_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, pack)
|
||||
shot_record_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, pack)
|
||||
shot_record_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
|
||||
@ -240,17 +241,17 @@ defmodule Cannery.ActivityLogTest do
|
||||
pack: pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
shot_group: %{date: date},
|
||||
shot_record: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{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, pack)
|
||||
%{date: date} = shot_record_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, pack)
|
||||
%{date: date} = shot_record_fixture(%{date: ~D[2022-11-11]}, current_user, pack)
|
||||
assert ^date = pack |> ActivityLog.get_last_used_date(current_user)
|
||||
end
|
||||
|
||||
@ -258,7 +259,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
pack: %{id: pack_id} = pack,
|
||||
ammo_type: ammo_type,
|
||||
container: container,
|
||||
shot_group: %{date: date},
|
||||
shot_record: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
@ -268,32 +269,32 @@ defmodule Cannery.ActivityLogTest do
|
||||
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_pack)
|
||||
shot_record_fixture(%{date: ~D[2022-11-09]}, current_user, another_pack)
|
||||
|
||||
# setting initial date
|
||||
last_used_shot_groups =
|
||||
last_used_shot_records =
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^pack_id => ^date} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ^date} = last_used_shot_records
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records
|
||||
|
||||
# setting another date
|
||||
shot_group_fixture(%{date: ~D[2022-11-10]}, current_user, pack)
|
||||
shot_record_fixture(%{date: ~D[2022-11-10]}, current_user, pack)
|
||||
|
||||
last_used_shot_groups =
|
||||
last_used_shot_records =
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^pack_id => ~D[2022-11-10]} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ~D[2022-11-10]} = last_used_shot_records
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records
|
||||
|
||||
# setting yet another date
|
||||
shot_group_fixture(%{date: ~D[2022-11-11]}, current_user, pack)
|
||||
shot_record_fixture(%{date: ~D[2022-11-11]}, current_user, pack)
|
||||
|
||||
last_used_shot_groups =
|
||||
last_used_shot_records =
|
||||
[pack, another_pack] |> ActivityLog.get_last_used_dates(current_user)
|
||||
|
||||
assert %{^pack_id => ~D[2022-11-11]} = last_used_shot_groups
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_groups
|
||||
assert %{^pack_id => ~D[2022-11-11]} = last_used_shot_records
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records
|
||||
end
|
||||
|
||||
test "get_used_count_for_ammo_type/2 gets accurate used round count for ammo type",
|
||||
@ -302,10 +303,10 @@ defmodule Cannery.ActivityLogTest do
|
||||
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, pack)
|
||||
shot_record_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, pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, pack)
|
||||
assert 11 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
end
|
||||
|
||||
@ -323,7 +324,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
|> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
|
||||
# use generated pack
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
shot_record_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
@ -332,7 +333,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
assert %{^another_ammo_type_id => 5} = used_counts
|
||||
|
||||
# use generated pack again
|
||||
shot_group_fixture(%{count: 1}, current_user, pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
@ -342,7 +343,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_shot_groups/3" do
|
||||
describe "list_shot_records/3" do
|
||||
setup do
|
||||
current_user = user_fixture()
|
||||
container = container_fixture(current_user)
|
||||
@ -357,7 +358,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
]
|
||||
end
|
||||
|
||||
test "list_shot_groups/3 returns relevant shot_groups for a type",
|
||||
test "list_shot_records/3 returns relevant shot_records for a type",
|
||||
%{current_user: current_user, container: container} do
|
||||
other_user = user_fixture()
|
||||
other_container = container_fixture(other_user)
|
||||
@ -365,56 +366,56 @@ defmodule Cannery.ActivityLogTest do
|
||||
for class <- ["rifle", "shotgun", "pistol"] do
|
||||
other_ammo_type = ammo_type_fixture(%{class: class}, other_user)
|
||||
{1, [other_pack]} = pack_fixture(other_ammo_type, other_container, other_user)
|
||||
shot_group_fixture(other_user, other_pack)
|
||||
shot_record_fixture(other_user, other_pack)
|
||||
end
|
||||
|
||||
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_ammo_type, container, current_user)
|
||||
rifle_shot_group = shot_group_fixture(current_user, rifle_pack)
|
||||
rifle_shot_record = shot_record_fixture(current_user, rifle_pack)
|
||||
|
||||
shotgun_ammo_type = ammo_type_fixture(%{class: :shotgun}, current_user)
|
||||
{1, [shotgun_pack]} = pack_fixture(shotgun_ammo_type, container, current_user)
|
||||
shotgun_shot_group = shot_group_fixture(current_user, shotgun_pack)
|
||||
shotgun_shot_record = shot_record_fixture(current_user, shotgun_pack)
|
||||
|
||||
pistol_ammo_type = ammo_type_fixture(%{class: :pistol}, current_user)
|
||||
{1, [pistol_pack]} = pack_fixture(pistol_ammo_type, container, current_user)
|
||||
pistol_shot_group = shot_group_fixture(current_user, pistol_pack)
|
||||
pistol_shot_record = shot_record_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)
|
||||
assert [^pistol_shot_group] = ActivityLog.list_shot_groups(:pistol, current_user)
|
||||
assert [^rifle_shot_record] = ActivityLog.list_shot_records(:rifle, current_user)
|
||||
assert [^shotgun_shot_record] = ActivityLog.list_shot_records(:shotgun, current_user)
|
||||
assert [^pistol_shot_record] = ActivityLog.list_shot_records(:pistol, current_user)
|
||||
|
||||
shot_groups = ActivityLog.list_shot_groups(:all, current_user)
|
||||
assert Enum.count(shot_groups) == 3
|
||||
assert rifle_shot_group in shot_groups
|
||||
assert shotgun_shot_group in shot_groups
|
||||
assert pistol_shot_group in shot_groups
|
||||
shot_records = ActivityLog.list_shot_records(:all, current_user)
|
||||
assert Enum.count(shot_records) == 3
|
||||
assert rifle_shot_record in shot_records
|
||||
assert shotgun_shot_record in shot_records
|
||||
assert pistol_shot_record in shot_records
|
||||
|
||||
shot_groups = ActivityLog.list_shot_groups(nil, current_user)
|
||||
assert Enum.count(shot_groups) == 3
|
||||
assert rifle_shot_group in shot_groups
|
||||
assert shotgun_shot_group in shot_groups
|
||||
assert pistol_shot_group in shot_groups
|
||||
shot_records = ActivityLog.list_shot_records(nil, current_user)
|
||||
assert Enum.count(shot_records) == 3
|
||||
assert rifle_shot_record in shot_records
|
||||
assert shotgun_shot_record in shot_records
|
||||
assert pistol_shot_record in shot_records
|
||||
end
|
||||
|
||||
test "list_shot_groups/3 returns relevant shot_groups for a search", %{
|
||||
test "list_shot_records/3 returns relevant shot_records for a search", %{
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
shot_group_a = shot_group_fixture(%{notes: "amazing"}, current_user, pack)
|
||||
shot_record_a = shot_record_fixture(%{notes: "amazing"}, current_user, pack)
|
||||
|
||||
{1, [another_pack]} =
|
||||
pack_fixture(%{notes: "stupendous"}, ammo_type, container, current_user)
|
||||
|
||||
shot_group_b = shot_group_fixture(current_user, another_pack)
|
||||
shot_record_b = shot_record_fixture(current_user, another_pack)
|
||||
|
||||
another_ammo_type = ammo_type_fixture(%{name: "fabulous ammo"}, current_user)
|
||||
|
||||
{1, [yet_another_pack]} = pack_fixture(another_ammo_type, container, current_user)
|
||||
|
||||
shot_group_c = shot_group_fixture(current_user, yet_another_pack)
|
||||
shot_record_c = shot_record_fixture(current_user, yet_another_pack)
|
||||
|
||||
another_user = user_fixture()
|
||||
another_container = container_fixture(another_user)
|
||||
@ -422,16 +423,16 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
{1, [another_pack]} = pack_fixture(another_ammo_type, another_container, another_user)
|
||||
|
||||
_shouldnt_return = shot_group_fixture(another_user, another_pack)
|
||||
_shouldnt_return = shot_record_fixture(another_user, another_pack)
|
||||
|
||||
# notes
|
||||
assert ActivityLog.list_shot_groups("amazing", :all, current_user) == [shot_group_a]
|
||||
assert ActivityLog.list_shot_records("amazing", :all, current_user) == [shot_record_a]
|
||||
|
||||
# pack attributes
|
||||
assert ActivityLog.list_shot_groups("stupendous", :all, current_user) == [shot_group_b]
|
||||
assert ActivityLog.list_shot_records("stupendous", :all, current_user) == [shot_record_b]
|
||||
|
||||
# ammo type attributes
|
||||
assert ActivityLog.list_shot_groups("fabulous", :all, current_user) == [shot_group_c]
|
||||
assert ActivityLog.list_shot_records("fabulous", :all, current_user) == [shot_record_c]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -362,10 +362,10 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 51 = Ammo.get_round_count_for_ammo_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 26}, current_user, pack)
|
||||
shot_record_fixture(%{count: 26}, current_user, pack)
|
||||
assert 25 = Ammo.get_round_count_for_ammo_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
assert 24 = Ammo.get_round_count_for_ammo_type(ammo_type, current_user)
|
||||
end
|
||||
|
||||
@ -397,7 +397,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^ammo_type_id => 51} = round_counts
|
||||
assert %{^another_ammo_type_id => 1} = round_counts
|
||||
|
||||
shot_group_fixture(%{count: 26}, current_user, pack)
|
||||
shot_record_fixture(%{count: 26}, current_user, pack)
|
||||
|
||||
round_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_round_count_for_ammo_types(current_user)
|
||||
@ -405,7 +405,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^ammo_type_id => 25} = round_counts
|
||||
assert %{^another_ammo_type_id => 1} = round_counts
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
|
||||
round_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_round_count_for_ammo_types(current_user)
|
||||
@ -426,10 +426,10 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 51 = Ammo.get_historical_count_for_ammo_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 26}, current_user, pack)
|
||||
shot_record_fixture(%{count: 26}, current_user, pack)
|
||||
assert 51 = Ammo.get_historical_count_for_ammo_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
assert 51 = Ammo.get_historical_count_for_ammo_type(ammo_type, current_user)
|
||||
end
|
||||
|
||||
@ -464,7 +464,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^ammo_type_id => 51} = historical_counts
|
||||
assert %{^another_ammo_type_id => 1} = historical_counts
|
||||
|
||||
shot_group_fixture(%{count: 26}, current_user, pack)
|
||||
shot_record_fixture(%{count: 26}, current_user, pack)
|
||||
|
||||
historical_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_historical_count_for_ammo_types(current_user)
|
||||
@ -472,7 +472,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^ammo_type_id => 51} = historical_counts
|
||||
assert %{^another_ammo_type_id => 1} = historical_counts
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
|
||||
historical_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_historical_count_for_ammo_types(current_user)
|
||||
@ -493,10 +493,10 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 0 = Ammo.get_used_packs_count_for_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 50}, current_user, pack)
|
||||
shot_record_fixture(%{count: 50}, current_user, pack)
|
||||
assert 1 = Ammo.get_used_packs_count_for_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
assert 2 = Ammo.get_used_packs_count_for_type(ammo_type, current_user)
|
||||
end
|
||||
|
||||
@ -526,7 +526,7 @@ defmodule Cannery.AmmoTest do
|
||||
# testing ammo type with used pack
|
||||
{1, [another_pack]} = pack_fixture(%{count: 50}, another_ammo_type, container, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 50}, current_user, another_pack)
|
||||
shot_record_fixture(%{count: 50}, current_user, another_pack)
|
||||
|
||||
assert %{another_ammo_type_id => 1} ==
|
||||
[ammo_type, another_ammo_type]
|
||||
@ -534,7 +534,7 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
# testing two ammo types with zero and one used packs
|
||||
{1, [pack]} = pack_fixture(%{count: 50}, ammo_type, container, current_user)
|
||||
shot_group_fixture(%{count: 50}, current_user, pack)
|
||||
shot_record_fixture(%{count: 50}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_used_packs_count_for_types(current_user)
|
||||
@ -543,7 +543,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^another_ammo_type_id => 1} = used_counts
|
||||
|
||||
# testing two ammo type with one and two used packs
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> Ammo.get_used_packs_count_for_types(current_user)
|
||||
@ -562,10 +562,10 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 26 = Ammo.get_packs_count_for_container!(container, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
assert 26 = Ammo.get_packs_count_for_container!(container, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 4}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 4}, current_user, first_pack)
|
||||
assert 25 = Ammo.get_packs_count_for_container!(container, current_user)
|
||||
end
|
||||
|
||||
@ -596,7 +596,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^container_id => 26} = packs_count
|
||||
assert %{^another_container_id => 1} = packs_count
|
||||
|
||||
shot_group_fixture(%{count: 1}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 1}, current_user, first_pack)
|
||||
|
||||
packs_count =
|
||||
[container, another_container]
|
||||
@ -605,7 +605,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^container_id => 26} = packs_count
|
||||
assert %{^another_container_id => 1} = packs_count
|
||||
|
||||
shot_group_fixture(%{count: 4}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 4}, current_user, first_pack)
|
||||
|
||||
packs_count =
|
||||
[container, another_container]
|
||||
@ -625,7 +625,7 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 130 = Ammo.get_round_count_for_container!(container, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 5}, current_user, first_pack)
|
||||
assert 125 = Ammo.get_round_count_for_container!(container, current_user)
|
||||
end
|
||||
|
||||
@ -655,7 +655,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^container_id => 130} = round_counts
|
||||
assert %{^another_container_id => 5} = round_counts
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, first_pack)
|
||||
shot_record_fixture(%{count: 5}, current_user, first_pack)
|
||||
|
||||
round_counts =
|
||||
[container, another_container] |> Ammo.get_round_count_for_containers(current_user)
|
||||
@ -725,7 +725,7 @@ defmodule Cannery.AmmoTest do
|
||||
{1, [another_pack]} =
|
||||
pack_fixture(%{count: 30}, other_ammo_type, other_container, other_user)
|
||||
|
||||
shot_group_fixture(%{count: 30}, other_user, another_pack)
|
||||
shot_record_fixture(%{count: 30}, other_user, another_pack)
|
||||
assert Ammo.get_packs_count!(other_user) == 0
|
||||
assert Ammo.get_packs_count!(other_user, true) == 1
|
||||
end
|
||||
@ -767,7 +767,7 @@ defmodule Cannery.AmmoTest do
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
pack_fixture(%{count: 30}, ammo_type, container, current_user)
|
||||
|
||||
shot_group_fixture(%{count: 30}, current_user, another_pack)
|
||||
shot_record_fixture(%{count: 30}, current_user, another_pack)
|
||||
another_pack = Ammo.get_pack!(another_pack_id, current_user)
|
||||
|
||||
assert Ammo.list_packs(nil, :all, current_user, false) == [pack]
|
||||
@ -831,7 +831,7 @@ defmodule Cannery.AmmoTest do
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
assert [^pack] = Ammo.list_packs_for_type(ammo_type, current_user)
|
||||
|
||||
shot_group_fixture(current_user, pack)
|
||||
shot_record_fixture(current_user, pack)
|
||||
pack = Ammo.get_pack!(pack.id, current_user)
|
||||
assert [] == Ammo.list_packs_for_type(ammo_type, current_user)
|
||||
assert [^pack] = Ammo.list_packs_for_type(ammo_type, current_user, true)
|
||||
@ -1013,15 +1013,15 @@ defmodule Cannery.AmmoTest do
|
||||
%{pack: %{id: pack_id} = pack, current_user: current_user} do
|
||||
assert 100 = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 14}, current_user, pack)
|
||||
shot_record_fixture(%{count: 14}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 72 = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 11}, current_user, pack)
|
||||
shot_record_fixture(%{count: 11}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 50 = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 25}, current_user, pack)
|
||||
shot_record_fixture(%{count: 25}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 0 = pack |> Ammo.get_percentage_remaining(current_user)
|
||||
end
|
||||
@ -1044,7 +1044,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^pack_id => 100} = percentages
|
||||
assert %{^another_pack_id => 100} = percentages
|
||||
|
||||
shot_group_fixture(%{count: 14}, current_user, pack)
|
||||
shot_record_fixture(%{count: 14}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
|
||||
percentages = [pack, another_pack] |> Ammo.get_percentages_remaining(current_user)
|
||||
@ -1052,7 +1052,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^pack_id => 72} = percentages
|
||||
assert %{^another_pack_id => 100} = percentages
|
||||
|
||||
shot_group_fixture(%{count: 11}, current_user, pack)
|
||||
shot_record_fixture(%{count: 11}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
|
||||
percentages = [pack, another_pack] |> Ammo.get_percentages_remaining(current_user)
|
||||
@ -1060,7 +1060,7 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^pack_id => 50} = percentages
|
||||
assert %{^another_pack_id => 100} = percentages
|
||||
|
||||
shot_group_fixture(%{count: 25}, current_user, pack)
|
||||
shot_record_fixture(%{count: 25}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
|
||||
percentages = [pack, another_pack] |> Ammo.get_percentages_remaining(current_user)
|
||||
@ -1104,8 +1104,8 @@ defmodule Cannery.AmmoTest do
|
||||
|
||||
assert 0.722 = pack |> Ammo.get_cpr(current_user)
|
||||
|
||||
# with shot group, maintains total
|
||||
shot_group_fixture(%{count: 14}, current_user, pack)
|
||||
# with shot record, maintains total
|
||||
shot_record_fixture(%{count: 14}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack.id, current_user)
|
||||
assert 0.722 = pack |> Ammo.get_cpr(current_user)
|
||||
end
|
||||
@ -1151,8 +1151,8 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^another_pack_id => 1.5} = cprs
|
||||
assert %{^yet_another_pack_id => 0.722} = cprs
|
||||
|
||||
# with shot group, maintains total
|
||||
shot_group_fixture(%{count: 14}, current_user, yet_another_pack)
|
||||
# with shot record, maintains total
|
||||
shot_record_fixture(%{count: 14}, current_user, yet_another_pack)
|
||||
yet_another_pack = Ammo.get_pack!(yet_another_pack.id, current_user)
|
||||
|
||||
cprs = [pack, another_pack, yet_another_pack] |> Ammo.get_cprs(current_user)
|
||||
@ -1166,15 +1166,15 @@ defmodule Cannery.AmmoTest do
|
||||
%{pack: %{id: pack_id} = pack, current_user: current_user} do
|
||||
assert 50 = pack |> Ammo.get_original_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 14}, current_user, pack)
|
||||
shot_record_fixture(%{count: 14}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 50 = pack |> Ammo.get_original_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 11}, current_user, pack)
|
||||
shot_record_fixture(%{count: 11}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 50 = pack |> Ammo.get_original_count(current_user)
|
||||
|
||||
shot_group_fixture(%{count: 25}, current_user, pack)
|
||||
shot_record_fixture(%{count: 25}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
assert 50 = pack |> Ammo.get_original_count(current_user)
|
||||
end
|
||||
@ -1192,19 +1192,19 @@ defmodule Cannery.AmmoTest do
|
||||
assert %{^pack_id => 50} = original_counts
|
||||
assert %{^another_pack_id => 25} = original_counts
|
||||
|
||||
shot_group_fixture(%{count: 14}, current_user, pack)
|
||||
shot_record_fixture(%{count: 14}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
original_counts = [pack, another_pack] |> Ammo.get_original_counts(current_user)
|
||||
assert %{^pack_id => 50} = original_counts
|
||||
assert %{^another_pack_id => 25} = original_counts
|
||||
|
||||
shot_group_fixture(%{count: 11}, current_user, pack)
|
||||
shot_record_fixture(%{count: 11}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
original_counts = [pack, another_pack] |> Ammo.get_original_counts(current_user)
|
||||
assert %{^pack_id => 50} = original_counts
|
||||
assert %{^another_pack_id => 25} = original_counts
|
||||
|
||||
shot_group_fixture(%{count: 25}, current_user, pack)
|
||||
shot_record_fixture(%{count: 25}, current_user, pack)
|
||||
pack = Ammo.get_pack!(pack_id, current_user)
|
||||
original_counts = [pack, another_pack] |> Ammo.get_original_counts(current_user)
|
||||
assert %{^pack_id => 50} = original_counts
|
||||
|
@ -16,14 +16,14 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
tag = tag_fixture(current_user)
|
||||
Containers.add_tag!(container, tag, current_user)
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(current_user, pack)
|
||||
shot_record = shot_record_fixture(current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
|
||||
%{
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
container: container,
|
||||
shot_group: shot_group,
|
||||
shot_record: shot_record,
|
||||
tag: tag
|
||||
}
|
||||
end
|
||||
@ -37,7 +37,7 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
shot_group: shot_group,
|
||||
shot_record: shot_record,
|
||||
tag: tag
|
||||
} do
|
||||
conn = get(conn, Routes.export_path(conn, :export, :json))
|
||||
@ -104,12 +104,12 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
"round_count" => container |> Ammo.get_round_count_for_container!(current_user)
|
||||
}
|
||||
|
||||
ideal_shot_group = %{
|
||||
"pack_id" => shot_group.pack_id,
|
||||
"count" => shot_group.count,
|
||||
"date" => to_string(shot_group.date),
|
||||
"id" => shot_group.id,
|
||||
"notes" => shot_group.notes
|
||||
ideal_shot_record = %{
|
||||
"pack_id" => shot_record.pack_id,
|
||||
"count" => shot_record.count,
|
||||
"date" => to_string(shot_record.date),
|
||||
"id" => shot_record.id,
|
||||
"notes" => shot_record.notes
|
||||
}
|
||||
|
||||
ideal_user = %{
|
||||
@ -127,7 +127,7 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
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
|
||||
assert %{"shot_records" => [^ideal_shot_record]} = json_resp
|
||||
assert %{"user" => ^ideal_user} = json_resp
|
||||
end
|
||||
end
|
||||
|
@ -37,8 +37,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
notes: "some pack",
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
notes: "some shot group",
|
||||
@shot_record_attrs %{
|
||||
notes: "some shot recorddd",
|
||||
count: 20
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
defp create_empty_pack(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
container = container_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, container: container, shot_group: shot_group]
|
||||
[pack: pack, container: container, shot_record: shot_record]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -275,7 +275,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
assert html =~ "\n0\n"
|
||||
assert html =~ "\n1\n"
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
shot_record_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
|
@ -12,18 +12,18 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
@update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7}
|
||||
@invalid_attrs %{count: nil, notes: nil, price_paid: nil}
|
||||
@pack_create_limit 10_000
|
||||
@shot_group_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_group_update_attrs %{
|
||||
@shot_record_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_record_update_attrs %{
|
||||
count: 5,
|
||||
date: ~N[2022-02-13 03:17:00],
|
||||
notes: "some updated notes"
|
||||
}
|
||||
@shot_group_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
|
||||
@shot_record_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
|
||||
@empty_attrs %{
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
@shot_record_attrs %{
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
@ -35,10 +35,10 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
[ammo_type: ammo_type, pack: pack, container: container]
|
||||
end
|
||||
|
||||
defp create_shot_group(%{current_user: current_user, pack: pack}) do
|
||||
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, pack)
|
||||
defp create_shot_record(%{current_user: current_user, pack: pack}) do
|
||||
shot_record = shot_record_fixture(@shot_record_update_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, shot_group: shot_group]
|
||||
[pack: pack, shot_record: shot_record]
|
||||
end
|
||||
|
||||
defp create_empty_pack(%{
|
||||
@ -47,9 +47,9 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
container: container
|
||||
}) do
|
||||
{1, [pack]} = pack_fixture(@empty_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[empty_pack: pack, shot_group: shot_group]
|
||||
[empty_pack: pack, shot_record: shot_record]
|
||||
end
|
||||
|
||||
describe "Index of pack" do
|
||||
@ -311,20 +311,20 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
refute has_element?(index_live, "#pack-#{pack.id}")
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{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.pack_index_path(conn, :add_shot_group, pack))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> render_submit(shot_record: @shot_record_create_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
@ -394,66 +394,66 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{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.pack_show_path(conn, :add_shot_group, pack))
|
||||
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> render_submit(shot_record: @shot_record_create_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show pack with shot group" do
|
||||
setup [:register_and_log_in_user, :create_pack, :create_shot_group]
|
||||
describe "Show pack with shot recorddd" do
|
||||
setup [:register_and_log_in_user, :create_pack, :create_shot_record]
|
||||
|
||||
test "updates shot_group in listing",
|
||||
%{conn: conn, pack: pack, shot_group: shot_group} do
|
||||
test "updates shot_record in listing",
|
||||
%{conn: conn, pack: pack, shot_record: shot_record} 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"]/)
|
||||
|> element(~s/a[aria-label="Edit shot recordd of #{shot_record.count} shots"]/)
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group)
|
||||
Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record)
|
||||
)
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_update_attrs)
|
||||
|> render_submit(shot_record: @shot_record_update_attrs)
|
||||
|> 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, pack: pack, shot_group: shot_group} do
|
||||
test "deletes shot_record in listing",
|
||||
%{conn: conn, pack: pack, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} =
|
||||
live(conn, Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group))
|
||||
live(conn, Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click()
|
||||
|
||||
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
|
||||
refute has_element?(index_live, "#shot_record-#{shot_record.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,32 +12,32 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
@update_attrs %{count: 16, notes: "some updated notes"}
|
||||
@invalid_attrs %{count: nil, notes: nil}
|
||||
|
||||
defp create_shot_group(%{current_user: current_user}) do
|
||||
defp create_shot_record(%{current_user: current_user}) do
|
||||
container = container_fixture(%{staged: true}, current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
|
||||
{1, [pack]} = pack_fixture(%{staged: true}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
shot_record =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, pack)
|
||||
|> shot_record_fixture(current_user, pack)
|
||||
|
||||
[
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
shot_record: shot_record
|
||||
]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:register_and_log_in_user, :create_shot_group]
|
||||
setup [:register_and_log_in_user, :create_shot_record]
|
||||
|
||||
test "lists all shot_groups", %{conn: conn, shot_group: shot_group} do
|
||||
test "lists all shot_records", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Range day"
|
||||
assert html =~ shot_group.notes
|
||||
assert html =~ shot_record.notes
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
@ -45,123 +45,123 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, 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_pack)
|
||||
rifle_shot_record = shot_record_fixture(%{notes: "group_one"}, current_user, rifle_pack)
|
||||
|
||||
shotgun_ammo_type = ammo_type_fixture(%{class: :shotgun}, 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_pack)
|
||||
shotgun_shot_record = shot_record_fixture(%{notes: "group_two"}, current_user, shotgun_pack)
|
||||
|
||||
pistol_ammo_type = ammo_type_fixture(%{class: :pistol}, 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_pack)
|
||||
pistol_shot_record = shot_record_fixture(%{notes: "group_three"}, current_user, pistol_pack)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "All"
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :rifle})
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
refute html =~ shotgun_shot_group.notes
|
||||
refute html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
refute html =~ shotgun_shot_record.notes
|
||||
refute html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :shotgun})
|
||||
|
||||
refute html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
refute html =~ pistol_shot_group.notes
|
||||
refute html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
refute html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :pistol})
|
||||
|
||||
refute html =~ rifle_shot_group.notes
|
||||
refute html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
refute html =~ rifle_shot_record.notes
|
||||
refute html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :all})
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
end
|
||||
|
||||
test "can search for shot_group", %{conn: conn, shot_group: shot_group} do
|
||||
test "can search for shot_record", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ shot_group.notes
|
||||
assert html =~ shot_record.notes
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: shot_group.notes}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: shot_record.notes}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_group.notes))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_record.notes))
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: "something_else"}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: "something_else"}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: ""}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :index))
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{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, pack))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @create_attrs)
|
||||
|> render_submit(shot_record: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
assert html =~ "some notes"
|
||||
end
|
||||
|
||||
test "updates shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
||||
test "updates shot_record in listing", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Edit shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_group))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_record))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @update_attrs)
|
||||
|> form("#shot-group-form", shot_record: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
@ -169,14 +169,14 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "deletes shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
||||
test "deletes shot_record in listing", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click()
|
||||
|
||||
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
|
||||
refute has_element?(index_live, "#shot_record-#{shot_record.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ defmodule Cannery.Fixtures do
|
||||
alias Cannery.{
|
||||
Accounts,
|
||||
Accounts.User,
|
||||
ActivityLog.ShotGroup,
|
||||
ActivityLog.ShotRecord,
|
||||
Ammo,
|
||||
Ammo.AmmoType,
|
||||
Ammo.Pack,
|
||||
@ -69,18 +69,18 @@ defmodule Cannery.Fixtures do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a ShotGroup
|
||||
Generate a ShotRecord
|
||||
"""
|
||||
@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
|
||||
@spec shot_record_fixture(User.t(), Pack.t()) :: ShotRecord.t()
|
||||
@spec shot_record_fixture(attrs :: map(), User.t(), Pack.t()) :: ShotRecord.t()
|
||||
def shot_record_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, pack)
|
||||
|> Cannery.ActivityLog.create_shot_record(user, pack)
|
||||
|> unwrap_ok_tuple()
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user