zf

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

type.test.exs (3887B)


      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.Process.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 			"finished" => Factory.bool(),
     29 			"classifiedAs" => Factory.str_list("class"),
     30 			"basedOn" => Factory.insert!(:process_specification).id,
     31 			"plannedWithin" => Factory.insert!(:plan).id,
     32 			"nestedIn" => Factory.insert!(:scenario).id,
     33 		},
     34 		inserted: Factory.insert!(:process),
     35 	}
     36 end
     37 
     38 @frag """
     39 fragment process on Process {
     40 	id
     41 	name
     42 	note
     43 	hasBeginning
     44 	hasEnd
     45 	finished
     46 	deletable
     47 	classifiedAs
     48 	basedOn {id}
     49 	plannedWithin {id}
     50 	nestedIn {id}
     51 }
     52 """
     53 
     54 describe "Query" do
     55 	test "process", %{inserted: new} do
     56 		assert %{data: %{"process" => data}} =
     57 			run!("""
     58 				#{@frag}
     59 				query ($id: ID!) {
     60 					process(id: $id) {...process}
     61 				}
     62 			""", vars: %{"id" => new.id})
     63 
     64 		assert data["id"] == new.id
     65 		assert data["name"] == new.name
     66 		assert data["hasBeginning"] == DateTime.to_iso8601(new.has_beginning)
     67 		assert data["hasEnd"] == DateTime.to_iso8601(new.has_end)
     68 		assert data["finished"] == new.finished
     69 		assert data["deletable"] == false
     70 		assert data["classifiedAs"] == new.classified_as
     71 		assert data["basedOn"]["id"] == new.based_on_id
     72 		assert data["plannedWithin"]["id"] == new.planned_within_id
     73 		assert data["nestedIn"]["id"] == new.nested_in_id
     74 	end
     75 end
     76 
     77 describe "Mutation" do
     78 	test "createProcess", %{params: params} do
     79 		assert %{data: %{"createProcess" => %{"process" => data}}} =
     80 			run!("""
     81 				#{@frag}
     82 				mutation ($process: ProcessCreateParams!) {
     83 					createProcess(process: $process) {
     84 						process {...process}
     85 					}
     86 				}
     87 			""", vars: %{"process" => params})
     88 
     89 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     90 
     91 		keys = ~w[name hasBeginning hasEnd finished classifiedAs]
     92 		assert Map.take(data, keys) == Map.take(params, keys)
     93 
     94 		assert data["deletable"] == false
     95 		assert data["basedOn"]["id"] == params["basedOn"]
     96 		assert data["plannedWithin"]["id"] == params["plannedWithin"]
     97 		assert data["nestedIn"]["id"] == params["nestedIn"]
     98 	end
     99 
    100 	test "updateProcess", %{params: params, inserted: old} do
    101 		assert %{data: %{"updateProcess" => %{"process" => data}}} =
    102 			run!("""
    103 				#{@frag}
    104 				mutation ($process: ProcessUpdateParams!) {
    105 					updateProcess(process: $process) {
    106 						process {...process}
    107 					}
    108 				}
    109 			""", vars: %{"process" => Map.put(params, "id", old.id)})
    110 
    111 		assert data["id"] == old.id
    112 		keys = ~w[name hasBeginning hasEnd finished classifiedAs]
    113 		assert Map.take(data, keys) == Map.take(params, keys)
    114 
    115 		assert data["deletable"] == false
    116 		assert data["basedOn"]["id"] == params["basedOn"]
    117 		assert data["plannedWithin"]["id"] == params["plannedWithin"]
    118 		assert data["nestedIn"]["id"] == params["nestedIn"]
    119 	end
    120 
    121 	test "deleteProcess", %{inserted: %{id: id}} do
    122 		assert %{data: %{"deleteProcess" => true}} =
    123 			run!("""
    124 				mutation ($id: ID!) {
    125 					deleteProcess(id: $id)
    126 				}
    127 			""", vars: %{"id" => id})
    128 	end
    129 end
    130 end