improve tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
shibao 2023-04-15 21:47:50 -04:00
parent beeaf521c5
commit e6ef0a8c68
9 changed files with 4 additions and 42 deletions

View File

@ -1,3 +1,6 @@
# v0.9.4
- Improve tests
# v0.9.3
- Update dependencies
- Add pack lot number to search

View File

@ -4,7 +4,7 @@ defmodule Cannery.MixProject do
def project do
[
app: :cannery,
version: "0.9.3",
version: "0.9.4",
elixir: "1.14.4",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,

View File

@ -44,7 +44,6 @@ defmodule CanneryWeb.UserAuthTest do
conn |> fetch_cookies() |> UserAuth.log_in_user(current_user, %{"remember_me" => "true"})
assert get_session(conn, :user_token) == conn.cookies[@remember_me_cookie]
assert %{value: signed_token, max_age: max_age} = conn.resp_cookies[@remember_me_cookie]
assert signed_token != get_session(conn, :user_token)
assert max_age == 5_184_000

View File

@ -70,7 +70,6 @@ defmodule CanneryWeb.UserConfirmationControllerTest do
# When not logged in
conn = get(conn, ~p"/users/confirm/#{token}")
assert redirected_to(conn) == ~p"/"
assert conn.assigns.flash["error"] =~ "User confirmation link is invalid or it has expired"
# When logged in

View File

@ -22,14 +22,12 @@ defmodule CanneryWeb.InviteLiveTest do
test "lists all invites", %{conn: conn, invite: invite} do
{:ok, _index_live, html} = live(conn, ~p"/invites")
assert html =~ "Invites"
assert html =~ invite.name
end
test "saves new invite", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/invites")
assert index_live |> element("a", "Create Invite") |> render_click() =~ "New Invite"
assert_patch(index_live, ~p"/invites/new")

View File

@ -72,9 +72,7 @@ defmodule CanneryWeb.PackLiveTest do
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
{:ok, index_live, html} = live(conn, ~p"/ammo")
assert html =~ "All"
assert html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
@ -120,7 +118,6 @@ defmodule CanneryWeb.PackLiveTest do
{:ok, index_live, html} = live(conn, ~p"/ammo")
pack = pack |> Repo.preload(:type)
assert html =~ pack.type.name
assert index_live
@ -146,7 +143,6 @@ defmodule CanneryWeb.PackLiveTest do
test "saves a single new pack", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, ~p"/ammo/new")
@ -167,7 +163,6 @@ defmodule CanneryWeb.PackLiveTest do
test "saves multiple new packs", %{conn: conn, current_user: current_user} do
multiplier = 25
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, ~p"/ammo/new")
@ -187,7 +182,6 @@ defmodule CanneryWeb.PackLiveTest do
test "does not save invalid number of new packs", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
assert_patch(index_live, ~p"/ammo/new")
@ -239,7 +233,6 @@ defmodule CanneryWeb.PackLiveTest do
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
assert_patch(index_live, ~p"/ammo/clone/#{pack}")
{:ok, _index_live, html} =
@ -263,7 +256,6 @@ defmodule CanneryWeb.PackLiveTest do
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
assert_patch(index_live, ~p"/ammo/clone/#{pack}")
assert index_live
@ -310,7 +302,6 @@ defmodule CanneryWeb.PackLiveTest do
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, ~p"/ammo")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, ~p"/ammo/add_shot_record/#{pack}")
@ -340,10 +331,8 @@ defmodule CanneryWeb.PackLiveTest do
current_user: current_user
} do
{:ok, show_live, html} = live(conn, ~p"/ammo")
assert html =~ "Show used"
refute html =~ "$#{display_currency(50.00)}"
percentage = pack |> Ammo.get_percentage_remaining(current_user)
refute html =~ "\n#{"#{percentage}%"}\n"
@ -393,7 +382,6 @@ defmodule CanneryWeb.PackLiveTest do
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, ~p"/ammo/show/#{pack}")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, ~p"/ammo/show/add_shot_record/#{pack}")

View File

