zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

domain.test.exs (2717B)


      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.ProposedIntent.Domain do
     19 use ZenflowsTest.Help.EctoCase, async: true
     20 
     21 alias Ecto.Changeset
     22 alias Zenflows.VF.{
     23 	Intent,
     24 	Proposal,
     25 	ProposedIntent,
     26 	ProposedIntent.Domain,
     27 }
     28 
     29 setup do
     30 	%{
     31 		params: %{
     32 			reciprocal: Factory.bool(),
     33 			publishes_id: Factory.insert!(:intent).id,
     34 			published_in_id: Factory.insert!(:proposal).id,
     35 		},
     36 		inserted: Factory.insert!(:proposed_intent),
     37 	}
     38 end
     39 
     40 describe "one/1" do
     41 	test "with good id: finds the ProposedIntent", %{inserted: %{id: id}} do
     42 		assert {:ok, %ProposedIntent{}} = Domain.one(id)
     43 	end
     44 
     45 	test "with bad id: doesn't find the ProposedIntent" do
     46 		assert {:error, "not found"} = Domain.one(Factory.id())
     47 	end
     48 end
     49 
     50 describe "create/1" do
     51 	test "with good params: creates a ProposedIntent", %{params: params} do
     52 		assert {:ok, %ProposedIntent{} = new} = Domain.create(params)
     53 		assert new.reciprocal == params.reciprocal
     54 		assert new.publishes_id == params.publishes_id
     55 		assert new.published_in_id == params.published_in_id
     56 	end
     57 
     58 	test "with bad params: doesn't create a ProposedIntent" do
     59 		assert {:error, %Changeset{}} = Domain.create(%{})
     60 	end
     61 end
     62 
     63 describe "delete/1" do
     64 	test "with good id: deletes the ProposedIntent", %{inserted: %{id: id}} do
     65 		assert {:ok, %ProposedIntent{id: ^id}} = Domain.delete(id)
     66 		assert {:error, "not found"} = Domain.one(id)
     67 	end
     68 
     69 	test "with bad id: doesn't delete the ProposedIntent" do
     70 		assert {:error, "not found"} = Domain.delete(Factory.id())
     71 	end
     72 end
     73 
     74 describe "preload/2" do
     75 	test "preloads `:published_in`", %{inserted: %{id: id}} do
     76 		assert {:ok, prop} =  Domain.one(id)
     77 		prop = Domain.preload(prop, :published_in)
     78 		assert %Proposal{} = prop.published_in
     79  	end
     80 
     81 	test "preloads `:publishes`", %{inserted: %{id: id}} do
     82 		assert {:ok, prop} =  Domain.one(id)
     83 		prop = Domain.preload(prop, :publishes)
     84 		assert %Intent{} = prop.publishes
     85  	end
     86 end
     87 end