zf

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

type.test.exs (3886B)


      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.ResourceSpecification.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 			"note" => Factory.str("note"),
     27 			"defaultUnitOfEffort" => Factory.insert!(:unit).id,
     28 			"defaultUnitOfResource" => Factory.insert!(:unit).id,
     29 		},
     30 		inserted: Factory.insert!(:resource_specification),
     31 	}
     32 end
     33 
     34 @frag """
     35 fragment resourceSpecification on ResourceSpecification {
     36 	id
     37 	name
     38 	resourceClassifiedAs
     39 	defaultUnitOfResource {id}
     40 	defaultUnitOfEffort {id}
     41 	note
     42 }
     43 """
     44 
     45 describe "Query" do
     46 	test "resourceSpecification", %{inserted: new} do
     47 		assert %{data: %{"resourceSpecification" => data}} =
     48 			run!("""
     49 				#{@frag}
     50 				query ($id: ID!) {
     51 					resourceSpecification(id: $id) {...resourceSpecification}
     52 				}
     53 			""", vars: %{"id" => new.id})
     54 
     55 		assert data["id"] == new.id
     56 		assert data["name"] == new.name
     57 		assert data["resourceClassifiedAs"] == new.resource_classified_as
     58 		assert data["defaultUnitOfResource"]["id"] == new.default_unit_of_resource_id
     59 		assert data["defaultUnitOfEffort"]["id"] == new.default_unit_of_effort_id
     60 		assert data["note"] == new.note
     61 	end
     62 end
     63 
     64 describe "Mutation" do
     65 	test "createResourceSpecification", %{params: params} do
     66 		assert %{data: %{"createResourceSpecification" => %{"resourceSpecification" => data}}} =
     67 			run!("""
     68 				#{@frag}
     69 				mutation ($resourceSpecification: ResourceSpecificationCreateParams!) {
     70 					createResourceSpecification(resourceSpecification: $resourceSpecification) {
     71 						resourceSpecification {...resourceSpecification}
     72 					}
     73 				}
     74 			""", vars: %{"resourceSpecification" => params})
     75 
     76 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     77 		keys = ~w[name note resourceClassifiedAs note]
     78 		assert Map.take(data, keys) == Map.take(params, keys)
     79 		assert data["defaultUnitOfResource"]["id"] == params["defaultUnitOfResource"]
     80 		assert data["defaultUnitOfEffort"]["id"] == params["defaultUnitOfEffort"]
     81 	end
     82 
     83 	test "updateResourceSpecification()", %{params: params, inserted: old} do
     84 		assert %{data: %{"updateResourceSpecification" => %{"resourceSpecification" => data}}} =
     85 			run!("""
     86 				#{@frag}
     87 				mutation ($resourceSpecification: ResourceSpecificationUpdateParams!) {
     88 					updateResourceSpecification(resourceSpecification: $resourceSpecification) {
     89 						resourceSpecification {...resourceSpecification}
     90 					}
     91 				}
     92 			""", vars: %{"resourceSpecification" => Map.put(params, "id", old.id)})
     93 
     94 		assert data["id"] == old.id
     95 		keys = ~w[name note resourceClassifiedAs note]
     96 		assert Map.take(data, keys) == Map.take(params, keys)
     97 		assert data["defaultUnitOfResource"]["id"] == params["defaultUnitOfResource"]
     98 		assert data["defaultUnitOfEffort"]["id"] == params["defaultUnitOfEffort"]
     99 	end
    100 
    101 	test "deleteResourceSpecification()", %{inserted: %{id: id}} do
    102 		assert %{data: %{"deleteResourceSpecification" => true}} =
    103 			run!("""
    104 				mutation ($id: ID!) {
    105 					deleteResourceSpecification(id: $id)
    106 				}
    107 			""", vars: %{"id" => id})
    108 	end
    109 end
    110 end