zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

type.test.exs (5190B)


      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.EconomicResource.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 			#"image" => Factory.img(),
     27 		},
     28 		inserted: Factory.insert!(:economic_resource),
     29 	}
     30 end
     31 
     32 @frag """
     33 fragment economicResource on EconomicResource {
     34 	id
     35 	name
     36 	note
     37 	#image
     38 	trackingIdentifier
     39 	classifiedAs
     40 	conformsTo {id}
     41 	accountingQuantity {
     42 		hasUnit { id }
     43 		hasNumericalValue
     44 	}
     45 	onhandQuantity {
     46 		hasUnit { id }
     47 		hasNumericalValue
     48 	}
     49 	primaryAccountable {id}
     50 	custodian {id}
     51 	stage {id}
     52 	state {id}
     53 	currentLocation {id}
     54 	lot {id}
     55 	containedIn {id}
     56 	unitOfEffort {id}
     57 	okhv
     58 	repo
     59 	version
     60 	licensor
     61 	license
     62 	metadata
     63 }
     64 """
     65 
     66 describe "Query" do
     67 	test "resource", %{inserted: new} do
     68 		assert %{data: %{"economicResource" => data}} =
     69 			run!("""
     70 				#{@frag}
     71 				query ($id: ID!) {
     72 					economicResource(id: $id) {...economicResource}
     73 				}
     74 			""", vars: %{"id" => new.id})
     75 
     76 		assert data["id"] == new.id
     77 		assert data["name"] == new.name
     78 		assert data["note"] == new.note
     79 		#assert data["image"] == new.image
     80 		assert data["trackingIdentifier"] == new.tracking_identifier
     81 		assert data["classifiedAs"] == new.classified_as
     82 		assert data["conformsTo"]["id"] == new.conforms_to_id
     83 		assert data["accountingQuantity"]["hasUnit"]["id"] == new.accounting_quantity_has_unit_id
     84 		assert Decimal.eq?(data["accountingQuantity"]["hasNumericalValue"], new.accounting_quantity_has_numerical_value)
     85 		assert data["onhandQuantity"]["hasUnit"]["id"] == new.onhand_quantity_has_unit_id
     86 		assert Decimal.eq?(data["onhandQuantity"]["hasNumericalValue"], new.onhand_quantity_has_numerical_value)
     87 		assert data["primaryAccountable"]["id"] == new.primary_accountable_id
     88 		assert data["custodian"]["id"] == new.custodian_id
     89 		assert data["stage"]["id"] == new.stage_id
     90 		assert data["state"]["id"] == new.state_id
     91 		assert data["currentLocation"]["id"] == new.current_location_id
     92 		assert data["lot"]["id"] == new.lot_id
     93 		assert data["containedIn"]["id"] == new.contained_in_id
     94 		assert data["unitOfEffort"]["id"] == new.unit_of_effort_id
     95 		assert data["okhv"] == new.okhv
     96 		assert data["repo"] == new.repo
     97 		assert data["version"] == new.version
     98 		assert data["licensor"] == new.licensor
     99 		assert data["license"] == new.license
    100 		assert data["metadata"] == new.metadata
    101 	end
    102 end
    103 
    104 describe "Mutation" do
    105 	@tag skip: "TODO: fix factory"
    106 	test "updateEconomicResource", %{params: params, inserted: old} do
    107 		assert %{data: %{"updateEconomicResource" => %{"economicResource" => data}}} =
    108 			run!("""
    109 				#{@frag}
    110 				mutation ($resource: EconomicResourceUpdateParams!) {
    111 					updateEconomicResource(resource: $resource) {
    112 						economicResource {...economicResource}
    113 					}
    114 				}
    115 			""", vars: %{"resource" => %{
    116 				"id" => old.id,
    117 				"note" => params["note"],
    118 				#"image" => params["image"],
    119 			}})
    120 
    121 		assert data["id"] == old.id
    122 		assert data["id"] == old.id
    123 		assert data["name"] == old.name
    124 		assert data["note"] == params["note"]
    125 		#assert data["image"] == params["image"]
    126 		assert data["trackingIdentifier"] == old.tracking_identifier
    127 		assert data["classifiedAs"] == old.classified_as
    128 		assert data["conformsTo"]["id"] == old.conforms_to_id
    129 		assert data["accountingQuantity"]["hasUnit"]["id"] == old.accounting_quantity_has_unit_id
    130 		assert data["accountingQuantity"]["hasNumericalValue"] == old.accounting_quantity_has_numerical_value
    131 		assert data["onhandQuantity"]["hasUnit"]["id"] == old.onhand_quantity_has_unit_id
    132 		assert data["onhandQuantity"]["hasNumericalValue"] == old.onhand_quantity_has_numerical_value
    133 		assert data["primaryAccountable"]["id"] == old.primary_accountable_id
    134 		assert data["custodian"]["id"] == old.custodian_id
    135 		assert data["stage"]["id"] == old.stage_id
    136 		assert data["state"]["id"] == old.state_id
    137 		assert data["currentLocation"]["id"] == old.current_location_id
    138 		assert data["lot"]["id"] == old.lot_id
    139 		assert data["containedIn"]["id"] == old.contained_in_id
    140 		assert data["unitOfEffort"]["id"] == old.unit_of_effort_id
    141 	end
    142 
    143 	@tag skip: "TODO: needs to deal with previous_event_id"
    144 	test "deleteEconomicResource()", %{inserted: %{id: id}} do
    145 		assert %{data: %{"deleteEconomicResource" => true}} =
    146 			run!("""
    147 				mutation ($id: ID!) {
    148 					deleteEconomicResource(id: $id)
    149 				}
    150 			""", vars: %{"id" => id})
    151 	end
    152 end
    153 end