settlement.test.exs (2741B)
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.Settlement do 19 use ZenflowsTest.Help.EctoCase, async: true 20 21 alias Zenflows.VF.Settlement 22 23 setup do 24 %{params: %{ 25 note: Factory.str("note"), 26 settled_by_id: Factory.insert!(:economic_event).id, 27 settles_id: Factory.insert!(:claim).id, 28 resource_quantity: %{ 29 has_unit_id: Factory.insert!(:unit).id, 30 has_numerical_value: Factory.decimal(), 31 }, 32 effort_quantity: %{ 33 has_unit_id: Factory.insert!(:unit).id, 34 has_numerical_value: Factory.decimal(), 35 }, 36 }} 37 end 38 39 @tag skip: "TODO: fix events in factory" 40 test "create Settlement", %{params: params} do 41 assert {:ok, %Settlement{} = settl} = 42 params 43 |> Settlement.changeset() 44 |> Repo.insert() 45 46 assert settl.note == params.note 47 assert settl.settled_by_id == params.settled_by_id 48 assert settl.settles_id == params.settles_id 49 assert settl.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id 50 assert settl.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value 51 assert settl.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id 52 assert settl.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value 53 end 54 55 @tag skip: "TODO: fix events in factory" 56 test "update Settlement", %{params: params} do 57 assert {:ok, %Settlement{} = settl} = 58 :settlement 59 |> Factory.insert!() 60 |> Settlement.changeset(params) 61 |> Repo.update() 62 63 assert settl.note == params.note 64 assert settl.settled_by_id == params.settled_by_id 65 assert settl.settles_id == params.settles_id 66 assert settl.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id 67 assert settl.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value 68 assert settl.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id 69 assert settl.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value 70 end 71 end