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