type.test.exs (6006B)
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.EconomicEvent.Type do 19 use ZenflowsTest.Help.AbsinCase, async: true 20 21 setup do 22 %{id: agent_id} = Factory.insert!(:agent) 23 %{ 24 params: %{ 25 action_id: "raise", 26 provider_id: agent_id, 27 receiver_id: agent_id, 28 resource_conforms_to_id: Factory.insert!(:resource_specification).id, 29 resource_quantity_has_unit_id: Factory.insert!(:unit).id, 30 resource_quantity_has_numerical_value: Factory.decimal(), 31 has_end: DateTime.utc_now(), 32 }, 33 inserted: %{}, 34 } 35 end 36 37 describe "Query" do 38 #test "economicEvent()", %{inserted: eco_evt} do 39 # assert %{data: %{"economicEvent" => data}} = 40 # query!(""" 41 # economicEvent(id: "#{eco_evt.id}") { 42 # id 43 # note 44 # action { id label resourceEffect onhandEffect inputOutput pairsWith } 45 # resourceQuantity { 46 # hasUnit { id } 47 # hasNumericalValue 48 # } 49 # effortQuantity { 50 # hasUnit { id } 51 # hasNumericalValue 52 # } 53 # economicEventResource { id } 54 # recipeInputOf { id } 55 # recipeOutputOf { id } 56 # recipeClauseOf { id } 57 # } 58 # """) 59 60 # assert data["id"] == eco_evt.id 61 # assert data["note"] == eco_evt.note 62 # assert data["action"]["id"] == action.id 63 # assert data["action"]["label"] == action.label 64 # assert data["action"]["resourceEffect"] == action.resource_effect 65 # assert data["action"]["onhandEffect"] == action.onhand_effect 66 # assert data["action"]["inputOutput"] == action.input_output 67 # assert data["action"]["pairsWith"] == action.pairs_with 68 # assert data["resourceQuantity"]["hasUnit"]["id"] == res_qty.has_unit_id 69 # assert data["resourceQuantity"]["hasNumericalValue"] == res_qty.has_numerical_value 70 # assert data["effortQuantity"]["hasUnit"]["id"] == eff_qty.has_unit_id 71 # assert data["effortQuantity"]["hasNumericalValue"] == eff_qty.has_numerical_value 72 # assert data["economicEventResource"]["id"] == eco_evt_res.id 73 # assert data["recipeInputOf"]["id"] == rec_in_of.id 74 # assert data["recipeOutputOf"]["id"] == rec_out_of.id 75 # assert data["recipeClauseOf"]["id"] == rec_clause_of.id 76 #end 77 end 78 79 describe "Mutation" do 80 test "createEconomicEvent()", %{params: params} do 81 assert %{data: %{"createEconomicEvent" => %{"economicEvent" => data}}} = 82 mutation!(""" 83 createEconomicEvent( 84 event: { 85 action: "raise" 86 provider: "#{params.provider_id}" 87 receiver: "#{params.receiver_id}" 88 resourceConformsTo: "#{params.resource_conforms_to_id}" 89 resourceQuantity: { 90 hasUnit: "#{params.resource_quantity_has_unit_id}" 91 hasNumericalValue: #{params.resource_quantity_has_numerical_value} 92 } 93 hasEnd: "#{params.has_end}" 94 } 95 newInventoriedResource: { 96 name: "yo/" 97 } 98 ) { 99 economicEvent { 100 id 101 action {id} 102 provider {id} 103 receiver {id} 104 resourceConformsTo {id} 105 resourceQuantity { 106 hasUnit {id} 107 hasNumericalValue 108 } 109 resourceInventoriedAs { 110 id 111 name 112 } 113 hasEnd 114 } 115 } 116 """) 117 118 assert {:ok, _} = Zenflows.DB.ID.cast(data["id"]) 119 end 120 121 #test "updateEconomicEvent()", %{params: params, inserted: eco_evt} do 122 # %{ 123 # action_id: action_id, 124 # resource_quantity: res_qty, 125 # effort_quantity: eff_qty, 126 # inserted_resource_id: eco_evt_res_id, 127 # recipe_input_of_id: rec_in_of_id, 128 # recipe_output_of_id: rec_out_of_id, 129 # recipe_clause_of_id: rec_clause_of_id, 130 # } = params 131 132 # assert %{data: %{"updateEconomicEvent" => %{"economicEvent" => data}}} = 133 # mutation!(""" 134 # updateEconomicEvent(economicEvent: { 135 # id: "#{eco_evt.id}" 136 # note: "#{params.note}" 137 # action: "#{action_id}" 138 # resourceQuantity: { 139 # hasUnit: "#{res_qty.has_unit_id}" 140 # hasNumericalValue: #{res_qty.has_numerical_value} 141 # } 142 # effortQuantity: { 143 # hasUnit: "#{eff_qty.has_unit_id}" 144 # hasNumericalValue: #{eff_qty.has_numerical_value} 145 # } 146 # economicEventResource: "#{eco_evt_res_id}" 147 # recipeInputOf: "#{rec_in_of_id}" 148 # recipeOutputOf: "#{rec_out_of_id}" 149 # recipeClauseOf: "#{rec_clause_of_id}" 150 # }) { 151 # economicEvent { 152 # id 153 # note 154 # action { id label resourceEffect onhandEffect inputOutput pairsWith } 155 # resourceQuantity { 156 # hasUnit { id } 157 # hasNumericalValue 158 # } 159 # effortQuantity { 160 # hasUnit { id } 161 # hasNumericalValue 162 # } 163 # economicEventResource { id } 164 # recipeInputOf { id } 165 # recipeOutputOf { id } 166 # recipeClauseOf { id } 167 # } 168 # } 169 # """) 170 171 # assert data["id"] == eco_evt.id 172 # assert data["note"] == params.note 173 # assert data["action"]["id"] == action_id 174 # assert data["resourceQuantity"]["hasUnit"]["id"] == res_qty.has_unit_id 175 # assert data["resourceQuantity"]["hasNumericalValue"] == res_qty.has_numerical_value 176 # assert data["effortQuantity"]["hasUnit"]["id"] == eff_qty.has_unit_id 177 # assert data["effortQuantity"]["hasNumericalValue"] == eff_qty.has_numerical_value 178 # assert data["economicEventResource"]["id"] == eco_evt_res_id 179 # assert data["recipeInputOf"]["id"] == rec_in_of_id 180 # assert data["recipeOutputOf"]["id"] == rec_out_of_id 181 # assert data["recipeClauseOf"]["id"] == rec_clause_of_id 182 #end 183 end 184 end