forked from shibao/cannery
fix tests
This commit is contained in:
parent
16018ae111
commit
820ceed6bb
@ -9,17 +9,16 @@ config :bcrypt_elixir, :log_rounds, 1
|
||||
# to provide built-in test partitioning in CI environment.
|
||||
# Run `mix help test` for more information.
|
||||
config :cannery, Cannery.Repo,
|
||||
username: "postgres",
|
||||
password: "postgres",
|
||||
hostname: "localhost",
|
||||
database: "cannery_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||
url:
|
||||
System.get_env("DATABASE_URL") ||
|
||||
"ecto://postgres:postgres@localhost/cannery_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||
pool: Ecto.Adapters.SQL.Sandbox,
|
||||
pool_size: 10
|
||||
|
||||
# We don't run a server during test. If one is required,
|
||||
# you can enable the server option below.
|
||||
config :cannery, CanneryWeb.Endpoint,
|
||||
http: [ip: {127, 0, 0, 1}, port: 4002],
|
||||
http: [ip: {0, 0, 0, 0}, port: 4002],
|
||||
secret_key_base: "S3qq9QtUdsFtlYej+HTjAVN95uP5i5tf2sPYINWSQfCKJghFj2B1+wTAoljZyHOK",
|
||||
server: false
|
||||
|
||||
|
@ -96,7 +96,8 @@ defmodule Cannery.Invites do
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
@spec create_invite(Accounts.User.t() | Ecto.UUID.t(), map()) :: Invite.t()
|
||||
@spec create_invite(user_or_user_id :: Accounts.User.t() | Ecto.UUID.t(), attrs :: map()) ::
|
||||
Invite.t()
|
||||
def create_invite(%{id: user_id}, attrs) do
|
||||
create_invite(user_id, attrs)
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,9 +6,30 @@ defmodule Cannery.AmmoTest do
|
||||
describe "ammo_types" do
|
||||
alias Cannery.Ammo.AmmoType
|
||||
|
||||
@valid_attrs %{bullet_type: "some bullet_type", case_material: "some case_material", desc: "some desc", manufacturer: "some manufacturer", name: "some name", weight: 120.5}
|
||||
@update_attrs %{bullet_type: "some updated bullet_type", case_material: "some updated case_material", desc: "some updated desc", manufacturer: "some updated manufacturer", name: "some updated name", weight: 456.7}
|
||||
@invalid_attrs %{bullet_type: nil, case_material: nil, desc: nil, manufacturer: nil, name: nil, weight: nil}
|
||||
@valid_attrs %{
|
||||
"bullet_type" => "some bullet_type",
|
||||
"case_material" => "some case_material",
|
||||
"desc" => "some desc",
|
||||
"manufacturer" => "some manufacturer",
|
||||
"name" => "some name",
|
||||
"weight" => 120.5
|
||||
}
|
||||
@update_attrs %{
|
||||
"bullet_type" => "some updated bullet_type",
|
||||
"case_material" => "some updated case_material",
|
||||
"desc" => "some updated desc",
|
||||
"manufacturer" => "some updated manufacturer",
|
||||
"name" => "some updated name",
|
||||
"weight" => 456.7
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"bullet_type" => nil,
|
||||
"case_material" => nil,
|
||||
"desc" => nil,
|
||||
"manufacturer" => nil,
|
||||
"name" => nil,
|
||||
"weight" => nil
|
||||
}
|
||||
|
||||
def ammo_type_fixture(attrs \\ %{}) do
|
||||
{:ok, ammo_type} =
|
||||
|
@ -6,8 +6,18 @@ defmodule Cannery.ContainersTest do
|
||||
describe "containers" do
|
||||
alias Cannery.Containers.Container
|
||||
|
||||
@valid_attrs %{desc: "some desc", location: "some location", name: "some name", type: "some type"}
|
||||
@update_attrs %{desc: "some updated desc", location: "some updated location", name: "some updated name", type: "some updated type"}
|
||||
@valid_attrs %{
|
||||
"desc" => "some desc",
|
||||
"location" => "some location",
|
||||
"name" => "some name",
|
||||
"type" => "some type"
|
||||
}
|
||||
@update_attrs %{
|
||||
"desc" => "some updated desc",
|
||||
"location" => "some updated location",
|
||||
"name" => "some updated name",
|
||||
"type" => "some updated type"
|
||||
}
|
||||
@invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
|
||||
|
||||
def container_fixture(attrs \\ %{}) do
|
||||
@ -43,7 +53,10 @@ defmodule Cannery.ContainersTest do
|
||||
|
||||
test "update_container/2 with valid data updates the container" do
|
||||
container = container_fixture()
|
||||
assert {:ok, %Container{} = container} = Containers.update_container(container, @update_attrs)
|
||||
|
||||
assert {:ok, %Container{} = container} =
|
||||
Containers.update_container(container, @update_attrs)
|
||||
|
||||
assert container.desc == "some updated desc"
|
||||
assert container.location == "some updated location"
|
||||
assert container.name == "some updated name"
|
||||
|
@ -1,20 +1,28 @@
|
||||
defmodule Cannery.InvitesTest do
|
||||
use Cannery.DataCase
|
||||
|
||||
alias Cannery.Invites
|
||||
alias Cannery.{AccountsFixtures, Invites}
|
||||
|
||||
describe "invites" do
|
||||
alias Cannery.Invites.Invite
|
||||
|
||||
@valid_attrs %{name: "some name", token: "some token"}
|
||||
@update_attrs %{name: "some updated name", token: "some updated token"}
|
||||
@invalid_attrs %{name: nil, token: nil}
|
||||
@valid_attrs %{
|
||||
"name" => "some name",
|
||||
"token" => "some token"
|
||||
}
|
||||
@update_attrs %{
|
||||
"name" => "some updated name",
|
||||
"token" => "some updated token"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"name" => nil,
|
||||
"token" => nil
|
||||
}
|
||||
|
||||
def invite_fixture(attrs \\ %{}) do
|
||||
{:ok, invite} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Invites.create_invite()
|
||||
AccountsFixtures.user_fixture()
|
||||
|> Invites.create_invite(attrs |> Enum.into(@valid_attrs))
|
||||
|
||||
invite
|
||||
end
|
||||
|
@ -1,18 +1,33 @@
|
||||
defmodule Cannery.TagsTest do
|
||||
use Cannery.DataCase
|
||||
|
||||
alias Cannery.Tags
|
||||
alias Cannery.{AccountsFixtures, Tags}
|
||||
|
||||
describe "tags" do
|
||||
alias Cannery.Tags.Tag
|
||||
|
||||
@valid_attrs %{bg_color: "some bg-color", name: "some name", text_color: "some text-color"}
|
||||
@update_attrs %{bg_color: "some updated bg-color", name: "some updated name", text_color: "some updated text-color"}
|
||||
@invalid_attrs %{bg_color: nil, name: nil, text_color: nil}
|
||||
@valid_attrs %{
|
||||
"bg_color" => "some bg-color",
|
||||
"name" => "some name",
|
||||
"text_color" => "some text-color"
|
||||
}
|
||||
@update_attrs %{
|
||||
"bg_color" => "some updated bg-color",
|
||||
"name" => "some updated name",
|
||||
"text_color" => "some updated text-color"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"bg_color" => nil,
|
||||
"name" => nil,
|
||||
"text_color" => nil
|
||||
}
|
||||
|
||||
def tag_fixture(attrs \\ %{}) do
|
||||
%{id: user_id} = AccountsFixtures.user_fixture()
|
||||
|
||||
{:ok, tag} =
|
||||
attrs
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Tags.create_tag()
|
||||
|
||||
@ -31,9 +46,9 @@ defmodule Cannery.TagsTest do
|
||||
|
||||
test "create_tag/1 with valid data creates a tag" do
|
||||
assert {:ok, %Tag{} = tag} = Tags.create_tag(@valid_attrs)
|
||||
assert tag.bg-color == "some bg-color"
|
||||
assert tag.bg_color == "some bg-color"
|
||||
assert tag.name == "some name"
|
||||
assert tag.text-color == "some text-color"
|
||||
assert tag.text_color == "some text-color"
|
||||
end
|
||||
|
||||
test "create_tag/1 with invalid data returns error changeset" do
|
||||
@ -43,9 +58,9 @@ defmodule Cannery.TagsTest do
|
||||
test "update_tag/2 with valid data updates the tag" do
|
||||
tag = tag_fixture()
|
||||
assert {:ok, %Tag{} = tag} = Tags.update_tag(tag, @update_attrs)
|
||||
assert tag.bg-color == "some updated bg-color"
|
||||
assert tag.bg_color == "some updated bg-color"
|
||||
assert tag.name == "some updated name"
|
||||
assert tag.text-color == "some updated text-color"
|
||||
assert tag.text_color == "some updated text-color"
|
||||
end
|
||||
|
||||
test "update_tag/2 with invalid data returns error changeset" do
|
||||
|
@ -5,9 +5,30 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
|
||||
alias Cannery.Ammo
|
||||
|
||||
@create_attrs %{bullet_type: "some bullet_type", case_material: "some case_material", desc: "some desc", manufacturer: "some manufacturer", name: "some name", weight: 120.5}
|
||||
@update_attrs %{bullet_type: "some updated bullet_type", case_material: "some updated case_material", desc: "some updated desc", manufacturer: "some updated manufacturer", name: "some updated name", weight: 456.7}
|
||||
@invalid_attrs %{bullet_type: nil, case_material: nil, desc: nil, manufacturer: nil, name: nil, weight: nil}
|
||||
@create_attrs %{
|
||||
"bullet_type" => "some bullet_type",
|
||||
"case_material" => "some case_material",
|
||||
"desc" => "some desc",
|
||||
"manufacturer" => "some manufacturer",
|
||||
"name" => "some name",
|
||||
"weight" => 120.5
|
||||
}
|
||||
@update_attrs %{
|
||||
"bullet_type" => "some updated bullet_type",
|
||||
"case_material" => "some updated case_material",
|
||||
"desc" => "some updated desc",
|
||||
"manufacturer" => "some updated manufacturer",
|
||||
"name" => "some updated name",
|
||||
"weight" => 456.7
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"bullet_type" => nil,
|
||||
"case_material" => nil,
|
||||
"desc" => nil,
|
||||
"manufacturer" => nil,
|
||||
"name" => nil,
|
||||
"weight" => nil
|
||||
}
|
||||
|
||||
defp fixture(:ammo_type) do
|
||||
{:ok, ammo_type} = Ammo.create_ammo_type(@create_attrs)
|
||||
|
@ -5,8 +5,18 @@ defmodule CanneryWeb.ContainerLiveTest do
|
||||
|
||||
alias Cannery.Containers
|
||||
|
||||
@create_attrs %{desc: "some desc", location: "some location", name: "some name", type: "some type"}
|
||||
@update_attrs %{desc: "some updated desc", location: "some updated location", name: "some updated name", type: "some updated type"}
|
||||
@create_attrs %{
|
||||
"desc" => "some desc",
|
||||
"location" => "some location",
|
||||
"name" => "some name",
|
||||
"type" => "some type"
|
||||
}
|
||||
@update_attrs %{
|
||||
"desc" => "some updated desc",
|
||||
"location" => "some updated location",
|
||||
"name" => "some updated name",
|
||||
"type" => "some updated type"
|
||||
}
|
||||
@invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
|
||||
|
||||
defp fixture(:container) do
|
||||
|
@ -5,9 +5,21 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
|
||||
alias Cannery.Tags
|
||||
|
||||
@create_attrs %{bg_color: "some bg-color", name: "some name", text_color: "some text-color"}
|
||||
@update_attrs %{bg_color: "some updated bg-color", name: "some updated name", text_color: "some updated text-color"}
|
||||
@invalid_attrs %{bg_color: nil, name: nil, text_color: nil}
|
||||
@create_attrs %{
|
||||
"bg_color" => "some bg-color",
|
||||
"name" => "some name",
|
||||
"text_color" => "some text-color"
|
||||
}
|
||||
@update_attrs %{
|
||||
"bg_color" => "some updated bg-color",
|
||||
"name" => "some updated name",
|
||||
"text_color" => "some updated text-color"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
"bg_color" => nil,
|
||||
"name" => nil,
|
||||
"text_color" => nil
|
||||
}
|
||||
|
||||
defp fixture(:tag) do
|
||||
{:ok, tag} = Tags.create_tag(@create_attrs)
|
||||
@ -26,7 +38,7 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
{:ok, _index_live, html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Tags"
|
||||
assert html =~ tag.bg-color
|
||||
assert html =~ tag.bg_color
|
||||
end
|
||||
|
||||
test "saves new tag", %{conn: conn} do
|
||||
@ -88,7 +100,7 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
{:ok, _show_live, html} = live(conn, Routes.tag_show_path(conn, :show, tag))
|
||||
|
||||
assert html =~ "Show Tag"
|
||||
assert html =~ tag.bg-color
|
||||
assert html =~ tag.bg_color
|
||||
end
|
||||
|
||||
test "updates tag within modal", %{conn: conn, tag: tag} do
|
||||
|
@ -4,9 +4,13 @@ defmodule Cannery.AccountsFixtures do
|
||||
entities via the `Cannery.Accounts` context.
|
||||
"""
|
||||
|
||||
alias Cannery.{Accounts}
|
||||
|
||||
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
|
||||
def valid_user_password, do: "hello world!"
|
||||
|
||||
@spec user_fixture() :: Accounts.User.t()
|
||||
@spec user_fixture(attrs :: map()) :: Accounts.User.t()
|
||||
def user_fixture(attrs \\ %{}) do
|
||||
{:ok, user} =
|
||||
attrs
|
||||
@ -14,7 +18,7 @@ defmodule Cannery.AccountsFixtures do
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password()
|
||||
})
|
||||
|> Cannery.Accounts.register_user()
|
||||
|> Accounts.register_user()
|
||||
|
||||
user
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user