track_and_trace.test.exs (21346B)
1 defmodule ZenflowsTest.VF.EconomicResource.TrackAndTrace do 2 use ZenflowsTest.Help.EctoCase, async: true 3 4 alias Zenflows.VF.{ 5 EconomicEvent, 6 EconomicResource, 7 EconomicResource.Domain, 8 Organization, 9 Process, 10 ProcessSpecification, 11 ResourceSpecification, 12 Unit, 13 } 14 15 test "previous/2 works" do 16 agent = Factory.insert!(:agent) 17 unit = Factory.insert!(:unit) 18 amount = Factory.decimal() 19 20 evt0 = EconomicEvent.Domain.create!(%{ 21 action_id: "raise", 22 provider_id: agent.id, 23 receiver_id: agent.id, 24 resource_conforms_to_id: Factory.insert!(:resource_specification).id, 25 resource_quantity: %{ 26 has_numerical_value: amount, 27 has_unit_id: unit.id, 28 }, 29 has_point_in_time: Factory.now(), 30 }, %{name: Factory.str("name")}) 31 res = Domain.one!(evt0.resource_inventoried_as_id) 32 assert res.previous_event_id == evt0.id 33 assert evt0.previous_event_id == nil 34 35 evt1 = EconomicEvent.Domain.create!(%{ 36 action_id: "raise", 37 provider_id: agent.id, 38 receiver_id: agent.id, 39 resource_inventoried_as_id: res.id, 40 resource_quantity: %{ 41 has_numerical_value: amount, 42 has_unit_id: unit.id, 43 }, 44 has_point_in_time: Factory.now(), 45 }) 46 res = Domain.one!(res.id) 47 assert res.previous_event_id == evt1.id 48 assert evt1.previous_event_id == evt0.id 49 50 evt2 = EconomicEvent.Domain.create!(%{ 51 action_id: "lower", 52 provider_id: agent.id, 53 receiver_id: agent.id, 54 resource_inventoried_as_id: res.id, 55 resource_quantity: %{ 56 has_numerical_value: amount, 57 has_unit_id: unit.id, 58 }, 59 has_point_in_time: Factory.now(), 60 }) 61 res = Domain.one!(res.id) 62 assert res.previous_event_id == evt2.id 63 assert evt2.previous_event_id == evt1.id 64 65 evt3 = EconomicEvent.Domain.create!(%{ 66 action_id: "produce", 67 output_of_id: Factory.insert!(:process).id, 68 provider_id: agent.id, 69 receiver_id: agent.id, 70 resource_inventoried_as_id: res.id, 71 resource_quantity: %{ 72 has_numerical_value: amount, 73 has_unit_id: unit.id, 74 }, 75 has_point_in_time: Factory.now(), 76 }) 77 res = Domain.one!(res.id) 78 assert res.previous_event_id == evt3.id 79 assert evt3.previous_event_id == evt2.id 80 81 evt4 = EconomicEvent.Domain.create!(%{ 82 action_id: "consume", 83 input_of_id: Factory.insert!(:process).id, 84 provider_id: agent.id, 85 receiver_id: agent.id, 86 resource_inventoried_as_id: res.id, 87 resource_quantity: %{ 88 has_numerical_value: amount, 89 has_unit_id: res.onhand_quantity_has_unit_id, 90 }, 91 has_point_in_time: Factory.now(), 92 }) 93 res = Domain.one!(res.id) 94 assert res.previous_event_id == evt4.id 95 assert evt4.previous_event_id == evt3.id 96 97 evt5 = EconomicEvent.Domain.create!(%{ 98 action_id: "use", 99 input_of_id: Factory.insert!(:process).id, 100 provider_id: agent.id, 101 receiver_id: agent.id, 102 resource_inventoried_as_id: res.id, 103 resource_quantity: %{ 104 has_numerical_value: amount, 105 has_unit_id: unit.id, 106 }, 107 effort_quantity: %{ 108 has_numerical_value: Factory.decimal(), 109 has_unit_id: Factory.insert!(:unit).id, 110 }, 111 has_point_in_time: Factory.now(), 112 }) 113 res = Domain.one!(res.id) 114 assert res.previous_event_id == evt5.id 115 assert evt5.previous_event_id == evt4.id 116 117 evt6 = EconomicEvent.Domain.create!(%{ 118 action_id: "cite", 119 input_of_id: Factory.insert!(:process).id, 120 provider_id: agent.id, 121 receiver_id: agent.id, 122 resource_inventoried_as_id: res.id, 123 resource_quantity: %{ 124 has_numerical_value: amount, 125 has_unit_id: unit.id, 126 }, 127 has_point_in_time: Factory.now(), 128 }) 129 res = Domain.one!(res.id) 130 assert res.previous_event_id == evt6.id 131 assert evt6.previous_event_id == evt5.id 132 133 proc = Factory.insert!(:process) 134 evt7 = EconomicEvent.Domain.create!(%{ 135 action_id: "pickup", 136 input_of_id: proc.id, 137 provider_id: agent.id, 138 receiver_id: agent.id, 139 resource_inventoried_as_id: res.id, 140 resource_quantity: %{ 141 has_numerical_value: amount, 142 has_unit_id: unit.id, 143 }, 144 has_point_in_time: Factory.now(), 145 }) 146 res = Domain.one!(res.id) 147 assert res.previous_event_id == evt7.id 148 assert evt7.previous_event_id == evt6.id 149 150 evt8 = EconomicEvent.Domain.create!(%{ 151 action_id: "dropoff", 152 output_of_id: proc.id, 153 provider_id: agent.id, 154 receiver_id: agent.id, 155 resource_inventoried_as_id: res.id, 156 resource_quantity: %{ 157 has_numerical_value: amount, 158 has_unit_id: unit.id, 159 }, 160 has_point_in_time: Factory.now(), 161 }) 162 res = Domain.one!(res.id) 163 assert res.previous_event_id == evt8.id 164 assert evt8.previous_event_id == evt7.id 165 166 proc = Factory.insert!(:process) 167 evt9 = EconomicEvent.Domain.create!(%{ 168 action_id: "accept", 169 input_of_id: proc.id, 170 provider_id: agent.id, 171 receiver_id: agent.id, 172 resource_inventoried_as_id: res.id, 173 resource_quantity: %{ 174 has_numerical_value: amount, 175 has_unit_id: unit.id, 176 }, 177 has_point_in_time: Factory.now(), 178 }) 179 res = Domain.one!(res.id) 180 assert res.previous_event_id == evt9.id 181 assert evt9.previous_event_id == evt8.id 182 183 evt10 = EconomicEvent.Domain.create!(%{ 184 action_id: "modify", 185 output_of_id: proc.id, 186 provider_id: agent.id, 187 receiver_id: agent.id, 188 resource_inventoried_as_id: res.id, 189 resource_quantity: %{ 190 has_numerical_value: amount, 191 has_unit_id: unit.id, 192 }, 193 has_point_in_time: Factory.now(), 194 }) 195 res = Domain.one!(res.id) 196 assert res.previous_event_id == evt10.id 197 assert evt10.previous_event_id == evt9.id 198 199 evt11 = EconomicEvent.Domain.create!(%{ 200 action_id: "transferCustody", 201 provider_id: agent.id, 202 receiver_id: agent.id, 203 resource_inventoried_as_id: res.id, 204 resource_quantity: %{ 205 has_numerical_value: amount, 206 has_unit_id: unit.id, 207 }, 208 has_point_in_time: Factory.now(), 209 }) 210 res = Domain.one!(res.id) 211 assert res.previous_event_id == evt11.id 212 assert evt11.previous_event_id == evt10.id 213 214 evt12 = EconomicEvent.Domain.create!(%{ 215 action_id: "transferAllRights", 216 provider_id: agent.id, 217 receiver_id: agent.id, 218 resource_inventoried_as_id: res.id, 219 resource_quantity: %{ 220 has_numerical_value: amount, 221 has_unit_id: unit.id, 222 }, 223 has_point_in_time: Factory.now(), 224 }) 225 res = Domain.one!(res.id) 226 assert res.previous_event_id == evt12.id 227 assert evt12.previous_event_id == evt11.id 228 229 evt13 = EconomicEvent.Domain.create!(%{ 230 action_id: "transfer", 231 provider_id: agent.id, 232 receiver_id: agent.id, 233 resource_inventoried_as_id: res.id, 234 resource_quantity: %{ 235 has_numerical_value: amount, 236 has_unit_id: unit.id, 237 }, 238 has_point_in_time: Factory.now(), 239 }) 240 res = Domain.one!(res.id) 241 assert res.previous_event_id == evt13.id 242 assert evt13.previous_event_id == evt12.id 243 244 evt14 = EconomicEvent.Domain.create!(%{ 245 action_id: "move", 246 provider_id: agent.id, 247 receiver_id: agent.id, 248 resource_inventoried_as_id: res.id, 249 resource_quantity: %{ 250 has_numerical_value: amount, 251 has_unit_id: unit.id, 252 }, 253 has_point_in_time: Factory.now(), 254 }) 255 res = Domain.one!(res.id) 256 assert res.previous_event_id == evt14.id 257 assert evt14.previous_event_id == evt13.id 258 259 evts = Domain.previous(res) 260 left = Enum.map(evts, & &1.id) 261 right = Enum.map([evt0, evt1, evt2, evt3, evt8, evt10], & &1.id) 262 #assert left == right 263 end 264 265 defp assert_trace(left, right) do 266 if length(left) != length(right), do: throw "lengths must be the same" 267 Enum.zip(left, right) 268 |> Enum.with_index(fn {l, r}, ind -> 269 if l.__struct__ != r.__struct__ and l.id != r.id, 270 do: flunk(""" 271 At index #{ind}: 272 273 #{inspect(l, pretty: true)} 274 275 DOES NOT MATCH 276 277 #{inspect(r, pretty: true)} 278 """) 279 end) 280 end 281 282 test "trace/2" do 283 spec_cotton = ResourceSpecification.Domain.create!(%{name: "cotton"}) 284 spec_water = ResourceSpecification.Domain.create!(%{name: "water"}) 285 spec_gown = ResourceSpecification.Domain.create!(%{name: "medical gown"}) 286 spec_surgery = ResourceSpecification.Domain.create!(%{name: "action of surgery"}) 287 spec_transport_service = ResourceSpecification.Domain.create!(%{name: "transport service"}) 288 spec_sewing_machine = ResourceSpecification.Domain.create!(%{name: "sewing machine"}) 289 spec_shirt = ResourceSpecification.Domain.create!(%{name: "shirt"}) 290 spec_shirt_design = ResourceSpecification.Domain.create!(%{name: "shirt design"}) 291 spec_shirt_design_work = ResourceSpecification.Domain.create!(%{name: "shirt design work"}) 292 293 proc_spec_clean = ProcessSpecification.Domain.create!(%{name: "gown after cleaned"}) 294 proc_spec_surgery = ProcessSpecification.Domain.create!(%{name: "gown after used in surgery"}) 295 296 unit_one = Unit.Domain.create!(%{label: "one", symbol: "one"}) 297 unit_kg = Unit.Domain.create!(%{label: "kilogram", symbol: "kg"}) 298 unit_lt = Unit.Domain.create!(%{label: "liter", symbol: "l"}) 299 unit_hour = Unit.Domain.create!(%{label: "hour", symbol: "h"}) 300 301 agent_alice = Organization.Domain.create!(%{name: "alice"}) 302 agent_bob = Organization.Domain.create!(%{name: "bob"}) 303 agent_carol = Organization.Domain.create!(%{name: "carol"}) 304 305 evt_raise = EconomicEvent.Domain.create!(%{ 306 action_id: "raise", 307 provider_id: agent_alice.id, 308 receiver_id: agent_alice.id, 309 resource_conforms_to_id: spec_water.id, 310 resource_quantity: %{ 311 has_numerical_value: "100", 312 has_unit_id: unit_lt.id, 313 }, 314 has_point_in_time: DateTime.utc_now(), 315 }, %{name: "water"}) 316 res_water = EconomicResource.Domain.one!(evt_raise.resource_inventoried_as_id) 317 318 evt_raise = EconomicEvent.Domain.create!(%{ 319 action_id: "raise", 320 provider_id: agent_alice.id, 321 receiver_id: agent_alice.id, 322 resource_conforms_to_id: spec_cotton.id, 323 resource_quantity: %{ 324 has_numerical_value: "100", 325 has_unit_id: unit_kg.id, 326 }, 327 has_point_in_time: DateTime.utc_now(), 328 }, %{name: "cotton"}) 329 res_cotton = EconomicResource.Domain.one!(evt_raise.resource_inventoried_as_id) 330 331 proc = Process.Domain.create!(%{name: "create gowns"}) 332 evt_consume = EconomicEvent.Domain.create!(%{ 333 action_id: "consume", 334 input_of_id: proc.id, 335 provider_id: agent_alice.id, 336 receiver_id: agent_alice.id, 337 resource_inventoried_as_id: res_cotton.id, 338 resource_quantity: %{ 339 has_numerical_value: "25", 340 has_unit_id: unit_kg.id, 341 }, 342 has_point_in_time: DateTime.utc_now(), 343 }) 344 evt_produce = EconomicEvent.Domain.create!(%{ 345 action_id: "produce", 346 output_of_id: proc.id, 347 provider_id: agent_alice.id, 348 receiver_id: agent_alice.id, 349 resource_conforms_to_id: spec_gown.id, 350 resource_quantity: %{ 351 has_numerical_value: "1", 352 has_unit_id: unit_one.id, 353 }, 354 has_point_in_time: DateTime.utc_now(), 355 }, %{name: "gown"}) 356 res_gown = EconomicResource.Domain.one!(evt_produce.resource_inventoried_as_id) 357 358 proc = Process.Domain.create!(%{ 359 name: "cleaning the gowns", 360 based_on_id: proc_spec_clean.id, 361 }) 362 evt_accept = EconomicEvent.Domain.create!(%{ 363 action_id: "accept", 364 input_of_id: proc.id, 365 provider_id: agent_alice.id, 366 receiver_id: agent_alice.id, 367 resource_inventoried_as_id: res_gown.id, 368 resource_quantity: %{ 369 has_numerical_value: "1", 370 has_unit_id: unit_one.id, 371 }, 372 has_point_in_time: DateTime.utc_now(), 373 }) 374 evt_modify = EconomicEvent.Domain.create!(%{ 375 action_id: "modify", 376 output_of_id: proc.id, 377 provider_id: agent_alice.id, 378 receiver_id: agent_alice.id, 379 resource_inventoried_as_id: res_gown.id, 380 resource_quantity: %{ 381 has_numerical_value: "1", 382 has_unit_id: unit_one.id, 383 }, 384 has_point_in_time: DateTime.utc_now(), 385 }) 386 evt_consume = EconomicEvent.Domain.create!(%{ 387 action_id: "consume", 388 input_of_id: proc.id, 389 provider_id: agent_alice.id, 390 receiver_id: agent_alice.id, 391 resource_inventoried_as_id: res_water.id, 392 resource_quantity: %{ 393 has_numerical_value: "25", 394 has_unit_id: unit_lt.id, 395 }, 396 has_point_in_time: DateTime.utc_now(), 397 }) 398 399 evt_transfer = EconomicEvent.Domain.create!(%{ 400 action_id: "transferCustody", 401 provider_id: agent_alice.id, 402 receiver_id: agent_bob.id, 403 resource_inventoried_as_id: res_gown.id, 404 to_resource_inventoried_as_id: res_gown.id, 405 resource_quantity: %{ 406 has_numerical_value: "1", 407 has_unit_id: unit_one.id, 408 }, 409 has_point_in_time: DateTime.utc_now(), 410 }) 411 412 proc = Process.Domain.create!(%{ 413 name: "doing the surgery", 414 based_on_id: proc_spec_surgery.id, 415 }) 416 evt_accept = EconomicEvent.Domain.create!(%{ 417 action_id: "accept", 418 input_of_id: proc.id, 419 provider_id: agent_bob.id, 420 receiver_id: agent_bob.id, 421 resource_inventoried_as_id: res_gown.id, 422 resource_quantity: %{ 423 has_numerical_value: "1", 424 has_unit_id: unit_one.id, 425 }, 426 has_point_in_time: DateTime.utc_now(), 427 }) 428 evt_modify = EconomicEvent.Domain.create!(%{ 429 action_id: "modify", 430 output_of_id: proc.id, 431 provider_id: agent_bob.id, 432 receiver_id: agent_bob.id, 433 resource_inventoried_as_id: res_gown.id, 434 resource_quantity: %{ 435 has_numerical_value: "1", 436 has_unit_id: unit_one.id, 437 }, 438 has_point_in_time: DateTime.utc_now(), 439 }) 440 evt_work = EconomicEvent.Domain.create!(%{ 441 action_id: "work", 442 input_of_id: proc.id, 443 provider_id: agent_bob.id, 444 receiver_id: agent_bob.id, 445 resource_conforms_to_id: spec_surgery.id, 446 effort_quantity: %{ 447 has_numerical_value: "5", 448 has_unit_id: unit_hour.id, 449 }, 450 has_point_in_time: DateTime.utc_now(), 451 }) 452 453 evt_transfer = EconomicEvent.Domain.create!(%{ 454 action_id: "transferCustody", 455 provider_id: agent_bob.id, 456 receiver_id: agent_alice.id, 457 resource_inventoried_as_id: res_gown.id, 458 to_resource_inventoried_as_id: res_gown.id, 459 resource_quantity: %{ 460 has_numerical_value: "1", 461 has_unit_id: unit_one.id, 462 }, 463 has_point_in_time: DateTime.utc_now(), 464 }) 465 466 proc = Process.Domain.create!(%{ 467 name: "cleaning the gowns again", 468 based_on_id: proc_spec_clean.id, 469 }) 470 evt_accept = EconomicEvent.Domain.create!(%{ 471 action_id: "accept", 472 input_of_id: proc.id, 473 provider_id: agent_alice.id, 474 receiver_id: agent_alice.id, 475 resource_inventoried_as_id: res_gown.id, 476 resource_quantity: %{ 477 has_numerical_value: "1", 478 has_unit_id: unit_one.id, 479 }, 480 has_point_in_time: DateTime.utc_now(), 481 }) 482 evt_modify = EconomicEvent.Domain.create!(%{ 483 action_id: "modify", 484 output_of_id: proc.id, 485 provider_id: agent_alice.id, 486 receiver_id: agent_alice.id, 487 resource_inventoried_as_id: res_gown.id, 488 resource_quantity: %{ 489 has_numerical_value: "1", 490 has_unit_id: unit_one.id, 491 }, 492 has_point_in_time: DateTime.utc_now(), 493 }) 494 evt_consume = EconomicEvent.Domain.create!(%{ 495 action_id: "consume", 496 input_of_id: proc.id, 497 provider_id: agent_alice.id, 498 receiver_id: agent_alice.id, 499 resource_inventoried_as_id: res_water.id, 500 resource_quantity: %{ 501 has_numerical_value: "25", 502 has_unit_id: unit_lt.id, 503 }, 504 has_point_in_time: DateTime.utc_now(), 505 }) 506 507 evt_raise = EconomicEvent.Domain.create!(%{ 508 action_id: "raise", 509 provider_id: agent_carol.id, 510 receiver_id: agent_carol.id, 511 resource_conforms_to_id: spec_sewing_machine.id, 512 resource_quantity: %{ 513 has_numerical_value: "1", 514 has_unit_id: unit_one.id, 515 }, 516 has_point_in_time: DateTime.utc_now(), 517 }, %{name: "sewing machine"}) 518 res_sewing_machine = EconomicResource.Domain.one!(evt_raise.resource_inventoried_as_id) 519 520 evt_transfer = EconomicEvent.Domain.create!(%{ 521 action_id: "transfer", 522 provider_id: agent_alice.id, 523 receiver_id: agent_carol.id, 524 resource_inventoried_as_id: res_cotton.id, 525 resource_quantity: %{ 526 has_numerical_value: "10", 527 has_unit_id: unit_kg.id, 528 }, 529 has_point_in_time: DateTime.utc_now(), 530 }) 531 res_transferred_cotton = EconomicResource.Domain.one!(evt_transfer.to_resource_inventoried_as_id) 532 533 proc = Process.Domain.create!(%{name: "create shirt design"}) 534 evt_work = EconomicEvent.Domain.create!(%{ 535 action_id: "work", 536 input_of_id: proc.id, 537 provider_id: agent_carol.id, 538 receiver_id: agent_carol.id, 539 resource_conforms_to_id: spec_shirt_design_work.id, 540 effort_quantity: %{ 541 has_numerical_value: "4", 542 has_unit_id: unit_hour.id, 543 }, 544 has_point_in_time: DateTime.utc_now(), 545 }) 546 evt_produce = EconomicEvent.Domain.create!(%{ 547 action_id: "produce", 548 output_of_id: proc.id, 549 provider_id: agent_carol.id, 550 receiver_id: agent_carol.id, 551 resource_conforms_to_id: spec_shirt_design.id, 552 resource_quantity: %{ 553 has_numerical_value: "1", 554 has_unit_id: unit_one.id, 555 }, 556 has_point_in_time: DateTime.utc_now(), 557 }, %{name: "shirt design"}) 558 res_shirt_design = EconomicResource.Domain.one!(evt_produce.resource_inventoried_as_id) 559 560 proc = Process.Domain.create!(%{name: "create shirt"}) 561 evt_consume = EconomicEvent.Domain.create!(%{ 562 action_id: "consume", 563 input_of_id: proc.id, 564 provider_id: agent_carol.id, 565 receiver_id: agent_carol.id, 566 resource_inventoried_as_id: res_transferred_cotton.id, 567 resource_quantity: %{ 568 has_numerical_value: "5", 569 has_unit_id: unit_kg.id, 570 }, 571 has_point_in_time: DateTime.utc_now(), 572 }) 573 evt_cite = EconomicEvent.Domain.create!(%{ 574 action_id: "cite", 575 input_of_id: proc.id, 576 provider_id: agent_carol.id, 577 receiver_id: agent_carol.id, 578 resource_inventoried_as_id: res_shirt_design.id, 579 resource_quantity: %{ 580 has_numerical_value: "1", 581 has_unit_id: unit_one.id, 582 }, 583 has_point_in_time: DateTime.utc_now(), 584 }) 585 evt_use = EconomicEvent.Domain.create!(%{ 586 action_id: "use", 587 input_of_id: proc.id, 588 provider_id: agent_carol.id, 589 receiver_id: agent_carol.id, 590 resource_inventoried_as_id: res_sewing_machine.id, 591 resource_quantity: %{ 592 has_numerical_value: "1", 593 has_unit_id: unit_one.id, 594 }, 595 effort_quantity: %{ 596 has_numerical_value: "3", 597 has_unit_id: unit_hour.id, 598 }, 599 has_point_in_time: DateTime.utc_now(), 600 }) 601 evt_produce = EconomicEvent.Domain.create!(%{ 602 action_id: "produce", 603 output_of_id: proc.id, 604 provider_id: agent_carol.id, 605 receiver_id: agent_carol.id, 606 resource_conforms_to_id: spec_shirt.id, 607 resource_quantity: %{ 608 has_numerical_value: "2", 609 has_unit_id: unit_one.id, 610 }, 611 has_point_in_time: DateTime.utc_now(), 612 }, %{name: "shirt"}) 613 res_shirt = EconomicResource.Domain.one!(evt_produce.resource_inventoried_as_id) 614 615 evt_lower = EconomicEvent.Domain.create!(%{ 616 action_id: "lower", 617 provider_id: agent_carol.id, 618 receiver_id: agent_carol.id, 619 resource_inventoried_as_id: res_transferred_cotton.id, 620 resource_quantity: %{ 621 has_numerical_value: "2", 622 has_unit_id: unit_kg.id, 623 }, 624 has_point_in_time: DateTime.utc_now(), 625 }) 626 627 evt_move = EconomicEvent.Domain.create!(%{ 628 action_id: "move", 629 provider_id: agent_carol.id, 630 receiver_id: agent_carol.id, 631 resource_inventoried_as_id: res_shirt.id, 632 resource_quantity: %{ 633 has_numerical_value: "1", 634 has_unit_id: unit_one.id, 635 }, 636 has_point_in_time: DateTime.utc_now(), 637 }) 638 res_moved_shirt = EconomicResource.Domain.one!(evt_move.to_resource_inventoried_as_id) 639 640 proc = Process.Domain.create!(%{name: "transport shirt"}) 641 evt_pickup = EconomicEvent.Domain.create!(%{ 642 action_id: "pickup", 643 input_of_id: proc.id, 644 provider_id: agent_carol.id, 645 receiver_id: agent_carol.id, 646 resource_inventoried_as_id: res_moved_shirt.id, 647 resource_quantity: %{ 648 has_numerical_value: "1", 649 has_unit_id: unit_one.id, 650 }, 651 has_point_in_time: DateTime.utc_now(), 652 }) 653 evt_dropoff = EconomicEvent.Domain.create!(%{ 654 action_id: "dropoff", 655 output_of_id: proc.id, 656 provider_id: agent_carol.id, 657 receiver_id: agent_carol.id, 658 resource_inventoried_as_id: res_moved_shirt.id, 659 resource_quantity: %{ 660 has_numerical_value: "1", 661 has_unit_id: unit_one.id, 662 }, 663 has_point_in_time: DateTime.utc_now(), 664 }) 665 evt_deliver_service = EconomicEvent.Domain.create!(%{ 666 action_id: "deliverService", 667 output_of_id: proc.id, 668 provider_id: agent_carol.id, 669 receiver_id: agent_alice.id, 670 resource_conforms_to_id: spec_transport_service.id, 671 resource_quantity: %{ 672 has_numerical_value: "1", 673 has_unit_id: unit_one.id, 674 }, 675 has_point_in_time: DateTime.utc_now(), 676 }) 677 evt_transfer = EconomicEvent.Domain.create!(%{ 678 action_id: "transfer", 679 provider_id: agent_carol.id, 680 receiver_id: agent_alice.id, 681 resource_inventoried_as_id: res_moved_shirt.id, 682 resource_quantity: %{ 683 has_numerical_value: "1", 684 has_unit_id: unit_one.id, 685 }, 686 triggered_by_id: evt_dropoff.id, 687 has_point_in_time: DateTime.utc_now(), 688 }) 689 res_transferred_shirt = EconomicResource.Domain.one!(evt_transfer.to_resource_inventoried_as_id) 690 691 proc = Process.Domain.create!(%{name: "clean gown and shirt", based_on_id: proc_spec_clean.id}) 692 evt_accept_gown = EconomicEvent.Domain.create!(%{ 693 action_id: "accept", 694 input_of_id: proc.id, 695 provider_id: agent_alice.id, 696 receiver_id: agent_alice.id, 697 resource_inventoried_as_id: res_gown.id, 698 resource_quantity: %{ 699 has_numerical_value: "1", 700 has_unit_id: unit_one.id, 701 }, 702 has_point_in_time: DateTime.utc_now(), 703 }) 704 evt_accept_shirt = EconomicEvent.Domain.create!(%{ 705 action_id: "accept", 706 input_of_id: proc.id, 707 provider_id: agent_alice.id, 708 receiver_id: agent_alice.id, 709 resource_inventoried_as_id: res_transferred_shirt.id, 710 resource_quantity: %{ 711 has_numerical_value: "1", 712 has_unit_id: unit_one.id, 713 }, 714 has_point_in_time: DateTime.utc_now(), 715 }) 716 evt_modify_gown = EconomicEvent.Domain.create!(%{ 717 action_id: "modify", 718 output_of_id: proc.id, 719 provider_id: agent_alice.id, 720 receiver_id: agent_alice.id, 721 resource_inventoried_as_id: res_gown.id, 722 resource_quantity: %{ 723 has_numerical_value: "1", 724 has_unit_id: unit_one.id, 725 }, 726 has_point_in_time: DateTime.utc_now(), 727 }) 728 evt_modify_shirt = EconomicEvent.Domain.create!(%{ 729 action_id: "modify", 730 output_of_id: proc.id, 731 provider_id: agent_alice.id, 732 receiver_id: agent_alice.id, 733 resource_inventoried_as_id: res_transferred_shirt.id, 734 resource_quantity: %{ 735 has_numerical_value: "1", 736 has_unit_id: unit_one.id, 737 }, 738 has_point_in_time: DateTime.utc_now(), 739 }) 740 end 741 end