82 lines
2.8 KiB
Elixir
82 lines
2.8 KiB
Elixir
defmodule RealEstate.PropertiesTest do
|
|
use RealEstate.DataCase
|
|
|
|
alias RealEstate.Properties
|
|
import RealEstate.AccountsFixtures
|
|
|
|
describe "properties" do
|
|
alias RealEstate.Properties.Property
|
|
|
|
@valid_attrs %{description: "some description", name: "some name", price: "120.5"}
|
|
@update_attrs %{
|
|
description: "some updated description",
|
|
name: "some updated name",
|
|
price: "456.7"
|
|
}
|
|
@invalid_attrs %{description: nil, name: nil, price: nil}
|
|
|
|
def property_fixture(attrs \\ %{}) do
|
|
user = user_fixture()
|
|
|
|
{:ok, property} =
|
|
attrs
|
|
|> Enum.into(@valid_attrs)
|
|
|> Enum.into(%{user_id: user.id})
|
|
|> Properties.create_property()
|
|
|
|
property
|
|
end
|
|
|
|
test "list_properties/0 returns all properties" do
|
|
property = property_fixture()
|
|
assert Properties.list_properties() == [property]
|
|
end
|
|
|
|
test "get_property!/1 returns the property with given id" do
|
|
property = property_fixture()
|
|
assert Properties.get_property!(property.id) == property
|
|
end
|
|
|
|
test "create_property/1 with valid data creates a property" do
|
|
user = user_fixture()
|
|
create_attributes = Enum.into(%{user_id: user.id}, @valid_attrs)
|
|
|
|
assert {:ok, %Property{} = property} = Properties.create_property(create_attributes)
|
|
assert property.description == "some description"
|
|
assert property.name == "some name"
|
|
assert property.price == Decimal.new("120.5")
|
|
assert property.user_id == user.id
|
|
end
|
|
|
|
test "create_property/1 with invalid data returns error changeset" do
|
|
user = user_fixture()
|
|
create_attributes = Enum.into(%{user_id: user.id}, @invalid_attrs)
|
|
assert {:error, %Ecto.Changeset{}} = Properties.create_property(create_attributes)
|
|
end
|
|
|
|
test "update_property/2 with valid data updates the property" do
|
|
property = property_fixture()
|
|
assert {:ok, %Property{} = property} = Properties.update_property(property, @update_attrs)
|
|
assert property.description == "some updated description"
|
|
assert property.name == "some updated name"
|
|
assert property.price == Decimal.new("456.7")
|
|
end
|
|
|
|
test "update_property/2 with invalid data returns error changeset" do
|
|
property = property_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = Properties.update_property(property, @invalid_attrs)
|
|
assert property == Properties.get_property!(property.id)
|
|
end
|
|
|
|
test "delete_property/1 deletes the property" do
|
|
property = property_fixture()
|
|
assert {:ok, %Property{}} = Properties.delete_property(property)
|
|
assert_raise Ecto.NoResultsError, fn -> Properties.get_property!(property.id) end
|
|
end
|
|
|
|
test "change_property/1 returns a property changeset" do
|
|
property = property_fixture()
|
|
assert %Ecto.Changeset{} = Properties.change_property(property)
|
|
end
|
|
end
|
|
end
|