forked from shibao/cannery
		
	add selectable ammo types
This commit is contained in:
		@@ -26,7 +26,7 @@ defmodule CanneryWeb.ConnCase do
 | 
			
		||||
      import Plug.Conn
 | 
			
		||||
      import Phoenix.ConnTest
 | 
			
		||||
      # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
 | 
			
		||||
      import Cannery.Fixtures
 | 
			
		||||
      import Cannery.{DataCase, Fixtures}
 | 
			
		||||
      import CanneryWeb.ConnCase
 | 
			
		||||
 | 
			
		||||
      alias CanneryWeb.Router.Helpers, as: Routes
 | 
			
		||||
 
 | 
			
		||||
@@ -48,4 +48,15 @@ defmodule Cannery.DataCase do
 | 
			
		||||
      end)
 | 
			
		||||
    end)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @doc """
 | 
			
		||||
  Generates a random string of any length, default of 12
 | 
			
		||||
  """
 | 
			
		||||
  @spec random_string(length :: non_neg_integer()) :: String.t()
 | 
			
		||||
  def random_string(length \\ 12) do
 | 
			
		||||
    :crypto.strong_rand_bytes(length) |> Base.url_encode64() |> binary_part(0, length)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def unique_user_email, do: "user#{System.unique_integer()}@example.com"
 | 
			
		||||
  def valid_user_password, do: "hello world!"
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,8 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
  This module defines test helpers for creating entities
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  import Cannery.DataCase
 | 
			
		||||
 | 
			
		||||
  alias Cannery.{
 | 
			
		||||
    Accounts,
 | 
			
		||||
    Accounts.User,
 | 
			
		||||
@@ -17,9 +19,6 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
    Repo
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  def unique_user_email, do: "user#{System.unique_integer()}@example.com"
 | 
			
		||||
  def valid_user_password, do: "hello world!"
 | 
			
		||||
 | 
			
		||||
  @spec user_fixture() :: User.t()
 | 
			
		||||
  @spec user_fixture(attrs :: map()) :: User.t()
 | 
			
		||||
  def user_fixture(attrs \\ %{}) do
 | 
			
		||||
@@ -79,7 +78,7 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
    |> Enum.into(%{
 | 
			
		||||
      "count" => 20,
 | 
			
		||||
      "date" => ~N[2022-02-13 03:17:00],
 | 
			
		||||
      "notes" => "some notes"
 | 
			
		||||
      "notes" => random_string()
 | 
			
		||||
    })
 | 
			
		||||
    |> Cannery.ActivityLog.create_shot_group(user, ammo_group)
 | 
			
		||||
    |> unwrap_ok_tuple()
 | 
			
		||||
@@ -92,7 +91,7 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
  @spec container_fixture(attrs :: map(), User.t()) :: Container.t()
 | 
			
		||||
  def container_fixture(attrs \\ %{}, %User{} = user) do
 | 
			
		||||
    attrs
 | 
			
		||||
    |> Enum.into(%{"name" => "My container", "type" => "Ammo can"})
 | 
			
		||||
    |> Enum.into(%{"name" => random_string(), "type" => "Ammo can"})
 | 
			
		||||
    |> Containers.create_container(user)
 | 
			
		||||
    |> unwrap_ok_tuple()
 | 
			
		||||
  end
 | 
			
		||||
@@ -104,7 +103,7 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
  @spec ammo_type_fixture(attrs :: map(), User.t()) :: AmmoType.t()
 | 
			
		||||
  def ammo_type_fixture(attrs \\ %{}, %User{} = user) do
 | 
			
		||||
    attrs
 | 
			
		||||
    |> Enum.into(%{"name" => "ammo_type"})
 | 
			
		||||
    |> Enum.into(%{"name" => random_string(), "type" => "rifle"})
 | 
			
		||||
    |> Ammo.create_ammo_type(user)
 | 
			
		||||
    |> unwrap_ok_tuple()
 | 
			
		||||
  end
 | 
			
		||||
@@ -150,7 +149,7 @@ defmodule Cannery.Fixtures do
 | 
			
		||||
    attrs
 | 
			
		||||
    |> Enum.into(%{
 | 
			
		||||
      "bg_color" => "#100000",
 | 
			
		||||
      "name" => "some name",
 | 
			
		||||
      "name" => random_string(),
 | 
			
		||||
      "text_color" => "#000000"
 | 
			
		||||
    })
 | 
			
		||||
    |> Containers.create_tag(user)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user