zf

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

type.test.exs (3387B)


      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.Scenario.Type do
     19 use ZenflowsTest.Help.AbsinCase, async: true
     20 
     21 setup do
     22 	%{
     23 		params: %{
     24 			"name" => Factory.str("name"),
     25 			"note" => Factory.str("note"),
     26 			"hasBeginning" => Factory.iso_now(),
     27 			"hasEnd" => Factory.iso_now(),
     28 			"definedAs" => Factory.insert!(:scenario_definition).id,
     29 			"refinementOf" => Factory.insert!(:scenario).id,
     30 		},
     31 		inserted: Factory.insert!(:scenario),
     32 	}
     33 end
     34 
     35 @frag """
     36 fragment scenario on Scenario {
     37 	id
     38 	name
     39 	note
     40 	hasBeginning
     41 	hasEnd
     42 	definedAs {id}
     43 	refinementOf {id}
     44 }
     45 """
     46 
     47 describe "Query" do
     48 	test "scenario", %{inserted: new} do
     49 		assert %{data: %{"scenario" => data}} =
     50 			run!("""
     51 				#{@frag}
     52 				query ($id: ID!) {
     53 					scenario(id: $id) {...scenario}
     54 				}
     55 			""", vars: %{"id" => new.id})
     56 
     57 		assert data["id"] == new.id
     58 		assert data["name"] == new.name
     59 		assert data["note"] == new.note
     60 		assert data["hasBeginning"] == DateTime.to_iso8601(new.has_beginning)
     61 		assert data["hasEnd"] == DateTime.to_iso8601(new.has_end)
     62 		assert data["definedAs"]["id"] == new.defined_as_id
     63 		assert data["refinementOf"]["id"] == new.refinement_of_id
     64 	end
     65 end
     66 
     67 describe "Mutation" do
     68 	test "createScenario", %{params: params} do
     69 		assert %{data: %{"createScenario" => %{"scenario" => data}}} =
     70 			run!("""
     71 				#{@frag}
     72 				mutation ($scenario: ScenarioCreateParams!) {
     73 					createScenario(scenario: $scenario) {
     74 						scenario {...scenario}
     75 					}
     76 				}
     77 			""", vars: %{"scenario" => params})
     78 
     79 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     80 		keys = ~w[name note hasBeginning hasEnd]
     81 		assert Map.take(data, keys) == Map.take(params, keys)
     82 		assert data["definedAs"]["id"] == params["definedAs"]
     83 		assert data["refinementOf"]["id"] == params["refinementOf"]
     84 	end
     85 
     86 	test "updateScenario", %{params: params, inserted: old} do
     87 		assert %{data: %{"updateScenario" => %{"scenario" => data}}} =
     88 			run!("""
     89 				#{@frag}
     90 				mutation ($scenario: ScenarioUpdateParams!) {
     91 					updateScenario(scenario: $scenario) {
     92 						scenario {...scenario}
     93 					}
     94 				}
     95 			""", vars: %{"scenario" => Map.put(params, "id", old.id)})
     96 
     97 		assert data["id"] == old.id
     98 		keys = ~w[name note hasBeginning hasEnd]
     99 		assert Map.take(data, keys) == Map.take(params, keys)
    100 		assert data["definedAs"]["id"] == params["definedAs"]
    101 		assert data["refinementOf"]["id"] == params["refinementOf"]
    102 	end
    103 
    104 	test "deleteScenario", %{inserted: %{id: id}} do
    105 		assert %{data: %{"deleteScenario" => true}} =
    106 			run!("""
    107 				mutation ($id: ID!) {
    108 					deleteScenario(id: $id)
    109 				}
    110 			""", vars: %{"id" => id})
    111 	end
    112 end
    113 end