zf

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

domain.test.exs (4077B)


      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.ResourceSpecification.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{
     23 	ResourceSpecification,
     24 	ResourceSpecification.Domain,
     25 	Unit,
     26 }
     27 
     28 setup do
     29 	%{
     30 		params: %{
     31 			name: Factory.str("name"),
     32 			resource_classified_as: Factory.str_list("uri"),
     33 			note: Factory.str("note"),
     34 			default_unit_of_effort_id: Factory.insert!(:unit).id,
     35 			default_unit_of_resource_id: Factory.insert!(:unit).id,
     36 		},
     37 		inserted: Factory.insert!(:resource_specification),
     38 	}
     39 end
     40 
     41 describe "one/1" do
     42 	test "with good id: finds the ResourceSpecification", %{inserted: %{id: id}} do
     43 		assert {:ok, %ResourceSpecification{}} = Domain.one(id)
     44 	end
     45 
     46 	test "with bad id: doesn't find the ResourceSpecification" 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 a ResourceSpecification", %{params: params} do
     53 		assert {:ok, %ResourceSpecification{} = new} = Domain.create(params)
     54 		assert new.name == params.name
     55 		assert new.resource_classified_as == params.resource_classified_as
     56 		assert new.note == params.note
     57 		assert new.default_unit_of_resource_id == params.default_unit_of_resource_id
     58 		assert new.default_unit_of_effort_id == params.default_unit_of_effort_id
     59 	end
     60 
     61 	test "with bad params: doesn't create a ResourceSpecification" do
     62 		assert {:error, %Changeset{}} = Domain.create(%{})
     63 	end
     64 end
     65 
     66 describe "update/2" do
     67 	test "with good params: updates the ResourceSpecification", %{params: params, inserted: old} do
     68 		assert {:ok, %ResourceSpecification{} = new} = Domain.update(old.id, params)
     69 		assert new.name == params.name
     70 		assert new.resource_classified_as == params.resource_classified_as
     71 		assert new.note == params.note
     72 		assert new.default_unit_of_resource_id == params.default_unit_of_resource_id
     73 		assert new.default_unit_of_effort_id == params.default_unit_of_effort_id
     74 	end
     75 
     76 	test "with bad params: doesn't update the ResourceSpecification", %{inserted: old} do
     77 		assert {:ok, %ResourceSpecification{} = new} = Domain.update(old.id, %{})
     78 		assert new.name == old.name
     79 		assert new.resource_classified_as == old.resource_classified_as
     80 		assert new.note == old.note
     81 		assert new.default_unit_of_resource_id == old.default_unit_of_resource_id
     82 		assert new.default_unit_of_effort_id == old.default_unit_of_effort_id
     83 	end
     84 end
     85 
     86 describe "delete/1" do
     87 	test "with good id: deletes the ResourceSpecification", %{inserted: %{id: id}} do
     88 		assert {:ok, %ResourceSpecification{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 ResourceSpecification" do
     93 		assert {:error, "not found"} = Domain.delete(Factory.id())
     94 	end
     95 end
     96 
     97 describe "preload/2" do
     98 	test "preloads `:default_unit_of_resource`", %{inserted: %{id: id}} do
     99 		assert {:ok, res_spec} =  Domain.one(id)
    100 		res_spec = Domain.preload(res_spec, :default_unit_of_resource)
    101 		assert %Unit{} = res_spec.default_unit_of_resource
    102  	end
    103 
    104 	test "preloads `:default_unit_of_effort`", %{inserted: %{id: id}} do
    105 		assert {:ok, res_spec} =  Domain.one(id)
    106 		res_spec = Domain.preload(res_spec, :default_unit_of_effort)
    107 		assert %Unit{} = res_spec.default_unit_of_effort
    108  	end
    109 end
    110 end