zf

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

domain.test.exs (2896B)


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