2020-09-14 12:22:25 -04:00
|
|
|
defmodule RealEstate.PropertiesTest do
|
|
|
|
use RealEstate.DataCase
|
|
|
|
|
|
|
|
alias RealEstate.Properties
|
2020-09-14 19:45:56 -04:00
|
|
|
import RealEstate.AccountsFixtures
|
2020-09-14 12:22:25 -04:00
|
|
|
|
|
|
|
describe "properties" do
|
|
|
|
alias RealEstate.Properties.Property
|
|
|
|
|
|
|
|
@valid_attrs %{description: "some description", name: "some name", price: "120.5"}
|
2020-09-14 19:45:56 -04:00
|
|
|
@update_attrs %{
|
|
|
|
description: "some updated description",
|
|
|
|
name: "some updated name",
|
|
|
|
price: "456.7"
|
|
|
|
}
|
2020-09-14 12:22:25 -04:00
|
|
|
@invalid_attrs %{description: nil, name: nil, price: nil}
|
|
|
|
|
|
|
|
def property_fixture(attrs \\ %{}) do
|
2020-09-14 19:45:56 -04:00
|
|
|
user = user_fixture()
|
|
|
|
|
2020-09-14 12:22:25 -04:00
|
|
|
{:ok, property} =
|
|
|
|
attrs
|
|
|
|
|> Enum.into(@valid_attrs)
|
2020-09-14 19:45:56 -04:00
|
|
|
|> Enum.into(%{user_id: user.id})
|
2020-09-14 12:22:25 -04:00
|
|
|
|> 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
|
2020-09-14 19:45:56 -04:00
|
|
|
user = user_fixture()
|
|
|
|
create_attributes = Enum.into(%{user_id: user.id}, @valid_attrs)
|
|
|
|
|
|
|
|
assert {:ok, %Property{} = property} = Properties.create_property(create_attributes)
|
2020-09-14 12:22:25 -04:00
|
|
|
assert property.description == "some description"
|
|
|
|
assert property.name == "some name"
|
|
|
|
assert property.price == Decimal.new("120.5")
|
2020-09-14 19:45:56 -04:00
|
|
|
assert property.user_id == user.id
|
2020-09-14 12:22:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_property/1 with invalid data returns error changeset" do
|
2020-09-14 19:45:56 -04:00
|
|
|
user = user_fixture()
|
|
|
|
create_attributes = Enum.into(%{user_id: user.id}, @invalid_attrs)
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Properties.create_property(create_attributes)
|
2020-09-14 12:22:25 -04:00
|
|
|
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
|