zf

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

domain.test.exs (4280B)


      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.RecipeResource.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{
     23 	RecipeResource,
     24 	RecipeResource.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 			unit_of_effort_id: Factory.insert!(:unit).id,
     34 			unit_of_resource_id: Factory.insert!(:unit).id,
     35 			resource_conforms_to_id: Factory.insert!(:resource_specification).id,
     36 			substitutable: Factory.bool(),
     37 			note: Factory.str("note"),
     38 		},
     39 		inserted: Factory.insert!(:recipe_resource),
     40 	}
     41 end
     42 
     43 describe "one/1" do
     44 	test "with good id: finds the RecipeResource", %{inserted: %{id: id}} do
     45 		assert {:ok, %RecipeResource{}} = Domain.one(id)
     46 	end
     47 
     48 	test "with bad id: doesn't find the RecipeResource" do
     49 		assert {:error, "not found"} = Domain.one(Factory.id())
     50 	end
     51 end
     52 
     53 describe "create/1" do
     54 	test "with good params: creates a RecipeResource", %{params: params} do
     55 		assert {:ok, %RecipeResource{} = new} = Domain.create(params)
     56 		assert new.name == params.name
     57 		assert new.resource_classified_as == params.resource_classified_as
     58 		assert new.unit_of_resource_id == params.unit_of_resource_id
     59 		assert new.unit_of_effort_id == params.unit_of_effort_id
     60 		assert new.resource_conforms_to_id == params.resource_conforms_to_id
     61 		assert new.substitutable == params.substitutable
     62 		assert new.note == params.note
     63 	end
     64 
     65 	test "with bad params: doesn't create a Process" do
     66 		assert {:error, %Changeset{}} = Domain.create(%{})
     67 	end
     68 end
     69 
     70 describe "update/2" do
     71 	test "with good params: updates the RecipeResource", %{params: params, inserted: old} do
     72 		assert {:ok, %RecipeResource{} = new} = Domain.update(old.id, params)
     73 		assert new.name == params.name
     74 		assert new.resource_classified_as == params.resource_classified_as
     75 		assert new.unit_of_resource_id == params.unit_of_resource_id
     76 		assert new.unit_of_effort_id == params.unit_of_effort_id
     77 		assert new.resource_conforms_to_id == params.resource_conforms_to_id
     78 		assert new.substitutable == params.substitutable
     79 		assert new.note == params.note
     80 	end
     81 
     82 	test "with bad params: doesn't update the RecipeResource", %{inserted: old} do
     83 		assert {:ok, %RecipeResource{} = new} = Domain.update(old.id, %{})
     84 		assert new.name == old.name
     85 		assert new.resource_classified_as == old.resource_classified_as
     86 		assert new.unit_of_resource_id == old.unit_of_resource_id
     87 		assert new.unit_of_effort_id == old.unit_of_effort_id
     88 		assert new.resource_conforms_to_id == old.resource_conforms_to_id
     89 		assert new.substitutable == old.substitutable
     90 		assert new.note == old.note
     91 	end
     92 end
     93 
     94 describe "delete/1" do
     95 	test "with good id: deletes the RecipeResource", %{inserted: %{id: id}} do
     96 		assert {:ok, %RecipeResource{id: ^id}} = Domain.delete(id)
     97 		assert {:error, "not found"} = Domain.one(id)
     98 	end
     99 
    100 	test "with bad id: doesn't delete the RecipeResource" do
    101 		assert {:error, "not found"} = Domain.delete(Factory.id())
    102 	end
    103 end
    104 
    105 describe "preload/2" do
    106 	test "preloads :unit_of_resource", %{inserted: rec_res} do
    107 		rec_res = Domain.preload(rec_res, :unit_of_resource)
    108 		assert unit_res = %Unit{} = rec_res.unit_of_resource
    109 		assert unit_res.id == rec_res.unit_of_resource_id
    110 	end
    111 
    112 	test "preloads :unit_of_effort", %{inserted: rec_res} do
    113 		rec_res = Domain.preload(rec_res, :unit_of_effort)
    114 		assert unit_eff = %Unit{} = rec_res.unit_of_effort
    115 		assert unit_eff.id == rec_res.unit_of_effort_id
    116 	end
    117 end
    118 end