zf

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

type.test.exs (3021B)


      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.ProcessSpecification.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 		},
     27 		inserted: Factory.insert!(:process_specification),
     28 	}
     29 end
     30 
     31 @frag """
     32 fragment processSpecification on ProcessSpecification {
     33 	id
     34 	name
     35 	note
     36 }
     37 """
     38 
     39 describe "Query" do
     40 	test "processSpecification", %{inserted: new} do
     41 		assert %{data: %{"processSpecification" => data}} =
     42 			run!("""
     43 				#{@frag}
     44 				query ($id: ID!) {
     45 					processSpecification(id: $id) {...processSpecification}
     46 				}
     47 			""", vars: %{"id" => new.id})
     48 
     49 		assert data["id"] == new.id
     50 		assert data["name"] == new.name
     51 		assert data["note"] == new.note
     52 	end
     53 end
     54 
     55 describe "Mutation" do
     56 	test "createProcessSpecification", %{params: params} do
     57 		assert %{data: %{"createProcessSpecification" => %{"processSpecification" => data}}} =
     58 			run!("""
     59 				#{@frag}
     60 				mutation ($processSpecification: ProcessSpecificationCreateParams!) {
     61 					createProcessSpecification(processSpecification: $processSpecification) {
     62 						processSpecification {...processSpecification}
     63 					}
     64 				}
     65 			""", vars: %{"processSpecification" => params})
     66 
     67 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     68 		assert data["name"] == params["name"]
     69 		assert data["note"] == params["note"]
     70 	end
     71 
     72 	test "updateProcessSpecification", %{params: params, inserted: old} do
     73 		assert %{data: %{"updateProcessSpecification" => %{"processSpecification" => data}}} =
     74 			run!("""
     75 				#{@frag}
     76 				mutation ($processSpecification: ProcessSpecificationUpdateParams!) {
     77 					updateProcessSpecification(processSpecification: $processSpecification) {
     78 						processSpecification {...processSpecification}
     79 					}
     80 				}
     81 			""", vars: %{"processSpecification" => Map.put(params, "id", old.id)})
     82 
     83 		assert data["id"] == old.id
     84 		assert data["name"] == params["name"]
     85 		assert data["note"] == params["note"]
     86 	end
     87 
     88 	test "deleteProcessSpecification", %{inserted: %{id: id}} do
     89 		assert %{data: %{"deleteProcessSpecification" => true}} =
     90 			run!("""
     91 				mutation ($id: ID!) {
     92 					deleteProcessSpecification(id: $id)
     93 				}
     94 			""", vars: %{"id" => id})
     95 	end
     96 end
     97 end