type.test.exs (2926B)
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.ProductBatch.Type do 19 use ZenflowsTest.Help.AbsinCase, async: true 20 21 setup do 22 %{ 23 params: %{ 24 "batchNumber" => Factory.str("batch number"), 25 "expiryDate" => Factory.iso_now(), 26 "productionDate" => Factory.iso_now(), 27 }, 28 inserted: Factory.insert!(:product_batch), 29 } 30 end 31 32 @frag """ 33 fragment productBatch on ProductBatch { 34 id 35 batchNumber 36 expiryDate 37 productionDate 38 } 39 """ 40 41 describe "Query" do 42 test "productBatch", %{inserted: new} do 43 assert %{data: %{"productBatch" => data}} = 44 run!(""" 45 #{@frag} 46 query ($id: ID!) { 47 productBatch(id: $id) {...productBatch} 48 } 49 """, vars: %{"id" => new.id}) 50 51 assert data["id"] == new.id 52 assert data["batchNumber"] == new.batch_number 53 assert data["expiryDate"] == DateTime.to_iso8601(new.expiry_date) 54 assert data["productionDate"] == DateTime.to_iso8601(new.production_date) 55 end 56 end 57 58 describe "Mutation" do 59 test "createProductBatch", %{params: params} do 60 assert %{data: %{"createProductBatch" => %{"productBatch" => data}}} = 61 run!(""" 62 #{@frag} 63 mutation ($productBatch: ProductBatchCreateParams!) { 64 createProductBatch(productBatch: $productBatch) { 65 productBatch {...productBatch} 66 } 67 } 68 """, vars: %{"productBatch" => params}) 69 70 assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) 71 data = Map.delete(data, "id") 72 assert data == params 73 end 74 75 test "updateProductBatch", %{params: params, inserted: old} do 76 assert %{data: %{"updateProductBatch" => %{"productBatch" => data}}} = 77 run!(""" 78 #{@frag} 79 mutation ($productBatch: ProductBatchUpdateParams!) { 80 updateProductBatch(productBatch: $productBatch) { 81 productBatch {...productBatch} 82 } 83 } 84 """, vars: %{"productBatch" => Map.put(params, "id", old.id)}) 85 86 assert data["id"] == old.id 87 data = Map.delete(data, "id") 88 assert data == params 89 end 90 91 test "deleteProductBatch()", %{inserted: %{id: id}} do 92 assert %{data: %{"deleteProductBatch" => true}} = 93 run!(""" 94 mutation ($id: ID!) { 95 deleteProductBatch(id: $id) 96 } 97 """, vars: %{"id" => id}) 98 end 99 end 100 end