zf

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

type.test.exs (3369B)


      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.Plan.Type do
     19 @moduledoc "A man, a plan, a canal: panama."
     20 
     21 use ZenflowsTest.Help.AbsinCase, async: true
     22 
     23 setup do
     24 	%{
     25 		params: %{
     26 			"name" => Factory.str("name"),
     27 			"note" => Factory.str("note"),
     28 			"due" => Factory.iso_now(),
     29 			"refinementOf" => Factory.insert!(:scenario).id,
     30 		},
     31 		inserted: Factory.insert!(:plan),
     32 	}
     33 end
     34 
     35 @frag """
     36 fragment plan on Plan {
     37 	id
     38 	name
     39 	note
     40 	created
     41 	due
     42 	refinementOf {id}
     43 }
     44 """
     45 
     46 describe "Query" do
     47 	test "plan", %{inserted: plan} do
     48 		assert %{data: %{"plan" => data}} =
     49 			run!("""
     50 				#{@frag}
     51 				query ($id: ID!) {
     52 					plan(id: $id) {...plan}
     53 				}
     54 			""", vars: %{"id" => plan.id})
     55 
     56 		assert data["id"] == plan.id
     57 		assert data["name"] == plan.name
     58 		assert data["note"] == plan.note
     59 		assert data["due"] == DateTime.to_iso8601(plan.due)
     60 		assert data["refinementOf"]["id"] == plan.refinement_of_id
     61 		assert {:ok, created, 0} = DateTime.from_iso8601(data["created"])
     62 		assert DateTime.compare(DateTime.utc_now(), created) != :lt
     63 	end
     64 end
     65 
     66 describe "Mutation" do
     67 	test "createPlan", %{params: params} do
     68 		assert %{data: %{"createPlan" => %{"plan" => data}}} =
     69 			run!("""
     70 				#{@frag}
     71 				mutation ($plan: PlanCreateParams!) {
     72 					createPlan(plan: $plan) {
     73 						plan {...plan}
     74 					}
     75 				}
     76 			""", vars: %{"plan" => params})
     77 
     78 		assert {:ok, _} = Zenflows.DB.ID.cast(data["id"])
     79 		assert data["name"] == params["name"]
     80 		assert data["note"] == params["note"]
     81 		assert data["due"] == params["due"]
     82 		assert data["refinementOf"]["id"] == params["refinementOf"]
     83 		assert {:ok, created, 0} = DateTime.from_iso8601(data["created"])
     84 		assert DateTime.compare(DateTime.utc_now(), created) != :lt
     85 	end
     86 
     87 	test "updatePlan", %{params: params, inserted: plan} do
     88 		assert %{data: %{"updatePlan" => %{"plan" => data}}} =
     89 			run!("""
     90 				#{@frag}
     91 				mutation ($plan: PlanUpdateParams!) {
     92 					updatePlan(plan: $plan) {
     93 						plan {...plan}
     94 					}
     95 				}
     96 			""", vars: %{"plan" => params |> Map.put("id", plan.id)})
     97 
     98 		assert data["id"] == plan.id
     99 		assert data["name"] == params["name"]
    100 		assert data["note"] == params["note"]
    101 		assert data["due"] == params["due"]
    102 		assert data["refinementOf"]["id"] == params["refinementOf"]
    103 		assert {:ok, created, 0} = DateTime.from_iso8601(data["created"])
    104 		assert DateTime.compare(DateTime.utc_now(), created) != :lt
    105 	end
    106 
    107 	test "deletePlan", %{inserted: %{id: id}} do
    108 		assert %{data: %{"deletePlan" => true}} =
    109 			run!("""
    110 				mutation ($id: ID!) {
    111 					deletePlan(id: $id)
    112 				}
    113 			""", vars: %{"id" => id})
    114 	end
    115 end
    116 end