@ -35,7 +35,6 @@ defmodule CanneryWeb.RangeLiveTest do
test "lists all shot_records", %{conn: conn, shot_record: shot_record} do
{:ok, _index_live, html} = live(conn, ~p"/range")
assert html =~ "Range day"
assert html =~ shot_record.notes
end
@ -44,23 +43,18 @@ defmodule CanneryWeb.RangeLiveTest do
%{conn: conn, container: container, current_user: current_user} do
rifle_type = type_fixture(%{class: :rifle}, current_user)
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
rifle_shot_record = shot_record_fixture(%{notes: "group_one"}, current_user, rifle_pack)
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
shotgun_shot_record = shot_record_fixture(%{notes: "group_two"}, current_user, shotgun_pack)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
pistol_shot_record = shot_record_fixture(%{notes: "group_three"}, current_user, pistol_pack)
{:ok, index_live, html} = live(conn, ~p"/range")
assert html =~ "All"
assert html =~ rifle_shot_record.notes
assert html =~ shotgun_shot_record.notes
assert html =~ pistol_shot_record.notes
@ -104,7 +98,6 @@ defmodule CanneryWeb.RangeLiveTest do
test "can search for shot_record", %{conn: conn, shot_record: shot_record} do
{:ok, index_live, html} = live(conn, ~p"/range")
assert html =~ shot_record.notes
assert index_live
@ -128,7 +121,6 @@ defmodule CanneryWeb.RangeLiveTest do
test "saves new shot_record", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, ~p"/range")
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
assert_patch(index_live, ~p"/range/add_shot_record/#{pack}")

View File

@ -34,14 +34,12 @@ defmodule CanneryWeb.TagLiveTest do
test "lists all tags", %{conn: conn, tag: tag} do
{:ok, _index_live, html} = live(conn, ~p"/tags")
assert html =~ "Tags"
assert html =~ tag.bg_color
end
test "can search for tag", %{conn: conn, tag: tag} do
{:ok, index_live, html} = live(conn, ~p"/tags")
assert html =~ tag.name
assert index_live
@ -65,7 +63,6 @@ defmodule CanneryWeb.TagLiveTest do
test "saves new tag", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/tags")
assert index_live |> element("a", "New Tag") |> render_click() =~ "New Tag"
assert_patch(index_live, ~p"/tags/new")
@ -107,7 +104,6 @@ defmodule CanneryWeb.TagLiveTest do
test "deletes tag in listing", %{conn: conn, tag: tag} do
{:ok, index_live, _html} = live(conn, ~p"/tags")
assert index_live |> element(~s/a[aria-label="Delete #{tag.name}"]/) |> render_click()
refute has_element?(index_live, "#tag-#{tag.id}")
end

View File

@ -75,9 +75,7 @@ defmodule CanneryWeb.TypeLiveTest do
pistol_type = type_fixture(%{class: :pistol}, current_user)
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ "All"
assert html =~ rifle_type.name
assert html =~ shotgun_type.name
assert html =~ pistol_type.name
@ -121,7 +119,6 @@ defmodule CanneryWeb.TypeLiveTest do
test "can search for type", %{conn: conn, type: type} do
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ type.bullet_type
assert index_live
@ -146,7 +143,6 @@ defmodule CanneryWeb.TypeLiveTest do
test "saves new type", %{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, ~p"/catalog")
assert index_live |> element("a", "New Type") |> render_click() =~ "New Type"
assert_patch(index_live, ~p"/catalog/new")
@ -192,11 +188,9 @@ defmodule CanneryWeb.TypeLiveTest do
test "clones type in listing",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, ~p"/catalog/clone/#{type}")
assert index_live
@ -217,11 +211,9 @@ defmodule CanneryWeb.TypeLiveTest do
test "clones type in listing with updates",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, ~p"/catalog/clone/#{type}")
assert index_live
@ -254,7 +246,6 @@ defmodule CanneryWeb.TypeLiveTest do
test "shows used packs on toggle",
%{conn: conn, pack: pack, current_user: current_user} do
{:ok, index_live, html} = live(conn, ~p"/catalog")
assert html =~ "Show used"
refute html =~ "Used rounds"
refute html =~ "Total ever rounds"
@ -270,13 +261,11 @@ defmodule CanneryWeb.TypeLiveTest do
assert html =~ "Total ever rounds"
assert html =~ "Used packs"
assert html =~ "Total ever packs"
assert html =~ "\n20\n"
assert html =~ "\n0\n"
assert html =~ "\n1\n"
shot_record_fixture(%{count: 5}, current_user, pack)
{:ok, index_live, _html} = live(conn, ~p"/catalog")
html =
@ -297,7 +286,6 @@ defmodule CanneryWeb.TypeLiveTest do
type: %{name: name, bullet_type: bullet_type} = type
} do
{:ok, _show_live, html} = live(conn, ~p"/type/#{type}")
assert html =~ name
assert html =~ bullet_type
end
@ -336,7 +324,6 @@ defmodule CanneryWeb.TypeLiveTest do
container: %{name: container_name}
} do
{:ok, _show_live, html} = live(conn, ~p"/type/#{type}")
assert html =~ type_name
assert html =~ "\n20\n"
assert html =~ container_name