domain.test.exs (3249B)
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.AgentRelationshipRole.Domain do 19 use ZenflowsTest.Help.EctoCase, async: true 20 21 alias Ecto.Changeset 22 alias Zenflows.VF.{AgentRelationshipRole, AgentRelationshipRole.Domain} 23 24 setup do 25 %{ 26 params: %{ 27 role_behavior_id: Factory.insert!(:role_behavior).id, 28 role_label: Factory.str("role label"), 29 inverse_role_label: Factory.str("inverse role label"), 30 note: Factory.str("note"), 31 }, 32 inserted: Factory.insert!(:agent_relationship_role), 33 } 34 end 35 36 describe "one/1" do 37 test "with good id: finds the AgentRelationshipRole", %{inserted: %{id: id}} do 38 assert {:ok, %AgentRelationshipRole{}} = Domain.one(id) 39 end 40 41 test "with bad id: doesn't find the AgentRelationshiprole"do 42 assert {:error, "not found"} = Domain.one(Factory.id()) 43 end 44 end 45 46 describe "create/1" do 47 test "with good params: creates an AgentRelationshipRole", %{params: params} do 48 assert {:ok, %AgentRelationshipRole{} = new} = Domain.create(params) 49 50 assert new.role_behavior_id == params.role_behavior_id 51 assert new.role_label == params.role_label 52 assert new.inverse_role_label == params.inverse_role_label 53 assert new.note == params.note 54 end 55 56 test "with bad params: doesn't create an AgentRelationshipRole" do 57 assert {:error, %Changeset{}} = Domain.create(%{}) 58 end 59 end 60 61 describe "update/2" do 62 test "with good params: updates the AgentRelationshipRole", %{params: params, inserted: old} do 63 assert {:ok, %AgentRelationshipRole{} = new} = Domain.update(old.id, params) 64 assert new.role_behavior_id == params.role_behavior_id 65 assert new.role_label == params.role_label 66 assert new.inverse_role_label == params.inverse_role_label 67 assert new.note == params.note 68 end 69 70 test "with bad params: doesn't update the AgentRelationshipRole", %{inserted: old} do 71 assert {:ok, %AgentRelationshipRole{} = new} = Domain.update(old.id, %{}) 72 assert new.role_behavior_id == old.role_behavior_id 73 assert new.role_label == old.role_label 74 assert new.inverse_role_label == old.inverse_role_label 75 assert new.note == old.note 76 end 77 end 78 79 describe "delete/1" do 80 test "with good id: deletes the AgentRelationshipRole", %{inserted: %{id: id}} do 81 assert {:ok, %AgentRelationshipRole{id: ^id}} = Domain.delete(id) 82 assert {:error, "not found"} = Domain.one(id) 83 end 84 85 test "with bad id: doesn't delete the AgentRelationshipRole" do 86 assert {:error, "not found"} = Domain.delete(Factory.id()) 87 end 88 end 89 end