type.test.exs (3423B)
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.ScenarioDefinition.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 "hasDuration" => %{ 27 "unitType" => Factory.build(:time_unit) |> to_string(), 28 "numericDuration" => Factory.decimal(), 29 }, 30 }, 31 inserted: Factory.insert!(:scenario_definition), 32 } 33 end 34 35 @frag """ 36 fragment scenarioDefinition on ScenarioDefinition { 37 id 38 name 39 note 40 hasDuration { 41 unitType 42 numericDuration 43 } 44 } 45 """ 46 47 describe "Query" do 48 test "scenarioDefinition", %{inserted: new} do 49 assert %{data: %{"scenarioDefinition" => data}} = 50 run!(""" 51 #{@frag} 52 query ($id: ID!) { 53 scenarioDefinition(id: $id) {...scenarioDefinition} 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["hasDuration"]["unitType"] == to_string(new.has_duration_unit_type) 61 assert Decimal.eq?(data["hasDuration"]["numericDuration"], new.has_duration_numeric_duration) 62 end 63 end 64 65 describe "Mutation" do 66 test "createScenarioDefinition", %{params: params} do 67 assert %{data: %{"createScenarioDefinition" => %{"scenarioDefinition" => data}}} = 68 run!(""" 69 #{@frag} 70 mutation ($scenarioDefinition: ScenarioDefinitionCreateParams!) { 71 createScenarioDefinition(scenarioDefinition: $scenarioDefinition) { 72 scenarioDefinition {...scenarioDefinition} 73 } 74 } 75 """, vars: %{"scenarioDefinition" => params}) 76 77 assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) 78 assert data["name"] == params["name"] 79 assert data["note"] == params["note"] 80 assert data["hasDuration"] == params["hasDuration"] 81 end 82 83 test "updateScenarioDefinition", %{params: params, inserted: old} do 84 assert %{data: %{"updateScenarioDefinition" => %{"scenarioDefinition" => data}}} = 85 run!(""" 86 #{@frag} 87 mutation ($scenarioDefinition: ScenarioDefinitionUpdateParams!) { 88 updateScenarioDefinition(scenarioDefinition: $scenarioDefinition) { 89 scenarioDefinition {...scenarioDefinition} 90 } 91 } 92 """, vars: %{"scenarioDefinition" => Map.put(params, "id", old.id)}) 93 94 assert data["id"] == old.id 95 assert data["name"] == params["name"] 96 assert data["note"] == params["note"] 97 assert data["hasDuration"] == params["hasDuration"] 98 end 99 100 test "deleteScenarioDefinition()", %{inserted: %{id: id}} do 101 assert %{data: %{"deleteScenarioDefinition" => true}} = 102 run!(""" 103 mutation ($id: ID!) { 104 deleteScenarioDefinition(id: $id) 105 } 106 """, vars: %{"id" => id}) 107 end 108 end 109 end