zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

domain.test.exs (3252B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule ZenflowsTest.VF.SpatialThing.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{SpatialThing, SpatialThing.Domain}
     23 
     24 setup do
     25 	%{
     26 		params: %{
     27 			name: Factory.str("name"),
     28 			mappable_address: Factory.str("address"),
     29 			lat: Factory.decimal(),
     30 			long: Factory.decimal(),
     31 			alt: Factory.decimal(),
     32 			note: Factory.str("note"),
     33 		},
     34 		inserted: Factory.insert!(:spatial_thing),
     35 	}
     36 end
     37 
     38 describe "one/1" do
     39 	test "with good id: finds the SpatialThing", %{inserted: %{id: id}} do
     40 		assert {:ok, %SpatialThing{}} = Domain.one(id)
     41 	end
     42 
     43 	test "with bad id: doesn't find the SpatialThing" do
     44 		assert {:error, "not found"} = Domain.one(Factory.id())
     45 	end
     46 end
     47 
     48 describe "create/1" do
     49 	test "with good params: creates a SpatialThing", %{params: params} do
     50 		assert {:ok, %SpatialThing{} = new} = Domain.create(params)
     51 		assert new.name == params.name
     52 		assert new.mappable_address == params.mappable_address
     53 		assert Decimal.eq?(new.lat, params.lat)
     54 		assert Decimal.eq?(new.long, params.long)
     55 		assert Decimal.eq?(new.alt, params.alt)
     56 		assert new.note == params.note
     57 	end
     58 
     59 	test "with bad params: doesn't create a SpatialThing" do
     60 		assert {:error, %Changeset{}} = Domain.create(%{})
     61 	end
     62 end
     63 
     64 describe "update/2" do
     65 	test "with good params: updates the SpatialThing", %{params: params, inserted: old} do
     66 		assert {:ok, %SpatialThing{} = new} = Domain.update(old.id, params)
     67 		assert new.name == params.name
     68 		assert new.mappable_address == params.mappable_address
     69 		assert Decimal.eq?(new.lat, params.lat)
     70 		assert Decimal.eq?(new.long, params.long)
     71 		assert Decimal.eq?(new.alt, params.alt)
     72 		assert new.note == params.note
     73 	end
     74 
     75 	test "with bad params: doesn't update the SpatialThing", %{inserted: old} do
     76 		assert {:ok, %SpatialThing{} = new} = Domain.update(old.id, %{})
     77 		assert new.name == old.name
     78 		assert new.mappable_address == old.mappable_address
     79 		assert Decimal.eq?(new.lat, old.lat)
     80 		assert Decimal.eq?(new.long, old.long)
     81 		assert Decimal.eq?(new.alt, old.alt)
     82 		assert new.note == old.note
     83 	end
     84 end
     85 
     86 describe "delete/1" do
     87 	test "with good id: deletes the SpatialThing", %{inserted: %{id: id}} do
     88 		assert {:ok, %SpatialThing{id: ^id}} = Domain.delete(id)
     89 		assert {:error, "not found"} = Domain.one(id)
     90 	end
     91 
     92 	test "with bad id: doesn't delete the SpatialThing" do
     93 		assert {:error, "not found"} = Domain.delete(Factory.id())
     94 	end
     95 end
     96 end