superuser()->create(); $supplier = Supplier::factory()->create(); $component = Component::factory() ->withInitialAcquisition($supplier, 89.00, '2026-06-01') ->create([ 'created_by' => $actor->id, 'company_id' => $actor->company_id, 'qty' => 12, ]); $line = OrderItem::where('item_type', Component::class) ->where('item_id', $component->id) ->firstOrFail(); $this->assertSame(12, (int) $line->qty); $this->assertEquals(89.00, (float) $line->price); $this->assertSame($actor->id, (int) $line->created_by); $order = Order::findOrFail($line->order_id); $this->assertSame($supplier->id, (int) $order->supplier_id); $this->assertSame($actor->company_id, $order->company_id); $this->assertSame('2026-06-01', $order->purchase_date->toDateString()); $this->assertSame($actor->id, (int) $order->created_by); } public function test_create_action_log_links_to_order_item_id(): void { $component = Component::factory()->create(['qty' => 4]); $line = OrderItem::where('item_type', Component::class) ->where('item_id', $component->id) ->firstOrFail(); $log = Actionlog::where('item_type', Component::class) ->where('item_id', $component->id) ->where('action_type', ActionType::Create->value) ->firstOrFail(); $this->assertSame($line->id, (int) $log->order_item_id); } }