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