zf

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

type.test.exs (3695B)


      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.Agent.Type do
     19 use ZenflowsTest.Help.AbsinCase, async: true
     20 
     21 setup do
     22 	%{
     23 		per: Factory.insert!(:person),
     24 		org: Factory.insert!(:organization),
     25 	}
     26 end
     27 
     28 @tag skip: "TODO: sign query"
     29 test "Query myAgent" do
     30 	assert %{data: %{"myAgent" => data}} =
     31 		run!("""
     32 			query {
     33 				myAgent {
     34 					id
     35 					name
     36 					note
     37 				}
     38 			}
     39 		""", auth?: true)
     40 
     41 	assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     42 	assert data["name"] == "hello"
     43 	assert data["note"] == "world"
     44 end
     45 
     46 describe "Query agent()" do
     47 	test "as Agent with Person concrete type", %{per: per} do
     48 		assert %{data: %{"agent" => data}} =
     49 			run!("""
     50 				query ($id: ID!) {
     51 					agent(id: $id) {
     52 						id
     53 						name
     54 						note
     55 						primaryLocation { id }
     56 					}
     57 				}
     58 			""", vars: %{"id" => per.id})
     59 
     60 		assert data["id"] == per.id
     61 		assert data["name"] == per.name
     62 		assert data["note"] == per.note
     63 		assert data["primaryLocation"]["id"] == per.primary_location_id
     64 	end
     65 
     66 	test "as Agent with Organization concrete type", %{org: org} do
     67 		assert %{data: %{"agent" => data}} =
     68 			run!("""
     69 				query ($id: ID!) {
     70 					agent(id: $id) {
     71 						id
     72 						name
     73 						note
     74 						primaryLocation { id }
     75 					}
     76 				}
     77 			""", vars: %{"id" => org.id})
     78 
     79 		assert data["id"] == org.id
     80 		assert data["name"] == org.name
     81 		assert data["note"] == org.note
     82 		assert data["primaryLocation"]["id"] == org.primary_location_id
     83 	end
     84 
     85 	test "as Person", %{per: per} do
     86 		assert %{data: %{"agent" => data}} =
     87 			run!("""
     88 				query($id: ID!) {
     89 					agent(id: $id) {
     90 						... on Person {
     91 							id
     92 							name
     93 							note
     94 							primaryLocation { id }
     95 							user
     96 							email
     97 							ecdhPublicKey
     98 							eddsaPublicKey
     99 							ethereumAddress
    100 							reflowPublicKey
    101 							bitcoinPublicKey
    102 						}
    103 					}
    104 				}
    105 			""", vars: %{"id" => per.id})
    106 
    107 		assert data["id"] == per.id
    108 		assert data["name"] == per.name
    109 		assert data["note"] == per.note
    110 		assert data["primaryLocation"]["id"] == per.primary_location_id
    111 
    112 		assert data["user"] == per.user
    113 		assert data["email"] == per.email
    114 		assert data["ecdhPublicKey"] == per.ecdh_public_key
    115 		assert data["eddsaPublicKey"] == per.eddsa_public_key
    116 		assert data["ethereumAddress"] == per.ethereum_address
    117 		assert data["reflowPublicKey"] == per.reflow_public_key
    118 		assert data["bitcoinPublicKey"] == per.bitcoin_public_key
    119 	end
    120 
    121 	test "as Organization", %{org: org} do
    122 		assert %{data: %{"agent" => data}} =
    123 			run!("""
    124 				query ($id: ID!) {
    125 					agent(id: $id) {
    126 						... on Organization {
    127 							id
    128 							name
    129 							note
    130 							primaryLocation { id }
    131 							classifiedAs
    132 						}
    133 					}
    134 				}
    135 			""", vars: %{"id" => org.id})
    136 
    137 		assert data["id"] == org.id
    138 		assert data["name"] == org.name
    139 		assert data["note"] == org.note
    140 		assert data["primaryLocation"]["id"] == org.primary_location_id
    141 
    142 		assert data["classifiedAs"] == org.classified_as
    143 	end
    144 end
    145 end