zf

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

type.test.exs (3072B)


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