|  |  |  | @@ -9,9 +9,8 @@ defmodule Cannery.ContainersTest do | 
		
	
		
			
				|  |  |  |  |   alias Cannery.{Accounts.User, Containers.Container} | 
		
	
		
			
				|  |  |  |  |   alias Ecto.Changeset | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |   @moduletag :containers | 
		
	
		
			
				|  |  |  |  |   @moduletag :containers_test | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |   describe "containers" do | 
		
	
		
			
				|  |  |  |  |   @valid_attrs %{ | 
		
	
		
			
				|  |  |  |  |     "desc" => "some desc", | 
		
	
		
			
				|  |  |  |  |     "location" => "some location", | 
		
	
	
		
			
				
					
					|  |  |  | @@ -26,45 +25,44 @@ defmodule Cannery.ContainersTest do | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   @invalid_attrs %{"desc" => nil, "location" => nil, "name" => nil, "type" => nil} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     @spec container_fixture(User.t(), map()) :: Container.t() | 
		
	
		
			
				|  |  |  |  |     def container_fixture(user, attrs \\ %{}) do | 
		
	
		
			
				|  |  |  |  |       {:ok, container} = @valid_attrs |> Map.merge(attrs) |> Containers.create_container(user) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |       container | 
		
	
		
			
				|  |  |  |  |   describe "containers" do | 
		
	
		
			
				|  |  |  |  |     setup do | 
		
	
		
			
				|  |  |  |  |       current_user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       container = container_fixture(current_user) | 
		
	
		
			
				|  |  |  |  |       [current_user: current_user, container: container] | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "list_containers/1 returns all containers" do | 
		
	
		
			
				|  |  |  |  |       user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       container = user |> container_fixture() | 
		
	
		
			
				|  |  |  |  |       assert Containers.list_containers(user) == [container] | 
		
	
		
			
				|  |  |  |  |     test "list_containers/1 returns all containers", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert Containers.list_containers(current_user) == [container] | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "get_container!/1 returns the container with given id" do | 
		
	
		
			
				|  |  |  |  |       container = user_fixture() |> container_fixture() | 
		
	
		
			
				|  |  |  |  |       assert Containers.get_container!(container.id) == container | 
		
	
		
			
				|  |  |  |  |     test "get_container!/1 returns the container with given id", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert Containers.get_container!(container.id, current_user) == container | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "create_container/1 with valid data creates a container" do | 
		
	
		
			
				|  |  |  |  |       user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       assert {:ok, %Container{} = container} = @valid_attrs |> Containers.create_container(user) | 
		
	
		
			
				|  |  |  |  |     test "create_container/1 with valid data creates a container", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert {:ok, %Container{} = container} = | 
		
	
		
			
				|  |  |  |  |                @valid_attrs |> Containers.create_container(current_user) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |       assert container.desc == "some desc" | 
		
	
		
			
				|  |  |  |  |       assert container.location == "some location" | 
		
	
		
			
				|  |  |  |  |       assert container.name == "some name" | 
		
	
		
			
				|  |  |  |  |       assert container.type == "some type" | 
		
	
		
			
				|  |  |  |  |       assert container.user_id == user.id | 
		
	
		
			
				|  |  |  |  |       assert container.user_id == current_user.id | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "create_container/1 with invalid data returns error changeset" do | 
		
	
		
			
				|  |  |  |  |       assert {:error, %Changeset{}} = | 
		
	
		
			
				|  |  |  |  |                @invalid_attrs |> Containers.create_container(user_fixture()) | 
		
	
		
			
				|  |  |  |  |     test "create_container/1 with invalid data returns error changeset", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user} do | 
		
	
		
			
				|  |  |  |  |       assert {:error, %Changeset{}} = @invalid_attrs |> Containers.create_container(current_user) | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "update_container/2 with valid data updates the container" do | 
		
	
		
			
				|  |  |  |  |       user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       container = user |> container_fixture() | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "update_container/2 with valid data updates the container", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert {:ok, %Container{} = container} = | 
		
	
		
			
				|  |  |  |  |                Containers.update_container(container, user, @update_attrs) | 
		
	
		
			
				|  |  |  |  |                Containers.update_container(container, current_user, @update_attrs) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |       assert container.desc == "some updated desc" | 
		
	
		
			
				|  |  |  |  |       assert container.location == "some updated location" | 
		
	
	
		
			
				
					
					|  |  |  | @@ -72,22 +70,24 @@ defmodule Cannery.ContainersTest do | 
		
	
		
			
				|  |  |  |  |       assert container.type == "some updated type" | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "update_container/2 with invalid data returns error changeset" do | 
		
	
		
			
				|  |  |  |  |       user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       container = user |> container_fixture() | 
		
	
		
			
				|  |  |  |  |       assert {:error, %Changeset{}} = Containers.update_container(container, user, @invalid_attrs) | 
		
	
		
			
				|  |  |  |  |       assert container == Containers.get_container!(container.id) | 
		
	
		
			
				|  |  |  |  |     test "update_container/2 with invalid data returns error changeset", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert {:error, %Changeset{}} = | 
		
	
		
			
				|  |  |  |  |                Containers.update_container(container, current_user, @invalid_attrs) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |       assert container == Containers.get_container!(container.id, current_user) | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "delete_container/1 deletes the container" do | 
		
	
		
			
				|  |  |  |  |       user = user_fixture() | 
		
	
		
			
				|  |  |  |  |       container = user |> container_fixture() | 
		
	
		
			
				|  |  |  |  |       assert {:ok, %Container{}} = Containers.delete_container(container, user) | 
		
	
		
			
				|  |  |  |  |       assert_raise Ecto.NoResultsError, fn -> Containers.get_container!(container.id) end | 
		
	
		
			
				|  |  |  |  |     test "delete_container/1 deletes the container", | 
		
	
		
			
				|  |  |  |  |          %{current_user: current_user, container: container} do | 
		
	
		
			
				|  |  |  |  |       assert {:ok, %Container{}} = Containers.delete_container(container, current_user) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |       assert_raise Ecto.NoResultsError, fn -> | 
		
	
		
			
				|  |  |  |  |         Containers.get_container!(container.id, current_user) | 
		
	
		
			
				|  |  |  |  |       end | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     test "change_container/1 returns a container changeset" do | 
		
	
		
			
				|  |  |  |  |       container = user_fixture() |> container_fixture() | 
		
	
		
			
				|  |  |  |  |     test "change_container/1 returns a container changeset", %{container: container} do | 
		
	
		
			
				|  |  |  |  |       assert %Changeset{} = Containers.change_container(container) | 
		
	
		
			
				|  |  |  |  |     end | 
		
	
		
			
				|  |  |  |  |   end | 
		
	
	
		
			
				
					
					|  |  |  |   |