zf

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

domain.test.exs (2487B)


      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.Agent.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Zenflows.VF.Agent.Domain
     22 
     23 setup do
     24 		%{
     25 			per: Factory.insert!(:person),
     26 			org: Factory.insert!(:organization),
     27 		}
     28 end
     29 
     30 describe "one/1" do
     31 	test "with per's id: finds the Person", %{per: per} do
     32 		assert {:ok, agent} = Domain.one(per.id)
     33 
     34 		# common
     35 		assert agent.id == per.id
     36 		assert agent.type == per.type and agent.type == :per
     37 		assert agent.name == per.name
     38 		assert agent.note == per.note
     39 		assert agent.primary_location_id == per.primary_location_id
     40 
     41 		# person
     42 		assert agent.user == per.user
     43 		assert agent.email == per.email
     44 
     45 		# organization
     46 		assert agent.classified_as == nil
     47 	end
     48 
     49 	test "with org's id: finds the Organization", %{org: org} do
     50 		assert {:ok, agent} = Domain.one(org.id)
     51 
     52 		# common
     53 		assert agent.id == org.id
     54 		assert agent.type == org.type and agent.type == :org
     55 		assert agent.name == org.name
     56 		assert agent.note == org.note
     57 		assert agent.primary_location_id == org.primary_location_id
     58 
     59 		# person
     60 		assert agent.user == nil
     61 		assert agent.email == nil
     62 
     63 		# organization
     64 		assert agent.classified_as == org.classified_as
     65 	end
     66 end
     67 
     68 describe "preload/2" do
     69 	test "preloads :primary_location for a Person", %{per: per} do
     70 		{:ok, agent} = Domain.one(per.id)
     71 		agent = Domain.preload(agent, :primary_location)
     72 		assert agent.primary_location.id == agent.primary_location_id
     73 	end
     74 
     75 	test "preloads :primary_location for an Organization", %{org: org} do
     76 		{:ok, agent} = Domain.one(org.id)
     77 		agent = Domain.preload(agent, :primary_location)
     78 		assert agent.primary_location.id == agent.primary_location_id
     79 	end
     80 end
     81 end