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