zf

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

type.test.exs (3631B)


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