zf

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

track_and_trace.test.exs (7009B)


      1 defmodule ZenflowsTest.VF.Process.TrackAndTrace do
      2 use ZenflowsTest.Help.EctoCase, async: true
      3 
      4 alias Zenflows.VF.{
      5 	EconomicEvent,
      6 	EconomicResource,
      7 	Process.Domain,
      8 }
      9 
     10 test "previous/2 works" do
     11 	agent = Factory.insert!(:agent)
     12 	unit = Factory.insert!(:unit)
     13 	amount = Factory.decimal()
     14 	proc = Factory.insert!(:process)
     15 
     16 	evt0 = EconomicEvent.Domain.create!(%{
     17 			action_id: "raise",
     18 			provider_id: agent.id,
     19 			receiver_id: agent.id,
     20 			resource_conforms_to_id: Factory.insert!(:resource_specification).id,
     21 			resource_quantity: %{
     22 				has_numerical_value: amount,
     23 				has_unit_id: unit.id,
     24 			},
     25 			has_point_in_time: Factory.now(),
     26 		}, %{name: Factory.str("name")})
     27 	res = EconomicResource.Domain.one!(evt0.resource_inventoried_as_id)
     28 	assert res.previous_event_id == evt0.id
     29 	assert evt0.previous_event_id == nil
     30 
     31 	evt1 = EconomicEvent.Domain.create!(%{
     32 		action_id: "raise",
     33 		provider_id: agent.id,
     34 		receiver_id: agent.id,
     35 		resource_inventoried_as_id: res.id,
     36 		resource_quantity: %{
     37 			has_numerical_value: amount,
     38 			has_unit_id: unit.id,
     39 		},
     40 		has_point_in_time: Factory.now(),
     41 	})
     42 	res = EconomicResource.Domain.one!(res.id)
     43 	assert res.previous_event_id == evt1.id
     44 	assert evt1.previous_event_id == evt0.id
     45 
     46 	evt2 = EconomicEvent.Domain.create!(%{
     47 		action_id: "lower",
     48 		provider_id: agent.id,
     49 		receiver_id: agent.id,
     50 		resource_inventoried_as_id: res.id,
     51 		resource_quantity: %{
     52 			has_numerical_value: amount,
     53 			has_unit_id: unit.id,
     54 		},
     55 		has_point_in_time: Factory.now(),
     56 	})
     57 	res = EconomicResource.Domain.one!(res.id)
     58 	assert res.previous_event_id == evt2.id
     59 	assert evt2.previous_event_id == evt1.id
     60 
     61 	evt3 = EconomicEvent.Domain.create!(%{
     62 		action_id: "produce",
     63 		output_of_id: Factory.insert!(:process).id,
     64 		provider_id: agent.id,
     65 		receiver_id: agent.id,
     66 		resource_inventoried_as_id: res.id,
     67 		resource_quantity: %{
     68 			has_numerical_value: amount,
     69 			has_unit_id: unit.id,
     70 		},
     71 		has_point_in_time: Factory.now(),
     72 	})
     73 	res = EconomicResource.Domain.one!(res.id)
     74 	assert res.previous_event_id == evt3.id
     75 	assert evt3.previous_event_id == evt2.id
     76 
     77 	evt4 = EconomicEvent.Domain.create!(%{
     78 		action_id: "consume",
     79 		input_of_id: proc.id,
     80 		provider_id: agent.id,
     81 		receiver_id: agent.id,
     82 		resource_inventoried_as_id: res.id,
     83 		resource_quantity: %{
     84 			has_numerical_value: amount,
     85 			has_unit_id: unit.id,
     86 		},
     87 		has_point_in_time: Factory.now(),
     88 	})
     89 	res = EconomicResource.Domain.one!(res.id)
     90 	assert res.previous_event_id == evt4.id
     91 	assert evt4.previous_event_id == evt3.id
     92 
     93 	evt5 = EconomicEvent.Domain.create!(%{
     94 		action_id: "use",
     95 		input_of_id: proc.id,
     96 		provider_id: agent.id,
     97 		receiver_id: agent.id,
     98 		resource_inventoried_as_id: res.id,
     99 		resource_quantity: %{
    100 			has_numerical_value: amount,
    101 			has_unit_id: unit.id,
    102 		},
    103 		effort_quantity: %{
    104 			has_numerical_value: Factory.decimal(),
    105 			has_unit_id: Factory.insert!(:unit).id,
    106 		},
    107 		has_point_in_time: Factory.now(),
    108 	})
    109 	res = EconomicResource.Domain.one!(res.id)
    110 	assert res.previous_event_id == evt5.id
    111 	assert evt5.previous_event_id == evt4.id
    112 
    113 	evt6 = EconomicEvent.Domain.create!(%{
    114 		action_id: "cite",
    115 		input_of_id: proc.id,
    116 		provider_id: agent.id,
    117 		receiver_id: agent.id,
    118 		resource_inventoried_as_id: res.id,
    119 		resource_quantity: %{
    120 			has_numerical_value: amount,
    121 			has_unit_id: unit.id,
    122 		},
    123 		has_point_in_time: Factory.now(),
    124 	})
    125 	res = EconomicResource.Domain.one!(res.id)
    126 	assert res.previous_event_id == evt6.id
    127 	assert evt6.previous_event_id == evt5.id
    128 
    129 	evt7 = EconomicEvent.Domain.create!(%{
    130 		action_id: "pickup",
    131 		input_of_id: proc.id,
    132 		provider_id: agent.id,
    133 		receiver_id: agent.id,
    134 		resource_inventoried_as_id: res.id,
    135 		resource_quantity: %{
    136 			has_numerical_value: amount,
    137 			has_unit_id: unit.id,
    138 		},
    139 		has_point_in_time: Factory.now(),
    140 	})
    141 	res = EconomicResource.Domain.one!(res.id)
    142 	assert res.previous_event_id == evt7.id
    143 	assert evt7.previous_event_id == evt6.id
    144 
    145 	evt8 = EconomicEvent.Domain.create!(%{
    146 		action_id: "dropoff",
    147 		output_of_id: proc.id,
    148 		provider_id: agent.id,
    149 		receiver_id: agent.id,
    150 		resource_inventoried_as_id: res.id,
    151 		resource_quantity: %{
    152 			has_numerical_value: amount,
    153 			has_unit_id: unit.id,
    154 		},
    155 		has_point_in_time: Factory.now(),
    156 	})
    157 	res = EconomicResource.Domain.one!(res.id)
    158 	assert res.previous_event_id == evt8.id
    159 	assert evt8.previous_event_id == evt7.id
    160 
    161 	evt9 = EconomicEvent.Domain.create!(%{
    162 		action_id: "accept",
    163 		input_of_id: proc.id,
    164 		provider_id: agent.id,
    165 		receiver_id: agent.id,
    166 		resource_inventoried_as_id: res.id,
    167 		resource_quantity: %{
    168 			has_numerical_value: amount,
    169 			has_unit_id: unit.id,
    170 		},
    171 		has_point_in_time: Factory.now(),
    172 	})
    173 	res = EconomicResource.Domain.one!(res.id)
    174 	assert res.previous_event_id == evt9.id
    175 	assert evt9.previous_event_id == evt8.id
    176 
    177 	evt10 = EconomicEvent.Domain.create!(%{
    178 		action_id: "modify",
    179 		output_of_id: proc.id,
    180 		provider_id: agent.id,
    181 		receiver_id: agent.id,
    182 		resource_inventoried_as_id: res.id,
    183 		resource_quantity: %{
    184 			has_numerical_value: amount,
    185 			has_unit_id: unit.id,
    186 		},
    187 		has_point_in_time: Factory.now(),
    188 	})
    189 	res = EconomicResource.Domain.one!(res.id)
    190 	assert res.previous_event_id == evt10.id
    191 	assert evt10.previous_event_id == evt9.id
    192 
    193 	evt11 = EconomicEvent.Domain.create!(%{
    194 		action_id: "transferCustody",
    195 		provider_id: agent.id,
    196 		receiver_id: agent.id,
    197 		resource_inventoried_as_id: res.id,
    198 		resource_quantity: %{
    199 			has_numerical_value: amount,
    200 			has_unit_id: unit.id,
    201 		},
    202 		has_point_in_time: Factory.now(),
    203 	})
    204 	res = EconomicResource.Domain.one!(res.id)
    205 	assert res.previous_event_id == evt11.id
    206 	assert evt11.previous_event_id == evt10.id
    207 
    208 	evt12 = EconomicEvent.Domain.create!(%{
    209 		action_id: "transferAllRights",
    210 		provider_id: agent.id,
    211 		receiver_id: agent.id,
    212 		resource_inventoried_as_id: res.id,
    213 		resource_quantity: %{
    214 			has_numerical_value: amount,
    215 			has_unit_id: unit.id,
    216 		},
    217 		has_point_in_time: Factory.now(),
    218 	})
    219 	res = EconomicResource.Domain.one!(res.id)
    220 	assert res.previous_event_id == evt12.id
    221 	assert evt12.previous_event_id == evt11.id
    222 
    223 	evt13 = EconomicEvent.Domain.create!(%{
    224 		action_id: "transfer",
    225 		provider_id: agent.id,
    226 		receiver_id: agent.id,
    227 		resource_inventoried_as_id: res.id,
    228 		resource_quantity: %{
    229 			has_numerical_value: amount,
    230 			has_unit_id: unit.id,
    231 		},
    232 		has_point_in_time: Factory.now(),
    233 	})
    234 	res = EconomicResource.Domain.one!(res.id)
    235 	assert res.previous_event_id == evt13.id
    236 	assert evt13.previous_event_id == evt12.id
    237 
    238 	evt14 = EconomicEvent.Domain.create!(%{
    239 		action_id: "move",
    240 		provider_id: agent.id,
    241 		receiver_id: agent.id,
    242 		resource_inventoried_as_id: res.id,
    243 		resource_quantity: %{
    244 			has_numerical_value: amount,
    245 			has_unit_id: unit.id,
    246 		},
    247 		has_point_in_time: Factory.now(),
    248 	})
    249 	res = EconomicResource.Domain.one!(res.id)
    250 	assert res.previous_event_id == evt14.id
    251 	assert evt14.previous_event_id == evt13.id
    252 
    253 	evts = Domain.previous(proc)
    254 	left = Enum.map(evts, & &1.id)
    255 	right = Enum.map([evt9, evt7, evt6, evt5, evt4], & &1.id)
    256 	assert left == right
    257 end
    258 end