zf

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

type.test.exs (3433B)


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