event_or_commitment.test.exs (3702B)
1 # Zenflows is designed to implement the Valueflows vocabulary, 2 # written and maintained by srfsh <info@dyne.org>. 3 # Copyright (C) 2021-2022 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.EventOrCommitment do 19 use ZenflowsTest.Help.EctoCase, async: true 20 21 alias Ecto.Changeset 22 alias Zenflows.VF.EventOrCommitment 23 24 setup do 25 %{params: %{ 26 event_id: Factory.insert!(:economic_event).id, 27 commitment_id: Factory.insert!(:commitment).id, 28 }} 29 end 30 31 describe "create EventOrCommitment" do 32 @tag skip: "TODO: fix events in factory" 33 test "with both event and commitment", %{params: params} do 34 assert {:error, %Changeset{errors: errs}} = 35 params 36 |> EventOrCommitment.changeset() 37 |> Repo.insert() 38 39 assert {:ok, _} = Keyword.fetch(errs, :event_id) 40 assert {:ok, _} = Keyword.fetch(errs, :commitment_id) 41 end 42 43 @tag skip: "TODO: fix events in factory" 44 test "with only event", %{params: params} do 45 assert {:ok, %EventOrCommitment{} = evt_comm} = 46 params 47 |> Map.delete(:commitment_id) 48 |> EventOrCommitment.changeset() 49 |> Repo.insert() 50 51 assert evt_comm.event_id == params.event_id 52 assert evt_comm.commitment_id == nil 53 end 54 55 @tag skip: "TODO: fix events in factory" 56 test "with only commitment", %{params: params} do 57 assert {:ok, %EventOrCommitment{} = evt_comm} = 58 params 59 |> Map.delete(:event_id) 60 |> EventOrCommitment.changeset() 61 |> Repo.insert() 62 63 assert evt_comm.event_id == nil 64 assert evt_comm.commitment_id == params.commitment_id 65 end 66 end 67 68 describe "update EventOrCommitment" do 69 @tag skip: "TODO: fix events in factory" 70 test "with both event and commitment", %{params: params} do 71 assert {:error, %Changeset{errors: errs}} = 72 :event_or_commitment 73 |> Factory.insert!(event: Factory.build(:economic_event), commitment: nil) 74 |> EventOrCommitment.changeset(params) 75 |> Repo.update() 76 77 assert {:ok, _} = Keyword.fetch(errs, :commitment_id) 78 79 assert {:error, %Changeset{errors: errs}} = 80 :event_or_commitment 81 |> Factory.insert!(event: nil, commitment: Factory.build(:commitment)) 82 |> EventOrCommitment.changeset(params) 83 |> Repo.update() 84 85 assert {:ok, _} = Keyword.fetch(errs, :event_id) 86 end 87 88 @tag skip: "TODO: fix events in factory" 89 test "with only event", %{params: params} do 90 assert {:ok, %EventOrCommitment{} = evt_comm} = 91 :event_or_commitment 92 |> Factory.insert!(event: Factory.build(:economic_event), commitment: nil) 93 |> EventOrCommitment.changeset( 94 Map.delete(params, :commitment_id) 95 ) 96 |> Repo.update() 97 98 assert evt_comm.event_id == params.event_id 99 assert evt_comm.commitment_id == nil 100 end 101 102 @tag skip: "TODO: fix events in factory" 103 test "with only commitment", %{params: params} do 104 assert {:ok, %EventOrCommitment{} = evt_comm} = 105 :event_or_commitment 106 |> Factory.insert!(event: nil, commitment: Factory.build(:commitment)) 107 |> EventOrCommitment.changeset( 108 Map.delete(params, :event_id) 109 ) 110 |> Repo.update() 111 112 assert evt_comm.event_id == nil 113 assert evt_comm.commitment_id == params.commitment_id 114 end 115 end 116 end