zf

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

domain.test.exs (4465B)


      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.Process.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{
     23 	Plan,
     24 	Process,
     25 	Process.Domain,
     26 	ProcessSpecification,
     27 	Scenario,
     28 }
     29 
     30 setup do
     31 	%{
     32 		params: %{
     33 			name: Factory.str("name"),
     34 			note: Factory.str("note"),
     35 			has_beginning: DateTime.utc_now(),
     36 			has_end: DateTime.utc_now(),
     37 			finished: Factory.bool(),
     38 			classified_as: Factory.str_list("class"),
     39 			based_on_id: Factory.insert!(:process_specification).id,
     40 			planned_within_id: Factory.insert!(:plan).id,
     41 			nested_in_id: Factory.insert!(:scenario).id,
     42 	 	},
     43 		inserted: Factory.insert!(:process),
     44 	}
     45 end
     46 
     47 describe "one/1" do
     48 	test "with good id: finds the Process", %{inserted: %{id: id}} do
     49 		assert {:ok, %Process{}} = Domain.one(id)
     50 	end
     51 
     52 	test "with bad id: doesn't find the Process" do
     53 		assert {:error, "not found"} = Domain.one(Factory.id())
     54 	end
     55 end
     56 
     57 describe "create/1" do
     58 	test "with good params: creates a Process", %{params: params} do
     59 		assert {:ok, %Process{} = new} = Domain.create(params)
     60 		assert new.name == params.name
     61 		assert new.note == params.note
     62 		assert new.has_beginning == params.has_beginning
     63 		assert new.has_end == params.has_end
     64 		assert new.finished == params.finished
     65 		assert new.classified_as == params.classified_as
     66 		assert new.based_on_id == params.based_on_id
     67 		assert new.planned_within_id == params.planned_within_id
     68 		assert new.nested_in_id == params.nested_in_id
     69 	end
     70 
     71 	test "with bad params: doesn't create a Process" do
     72 		assert {:error, %Changeset{}} = Domain.create(%{})
     73 	end
     74 end
     75 
     76 describe "update/2" do
     77 	test "with good params: updates the Process", %{params: params, inserted: old} do
     78 		assert {:ok, %Process{} = new} = Domain.update(old.id, params)
     79 		assert new.name == params.name
     80 		assert new.note == params.note
     81 		assert new.has_beginning == params.has_beginning
     82 		assert new.has_end == params.has_end
     83 		assert new.finished == params.finished
     84 		assert new.classified_as == params.classified_as
     85 		assert new.based_on_id == params.based_on_id
     86 		assert new.planned_within_id == params.planned_within_id
     87 		assert new.nested_in_id == params.nested_in_id
     88 	end
     89 
     90 	test "with bad params: doesn't update the Process", %{inserted: old} do
     91 		assert {:ok, %Process{} = new} = Domain.update(old.id, %{})
     92 		assert new.name == old.name
     93 		assert new.note == old.note
     94 		assert new.has_beginning == old.has_beginning
     95 		assert new.has_end == old.has_end
     96 		assert new.finished == old.finished
     97 		assert new.classified_as == old.classified_as
     98 		assert new.based_on_id == old.based_on_id
     99 		assert new.planned_within_id == old.planned_within_id
    100 		assert new.nested_in_id == old.nested_in_id
    101 	end
    102 end
    103 
    104 describe "delete/1" do
    105 	test "with good id: deletes the Process", %{inserted: %{id: id}} do
    106 		assert {:ok, %Process{id: ^id}} = Domain.delete(id)
    107 		assert {:error, "not found"} = Domain.one(id)
    108 	end
    109 
    110 	test "with bad id: doesn't delete the Process" do
    111 		assert {:error, "not found"} = Domain.delete(Factory.id())
    112 	end
    113 end
    114 
    115 describe "preload/2" do
    116 	test "preloads :based_on", %{inserted: proc} do
    117 		proc = Domain.preload(proc, :based_on)
    118 		assert based_on = %ProcessSpecification{} = proc.based_on
    119 		assert based_on.id == proc.based_on_id
    120 	end
    121 
    122 	test "preloads :planned_within", %{inserted: proc} do
    123 		proc = Domain.preload(proc, :planned_within)
    124 		assert planed_within = %Plan{} = proc.planned_within
    125 		assert planed_within.id == proc.planned_within_id
    126 	end
    127 
    128 	test "preloads :nested_in", %{inserted: proc} do
    129 		proc = Domain.preload(proc, :nested_in)
    130 		assert nested_in = %Scenario{} = proc.nested_in
    131 		assert nested_in.id == proc.nested_in_id
    132 	end
    133 end
    134 end