zf

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

type.test.exs (2519B)


      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.Unit.Type do
     19 use ZenflowsTest.Help.AbsinCase, async: true
     20 
     21 setup do
     22 	%{
     23 		params: %{
     24 			"label" => Factory.str("label"),
     25 			"symbol" => Factory.str("symbol"),
     26 		},
     27 		inserted: Factory.insert!(:unit),
     28 	}
     29 end
     30 
     31 @frag """
     32 fragment unit on Unit {
     33 	id
     34 	label
     35 	symbol
     36 }
     37 """
     38 
     39 describe "Query" do
     40 	test "unit", %{inserted: new} do
     41 		assert %{data: %{"unit" => data}} =
     42 			run!("""
     43 				#{@frag}
     44 				query ($id: ID!) {
     45 					unit(id: $id) {...unit}
     46 				}
     47 			""", vars: %{"id" => new.id})
     48 
     49 		assert data["id"] == new.id
     50 		assert data["label"] == new.label
     51 		assert data["symbol"] == new.symbol
     52 	end
     53 end
     54 
     55 describe "Mutation" do
     56 	test "createUnit", %{params: params} do
     57 		assert %{data: %{"createUnit" => %{"unit" => data}}} =
     58 			run!("""
     59 				#{@frag}
     60 				mutation ($unit: UnitCreateParams!) {
     61 					createUnit(unit: $unit) {
     62 						unit {...unit}
     63 					}
     64 				}
     65 			""", vars: %{"unit" => params})
     66 
     67 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     68 		assert data["label"] == params["label"]
     69 		assert data["symbol"] == params["symbol"]
     70 	end
     71 
     72 	test "updateUnit", %{params: params, inserted: old} do
     73 		assert %{data: %{"updateUnit" => %{"unit" => data}}} =
     74 			run!("""
     75 				#{@frag}
     76 				mutation ($unit: UnitUpdateParams!) {
     77 					updateUnit(unit: $unit) {
     78 						unit {...unit}
     79 					}
     80 				}
     81 			""", vars: %{"unit" => Map.put(params, "id", old.id)})
     82 
     83 		assert data["id"] == old.id
     84 		assert data["label"] == params["label"]
     85 		assert data["symbol"] == params["symbol"]
     86 	end
     87 
     88 	test "deleteUnit", %{inserted: %{id: id}} do
     89 		assert %{data: %{"deleteUnit" => true}} =
     90 			run!("""
     91 				mutation ($id: ID!) {
     92 					deleteUnit(id: $id)
     93 				}
     94 			""", vars: %{"id" => id})
     95 	end
     96 end
     97 end