type.test.exs (2757B)
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.RoleBehavior.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!(:role_behavior), 28 } 29 end 30 31 @frag """ 32 fragment roleBehavior on RoleBehavior { 33 id 34 name 35 note 36 } 37 """ 38 39 describe "Query" do 40 test "roleBehavior", %{inserted: new} do 41 assert %{data: %{"roleBehavior" => data}} = 42 run!(""" 43 #{@frag} 44 query ($id: ID!) { 45 roleBehavior(id: $id) {...roleBehavior} 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 "createRoleBehavior", %{params: params} do 57 assert %{data: %{"createRoleBehavior" => %{"roleBehavior" => data}}} = 58 run!(""" 59 #{@frag} 60 mutation ($roleBehavior: RoleBehaviorCreateParams!) { 61 createRoleBehavior(roleBehavior: $roleBehavior) { 62 roleBehavior {...roleBehavior} 63 } 64 } 65 """, vars: %{"roleBehavior" => 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 "updateRoleBehavior", %{params: params, inserted: old} do 73 assert %{data: %{"updateRoleBehavior" => %{"roleBehavior" => data}}} = 74 run!(""" 75 #{@frag} 76 mutation ($roleBehavior: RoleBehaviorUpdateParams!) { 77 updateRoleBehavior(roleBehavior: $roleBehavior) { 78 roleBehavior {...roleBehavior} 79 } 80 } 81 """, vars: %{"roleBehavior" => 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 "deleteRoleBehavior", %{inserted: %{id: id}} do 89 assert %{data: %{"deleteRoleBehavior" => true}} = 90 run!(""" 91 mutation ($id: ID!) { 92 deleteRoleBehavior(id: $id) 93 } 94 """, vars: %{"id" => id}) 95 end 96 end 97 end