zf

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

type.test.exs (4620B)


      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.RecipeProcess.Type do
     19 use ZenflowsTest.Help.AbsinCase, async: true
     20 
     21 setup do
     22 	%{
     23 		params: %{
     24 			"name" => Factory.str("name"),
     25 			"hasDuration" => %{
     26 				"unitType" => Factory.build(:time_unit) |> to_string(),
     27 				"numericDuration" => Factory.decimal(),
     28 			},
     29 			"processClassifiedAs" => Factory.str_list("uri"),
     30 			"processConformsTo" => Factory.insert!(:process_specification).id,
     31 			"note" => Factory.str("note"),
     32 		},
     33 		inserted: Factory.insert!(:recipe_process),
     34 	}
     35 end
     36 
     37 @frag """
     38 fragment recipeProcess on RecipeProcess {
     39 	id
     40 	name
     41 	note
     42 	processClassifiedAs
     43 	processConformsTo {id}
     44 	hasDuration {
     45 		unitType
     46 		numericDuration
     47 	}
     48 }
     49 """
     50 
     51 describe "Query" do
     52 	test "recipeProcess", %{inserted: new} do
     53 		assert %{data: %{"recipeProcess" => data}} =
     54 			run!("""
     55 				#{@frag}
     56 				query ($id: ID!) {
     57 					recipeProcess(id: $id) {...recipeProcess}
     58 				}
     59 			""", vars: %{"id" => new.id})
     60 
     61 		assert data["id"] == new.id
     62 		assert data["name"] == new.name
     63 		assert data["note"] == new.note
     64 		assert data["processClassifiedAs"] == new.process_classified_as
     65 		assert data["processConformsTo"]["id"] == new.process_conforms_to_id
     66 		assert data["hasDuration"]["unitType"] == to_string(new.has_duration_unit_type)
     67 		assert Decimal.eq?(data["hasDuration"]["numericDuration"], new.has_duration_numeric_duration) end
     68 end
     69 
     70 describe "Mutation" do
     71 	test "createRecipeProcess", %{params: params} do
     72 		assert %{data: %{"createRecipeProcess" => %{"recipeProcess" => data}}} =
     73 			run!("""
     74 				#{@frag}
     75 				mutation ($recipeProcess: RecipeProcessCreateParams!) {
     76 					createRecipeProcess(recipeProcess: $recipeProcess) {
     77 						recipeProcess {...recipeProcess}
     78 					}
     79 				}
     80 			""", vars: %{"recipeProcess" => params})
     81 
     82 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     83 		assert data["name"] == params["name"]
     84 		assert data["note"] == params["note"]
     85 		assert data["processClassifiedAs"] == params["processClassifiedAs"]
     86 		assert data["processConformsTo"]["id"] == params["processConformsTo"]
     87 		assert data["hasDuration"] == params["hasDuration"]
     88 	end
     89 
     90 	test "updateRecipeProcess", %{params: params, inserted: old} do
     91 		assert %{data: %{"updateRecipeProcess" => %{"recipeProcess" => data}}} =
     92 			run!("""
     93 				#{@frag}
     94 				mutation ($recipeProcess: RecipeProcessUpdateParams!) {
     95 					updateRecipeProcess(recipeProcess: $recipeProcess) {
     96 						recipeProcess {...recipeProcess}
     97 					}
     98 				}
     99 			""", vars: %{"recipeProcess" => Map.put(params, "id", old.id)})
    100 
    101 		assert data["id"] == old.id
    102 		assert data["name"] == params["name"]
    103 		assert data["note"] == params["note"]
    104 		assert data["processClassifiedAs"] == params["processClassifiedAs"]
    105 		assert data["processConformsTo"]["id"] == params["processConformsTo"]
    106 		assert data["hasDuration"] == params["hasDuration"]
    107 	end
    108 
    109 	test "updateRecipeProcess: hasDuration set null", %{params: params, inserted: old} do
    110 		assert %{data: %{"updateRecipeProcess" => %{"recipeProcess" => data}}} =
    111 			run!("""
    112 				#{@frag}
    113 				mutation ($recipeProcess: RecipeProcessUpdateParams!) {
    114 					updateRecipeProcess(recipeProcess: $recipeProcess) {
    115 						recipeProcess {...recipeProcess}
    116 					}
    117 				}
    118 			""", vars: %{
    119 				"recipeProcess" =>
    120 					params
    121 					|> Map.put("id", old.id)
    122 					|> Map.put("hasDuration", nil)
    123 			})
    124 
    125 		assert data["id"] == old.id
    126 		assert data["name"] == params["name"]
    127 		assert data["note"] == params["note"]
    128 		assert data["processClassifiedAs"] == params["processClassifiedAs"]
    129 		assert data["processConformsTo"]["id"] == params["processConformsTo"]
    130 		assert data["hasDuration"] == nil
    131 	end
    132 
    133 	test "deleteRecipeProcess", %{inserted: %{id: id}} do
    134 		assert %{data: %{"deleteRecipeProcess" => true}} =
    135 			run!("""
    136 				mutation ($id: ID!) {
    137 					deleteRecipeProcess(id: $id)
    138 				}
    139 			""", vars: %{"id" => id})
    140 	end
    141 end
    142 end