domain.test.exs (3021B)
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.Plan.Domain do 19 use ZenflowsTest.Help.EctoCase, async: true 20 21 alias Ecto.Changeset 22 alias Zenflows.VF.{Plan, Plan.Domain, Scenario} 23 24 setup do 25 %{ 26 params: %{ 27 name: Factory.str("name"), 28 note: Factory.str("note"), 29 due: Factory.now(), 30 refinement_of_id: Factory.insert!(:scenario).id, 31 }, 32 inserted: Factory.insert!(:plan), 33 } 34 end 35 36 describe "one/1" do 37 test "with good id: finds the Plan", %{inserted: %{id: id}} do 38 assert {:ok, %Plan{}} = Domain.one(id) 39 end 40 41 test "with bad id: doesn't find the Plan" 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 a Plan", %{params: params} do 48 assert {:ok, %Plan{} = new} = Domain.create(params) 49 assert new.name == params.name 50 assert new.note == params.note 51 assert new.due == params.due 52 assert new.refinement_of_id == params.refinement_of_id 53 end 54 55 test "with bad params: doesn't create an" do 56 assert {:error, %Changeset{}} = Domain.create(%{}) 57 end 58 end 59 60 describe "update/2" do 61 test "with good params: updates the Plan", %{params: params, inserted: old} do 62 assert {:ok, %Plan{} = new} = Domain.update(old.id, params) 63 assert new.name == params.name 64 assert new.note == params.note 65 assert new.due == params.due 66 assert new.refinement_of_id == params.refinement_of_id 67 end 68 69 test "with bad params: doesn't update the Plan", %{inserted: old} do 70 assert {:ok, %Plan{} = new} = Domain.update(old.id, %{}) 71 assert new.name == old.name 72 assert new.note == old.note 73 assert new.due == old.due 74 assert new.refinement_of_id == old.refinement_of_id 75 end 76 end 77 78 describe "delete/1" do 79 test "with good id: deletes the Plan", %{inserted: %{id: id}} do 80 assert {:ok, %Plan{id: ^id}} = Domain.delete(id) 81 assert {:error, "not found"} = Domain.one(id) 82 end 83 84 test "with bad id: doesn't delete the Plan" do 85 assert {:error, "not found"} = Domain.delete(Factory.id()) 86 end 87 end 88 89 describe "preload/2" do 90 test "preloads `:refinement_of`", %{inserted: plan} do 91 plan = Domain.preload(plan, :refinement_of) 92 assert refin_of = %Scenario{} = plan.refinement_of 93 assert refin_of.id == plan.refinement_of_id 94 end 95 end 96 end