zf

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

domain.test.exs (2718B)


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