zf

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

domain.test.exs (3188B)


      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.Organization.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{Organization, Organization.Domain}
     23 
     24 setup do
     25 	%{
     26 		params: %{
     27 			name: Factory.str("name"),
     28 			classified_as: Factory.str_list("uri"),
     29 			note: Factory.str("note"),
     30 			primary_location_id: Factory.insert!(:spatial_thing).id,
     31 		},
     32 		inserted: Factory.insert!(:organization),
     33 	}
     34 end
     35 
     36 describe "one/1" do
     37 	test "with good id: finds the Organization", %{inserted: %{id: id}} do
     38 		assert {:ok, %Organization{}} = Domain.one(id)
     39 	end
     40 
     41 	test "with per's id: doesn't return a Person" do
     42 		per = Factory.insert!(:person)
     43 		assert {:error, "not found"} = Domain.one(per.id)
     44 	end
     45 
     46 	test "with bad id: doesn't find the Organization" do
     47 		assert {:error, "not found"} = Domain.one(Factory.id())
     48 	end
     49 end
     50 
     51 describe "create/1" do
     52 	test "with good params: creates an Organization", %{params: params} do
     53 		assert {:ok, %Organization{} = new} = Domain.create(params)
     54 		assert new.type == :org
     55 		assert new.name == params.name
     56 		assert new.classified_as == params.classified_as
     57 		assert new.note == params.note
     58 		assert new.primary_location_id == params.primary_location_id	end
     59 
     60 	test "with bad params: doesn't create an Organization" do
     61 		assert {:error, %Changeset{}} = Domain.create(%{})
     62 	end
     63 end
     64 
     65 describe "update/2" do
     66 	test "with good params: updates the Organization", %{params: params, inserted: old} do
     67 		assert {:ok, %Organization{} = new} = Domain.update(old.id, params)
     68 		assert new.name == params.name
     69 		assert new.classified_as == params.classified_as
     70 		assert new.note == params.note
     71 		assert new.primary_location_id == params.primary_location_id
     72 	end
     73 
     74 	test "with bad params: doesn't update the Organization", %{inserted: old} do
     75 		assert {:ok, %Organization{} = new} = Domain.update(old.id, %{})
     76 		assert new.name == old.name
     77 		assert new.classified_as == old.classified_as
     78 		assert new.note == old.note
     79 		assert new.primary_location_id == old.primary_location_id
     80 	end
     81 end
     82 
     83 describe "delete/1" do
     84 	test "with good id: deletes the Organization", %{inserted: %{id: id}} do
     85 		assert {:ok, %Organization{id: ^id}} = Domain.delete(id)
     86 		assert {:error, "not found"} = Domain.one(id)
     87 	end
     88 
     89 	test "with bad id: doesn't delete the Organization" do
     90 		assert {:error, "not found"} = Domain.delete(Factory.id())
     91 	end
     92 end
     93 end