dings with user assoc
This commit is contained in:
69
test/dinge/ledger_test.exs
Normal file
69
test/dinge/ledger_test.exs
Normal file
@ -0,0 +1,69 @@
|
||||
defmodule Dinge.LedgerTest do
|
||||
use Dinge.DataCase
|
||||
|
||||
alias Dinge.Ledger
|
||||
|
||||
describe "dings" do
|
||||
alias Dinge.Ledger.Ding
|
||||
|
||||
import Dinge.LedgerFixtures
|
||||
|
||||
@invalid_attrs %{count: nil, status: nil, title: nil, target_count: nil, ding_type: nil, target_type: nil}
|
||||
|
||||
test "list_dings/0 returns all dings" do
|
||||
ding = ding_fixture()
|
||||
assert Ledger.list_dings() == [ding]
|
||||
end
|
||||
|
||||
test "get_ding!/1 returns the ding with given id" do
|
||||
ding = ding_fixture()
|
||||
assert Ledger.get_ding!(ding.id) == ding
|
||||
end
|
||||
|
||||
test "create_ding/1 with valid data creates a ding" do
|
||||
valid_attrs = %{count: 42, status: :active, title: "some title", target_count: 42, ding_type: :countdown, target_type: :default}
|
||||
|
||||
assert {:ok, %Ding{} = ding} = Ledger.create_ding(valid_attrs)
|
||||
assert ding.count == 42
|
||||
assert ding.status == :active
|
||||
assert ding.title == "some title"
|
||||
assert ding.target_count == 42
|
||||
assert ding.ding_type == :countdown
|
||||
assert ding.target_type == :default
|
||||
end
|
||||
|
||||
test "create_ding/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Ledger.create_ding(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_ding/2 with valid data updates the ding" do
|
||||
ding = ding_fixture()
|
||||
update_attrs = %{count: 43, status: :inactive, title: "some updated title", target_count: 43, ding_type: :countup, target_type: :daily}
|
||||
|
||||
assert {:ok, %Ding{} = ding} = Ledger.update_ding(ding, update_attrs)
|
||||
assert ding.count == 43
|
||||
assert ding.status == :inactive
|
||||
assert ding.title == "some updated title"
|
||||
assert ding.target_count == 43
|
||||
assert ding.ding_type == :countup
|
||||
assert ding.target_type == :daily
|
||||
end
|
||||
|
||||
test "update_ding/2 with invalid data returns error changeset" do
|
||||
ding = ding_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Ledger.update_ding(ding, @invalid_attrs)
|
||||
assert ding == Ledger.get_ding!(ding.id)
|
||||
end
|
||||
|
||||
test "delete_ding/1 deletes the ding" do
|
||||
ding = ding_fixture()
|
||||
assert {:ok, %Ding{}} = Ledger.delete_ding(ding)
|
||||
assert_raise Ecto.NoResultsError, fn -> Ledger.get_ding!(ding.id) end
|
||||
end
|
||||
|
||||
test "change_ding/1 returns a ding changeset" do
|
||||
ding = ding_fixture()
|
||||
assert %Ecto.Changeset{} = Ledger.change_ding(ding)
|
||||
end
|
||||
end
|
||||
end
|
113
test/dinge_web/live/ding_live_test.exs
Normal file
113
test/dinge_web/live/ding_live_test.exs
Normal file
@ -0,0 +1,113 @@
|
||||
defmodule DingeWeb.DingLiveTest do
|
||||
use DingeWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Dinge.LedgerFixtures
|
||||
|
||||
@create_attrs %{count: 42, status: :active, title: "some title", target_count: 42, ding_type: :countdown, target_type: :default}
|
||||
@update_attrs %{count: 43, status: :inactive, title: "some updated title", target_count: 43, ding_type: :countup, target_type: :daily}
|
||||
@invalid_attrs %{count: nil, status: nil, title: nil, target_count: nil, ding_type: nil, target_type: nil}
|
||||
|
||||
defp create_ding(_) do
|
||||
ding = ding_fixture()
|
||||
%{ding: ding}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_ding]
|
||||
|
||||
test "lists all dings", %{conn: conn, ding: ding} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/dings")
|
||||
|
||||
assert html =~ "Listing Dings"
|
||||
assert html =~ ding.title
|
||||
end
|
||||
|
||||
test "saves new ding", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/dings")
|
||||
|
||||
assert index_live |> element("a", "New Ding") |> render_click() =~
|
||||
"New Ding"
|
||||
|
||||
assert_patch(index_live, ~p"/dings/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#ding-form", ding: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#ding-form", ding: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/dings")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Ding created successfully"
|
||||
assert html =~ "some title"
|
||||
end
|
||||
|
||||
test "updates ding in listing", %{conn: conn, ding: ding} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/dings")
|
||||
|
||||
assert index_live |> element("#dings-#{ding.id} a", "Edit") |> render_click() =~
|
||||
"Edit Ding"
|
||||
|
||||
assert_patch(index_live, ~p"/dings/#{ding}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#ding-form", ding: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#ding-form", ding: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/dings")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Ding updated successfully"
|
||||
assert html =~ "some updated title"
|
||||
end
|
||||
|
||||
test "deletes ding in listing", %{conn: conn, ding: ding} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/dings")
|
||||
|
||||
assert index_live |> element("#dings-#{ding.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#dings-#{ding.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_ding]
|
||||
|
||||
test "displays ding", %{conn: conn, ding: ding} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/dings/#{ding}")
|
||||
|
||||
assert html =~ "Show Ding"
|
||||
assert html =~ ding.title
|
||||
end
|
||||
|
||||
test "updates ding within modal", %{conn: conn, ding: ding} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/dings/#{ding}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Ding"
|
||||
|
||||
assert_patch(show_live, ~p"/dings/#{ding}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#ding-form", ding: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#ding-form", ding: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/dings/#{ding}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Ding updated successfully"
|
||||
assert html =~ "some updated title"
|
||||
end
|
||||
end
|
||||
end
|
25
test/support/fixtures/ledger_fixtures.ex
Normal file
25
test/support/fixtures/ledger_fixtures.ex
Normal file
@ -0,0 +1,25 @@
|
||||
defmodule Dinge.LedgerFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Dinge.Ledger` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a ding.
|
||||
"""
|
||||
def ding_fixture(attrs \\ %{}) do
|
||||
{:ok, ding} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
count: 42,
|
||||
ding_type: :countdown,
|
||||
status: :active,
|
||||
target_count: 42,
|
||||
target_type: :default,
|
||||
title: "some title"
|
||||
})
|
||||
|> Dinge.Ledger.create_ding()
|
||||
|
||||
ding
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user