zf

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

type.test.exs (3982B)


      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.RecipeResource.Type do
     19 use ZenflowsTest.Help.AbsinCase, async: true
     20 
     21 setup do
     22 	%{
     23 		params: %{
     24 			"name" => Factory.str("name"),
     25 			"resourceClassifiedAs" => Factory.str_list("uri"),
     26 			"unitOfEffort" => Factory.insert!(:unit).id,
     27 			"unitOfResource" => Factory.insert!(:unit).id,
     28 			"resourceConformsTo" => Factory.insert!(:resource_specification).id,
     29 			"substitutable" => Factory.bool(),
     30 			"note" => Factory.str("note"),
     31 		},
     32 		inserted: Factory.insert!(:recipe_resource),
     33 	}
     34 end
     35 
     36 @frag """
     37 fragment recipeResource on RecipeResource {
     38 	id
     39 	name
     40 	resourceClassifiedAs
     41 	unitOfResource {id}
     42 	unitOfEffort {id}
     43 	resourceConformsTo {id}
     44 	substitutable
     45 	note
     46 }
     47 """
     48 
     49 describe "Query" do
     50 	test "recipeResource", %{inserted: new} do
     51 		assert %{data: %{"recipeResource" => data}} =
     52 			run!("""
     53 				#{@frag}
     54 				query ($id: ID!) {
     55 					recipeResource(id: $id) {...recipeResource}
     56 				}
     57 			""", vars: %{"id" => new.id})
     58 
     59 		assert data["id"] == new.id
     60 		assert data["name"] == new.name
     61 		assert data["resourceClassifiedAs"] == new.resource_classified_as
     62 		assert data["unitOfResource"]["id"] == new.unit_of_resource_id
     63 		assert data["unitOfEffort"]["id"] == new.unit_of_effort_id
     64 		assert data["resourceConformsTo"]["id"] == new.resource_conforms_to_id
     65 		assert data["note"] == new.note
     66 		assert data["substitutable"] == new.substitutable
     67 	end
     68 end
     69 
     70 describe "Mutation" do
     71 	test "createRecipeResource", %{params: params} do
     72 		assert %{data: %{"createRecipeResource" => %{"recipeResource" => data}}} =
     73 			run!("""
     74 				#{@frag}
     75 				mutation ($recipeResource: RecipeResourceCreateParams!) {
     76 					createRecipeResource(recipeResource: $recipeResource) {
     77 						recipeResource {...recipeResource}
     78 					}
     79 				}
     80 			""", vars: %{"recipeResource" => params})
     81 
     82 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     83 		keys = ~w[name note resourceClassifiedAs substitutable]
     84 		assert Map.take(data, keys) == Map.take(params, keys)
     85 		assert data["unitOfResource"]["id"] == params["unitOfResource"]
     86 		assert data["unitOfEffort"]["id"] == params["unitOfEffort"]
     87 		assert data["resourceConformsTo"]["id"] == params["resourceConformsTo"]
     88 	end
     89 
     90 	test "updateRecipeResource()", %{params: params, inserted: old} do
     91 		assert %{data: %{"updateRecipeResource" => %{"recipeResource" => data}}} =
     92 			run!("""
     93 				#{@frag}
     94 				mutation ($recipeResource: RecipeResourceUpdateParams!) {
     95 					updateRecipeResource(recipeResource: $recipeResource) {
     96 						recipeResource {...recipeResource}
     97 					}
     98 				}
     99 			""", vars: %{"recipeResource" => Map.put(params, "id", old.id)})
    100 
    101 		assert data["id"] == old.id
    102 		keys = ~w[name note resourceClassifiedAs substitutable]
    103 		assert Map.take(data, keys) == Map.take(params, keys)
    104 		assert data["unitOfResource"]["id"] == params["unitOfResource"]
    105 		assert data["unitOfEffort"]["id"] == params["unitOfEffort"]
    106 		assert data["resourceConformsTo"]["id"] == params["resourceConformsTo"]
    107 	end
    108 
    109 	test "deleteRecipeResource()", %{inserted: %{id: id}} do
    110 		assert %{data: %{"deleteRecipeResource" => true}} =
    111 			run!("""
    112 				mutation ($id: ID!) {
    113 					deleteRecipeResource(id: $id)
    114 				}
    115 			""", vars: %{"id" => id})
    116 	end
    117 end
    118 end