zf

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

domain.test.exs (3532B)


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