2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.AddressesTest do
|
|
|
|
use Mobilizon.DataCase
|
2018-01-17 11:39:01 +01:00
|
|
|
|
2019-07-30 10:35:29 +02:00
|
|
|
import Mobilizon.Factory
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Addresses
|
2018-01-17 11:39:01 +01:00
|
|
|
|
|
|
|
describe "addresses" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Addresses.Address
|
2018-01-17 11:39:01 +01:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
@valid_attrs %{
|
2019-03-22 15:51:23 +01:00
|
|
|
country: "some addressCountry",
|
|
|
|
locality: "some addressLocality",
|
|
|
|
region: "some addressRegion",
|
2018-07-27 10:45:35 +02:00
|
|
|
description: "some description",
|
2019-03-22 15:51:23 +01:00
|
|
|
postal_code: "some postalCode",
|
|
|
|
street: "some streetAddress",
|
2018-07-27 10:45:35 +02:00
|
|
|
geom: %Geo.Point{coordinates: {10, -10}, srid: 4326}
|
|
|
|
}
|
|
|
|
@update_attrs %{
|
2019-03-22 15:51:23 +01:00
|
|
|
country: "some updated addressCountry",
|
|
|
|
locality: "some updated addressLocality",
|
|
|
|
region: "some updated addressRegion",
|
2018-07-27 10:45:35 +02:00
|
|
|
description: "some updated description",
|
2019-03-22 15:51:23 +01:00
|
|
|
postal_code: "some updated postalCode",
|
|
|
|
street: "some updated streetAddress",
|
2018-07-27 10:45:35 +02:00
|
|
|
geom: %Geo.Point{coordinates: {20, -20}, srid: 4326}
|
|
|
|
}
|
2019-12-20 13:04:34 +01:00
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
# @invalid_attrs %{
|
|
|
|
# addressCountry: nil,
|
|
|
|
# addressLocality: nil,
|
|
|
|
# addressRegion: nil,
|
|
|
|
# description: nil,
|
|
|
|
# postalCode: nil,
|
|
|
|
# streetAddress: nil,
|
|
|
|
# geom: nil
|
|
|
|
# }
|
2018-01-17 11:39:01 +01:00
|
|
|
|
|
|
|
test "list_addresses/0 returns all addresses" do
|
2019-07-30 10:35:29 +02:00
|
|
|
address = insert(:address)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert [address.id] == Addresses.list_addresses() |> Enum.map(& &1.id)
|
2018-01-17 11:39:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "get_address!/1 returns the address with given id" do
|
2019-07-30 10:35:29 +02:00
|
|
|
address = insert(:address)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert Addresses.get_address!(address.id).id == address.id
|
2018-01-17 11:39:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_address/1 with valid data creates a address" do
|
|
|
|
assert {:ok, %Address{} = address} = Addresses.create_address(@valid_attrs)
|
2019-03-22 15:51:23 +01:00
|
|
|
assert address.country == "some addressCountry"
|
|
|
|
assert address.locality == "some addressLocality"
|
|
|
|
assert address.region == "some addressRegion"
|
2018-01-17 11:39:01 +01:00
|
|
|
assert address.description == "some description"
|
2019-03-22 15:51:23 +01:00
|
|
|
assert address.postal_code == "some postalCode"
|
|
|
|
assert address.street == "some streetAddress"
|
2018-01-17 11:39:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "update_address/2 with valid data updates the address" do
|
2019-07-30 10:35:29 +02:00
|
|
|
address = insert(:address)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert {:ok, %Address{} = address} = Addresses.update_address(address, @update_attrs)
|
2019-03-22 15:51:23 +01:00
|
|
|
assert address.country == "some updated addressCountry"
|
|
|
|
assert address.locality == "some updated addressLocality"
|
|
|
|
assert address.region == "some updated addressRegion"
|
2018-01-17 11:39:01 +01:00
|
|
|
assert address.description == "some updated description"
|
2019-03-22 15:51:23 +01:00
|
|
|
assert address.postal_code == "some updated postalCode"
|
|
|
|
assert address.street == "some updated streetAddress"
|
2018-01-17 11:39:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_address/1 deletes the address" do
|
2019-07-30 10:35:29 +02:00
|
|
|
address = insert(:address)
|
2018-01-17 11:39:01 +01:00
|
|
|
assert {:ok, %Address{}} = Addresses.delete_address(address)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Addresses.get_address!(address.id) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|