64 lines
2.1 KiB
Elixir
64 lines
2.1 KiB
Elixir
defmodule Bright.PatronsTest do
|
|
use Bright.DataCase
|
|
|
|
alias Bright.Patrons
|
|
|
|
describe "patrons" do
|
|
alias Bright.Patrons.Patron
|
|
|
|
import Bright.PatronsFixtures
|
|
|
|
@invalid_attrs %{name: nil, public: nil, lifetime_support_cents: nil}
|
|
|
|
test "list_patrons/0 returns all patrons" do
|
|
patron = patron_fixture()
|
|
assert Patrons.list_patrons() == [patron]
|
|
end
|
|
|
|
test "get_patron!/1 returns the patron with given id" do
|
|
patron = patron_fixture()
|
|
assert Patrons.get_patron!(patron.id) == patron
|
|
end
|
|
|
|
test "create_patron/1 with valid data creates a patron" do
|
|
valid_attrs = %{name: "some name", public: true, lifetime_support_cents: 42}
|
|
|
|
assert {:ok, %Patron{} = patron} = Patrons.create_patron(valid_attrs)
|
|
assert patron.name == "some name"
|
|
assert patron.public == true
|
|
assert patron.lifetime_support_cents == 42
|
|
end
|
|
|
|
test "create_patron/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Patrons.create_patron(@invalid_attrs)
|
|
end
|
|
|
|
test "update_patron/2 with valid data updates the patron" do
|
|
patron = patron_fixture()
|
|
update_attrs = %{name: "some updated name", public: false, lifetime_support_cents: 43}
|
|
|
|
assert {:ok, %Patron{} = patron} = Patrons.update_patron(patron, update_attrs)
|
|
assert patron.name == "some updated name"
|
|
assert patron.public == false
|
|
assert patron.lifetime_support_cents == 43
|
|
end
|
|
|
|
test "update_patron/2 with invalid data returns error changeset" do
|
|
patron = patron_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = Patrons.update_patron(patron, @invalid_attrs)
|
|
assert patron == Patrons.get_patron!(patron.id)
|
|
end
|
|
|
|
test "delete_patron/1 deletes the patron" do
|
|
patron = patron_fixture()
|
|
assert {:ok, %Patron{}} = Patrons.delete_patron(patron)
|
|
assert_raise Ecto.NoResultsError, fn -> Patrons.get_patron!(patron.id) end
|
|
end
|
|
|
|
test "change_patron/1 returns a patron changeset" do
|
|
patron = patron_fixture()
|
|
assert %Ecto.Changeset{} = Patrons.change_patron(patron)
|
|
end
|
|
end
|
|
end
|