3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 11:15:42 +00:00

Updated tests

This commit is contained in:
snipe
2026-08-05 14:57:27 +01:00
parent de2cdcb15b
commit 2ff8fc598e
3 changed files with 23 additions and 13 deletions

View File

@ -135,7 +135,11 @@ class UpdateAccessoryTest extends TestCase implements TestsFullMultipleCompanies
$this->assertEquals('A New Name', $accessory->name);
$this->assertEquals(10, $accessory->qty);
$this->assertEquals($supplierB->id, $accessory->supplier_id);
$this->assertEquals(199.99, $accessory->purchase_cost);
// purchase_cost is now create-only on the parent — the PATCH
// payload's 199.99 rides onto the OrderItem created by the
// qty-change adjustQuantity call (asserted in the dedicated
// qty test below) rather than overwriting the parent column.
$this->assertEquals(99.99, $accessory->purchase_cost);
$this->assertEquals('XYZ123', $accessory->model_number);
$this->assertEquals($categoryB->id, $accessory->category_id);
$this->assertEquals($companyB->id, $accessory->company_id);

View File

@ -87,12 +87,15 @@ class UpdateAccessoryTest extends TestCase
->create([
'min_amt' => 1,
'qty' => 5,
'purchase_cost' => 42.00,
]);
// qty is still ignored by the web edit form (flows through the
// adjust-quantity modal). order_number in the POST body silently
// drops because the parent column was renamed to legacy_order_number
// and taken out of fillable. supplier_id is editable again.
// qty, order_number, and purchase_cost are all create-only for
// accessories now. qty flows through the adjust-quantity modal
// instead; order_number and purchase_cost ride on OrderItems
// rather than the parent column. The edit form drops all three
// silently, so a POST body carrying them shouldn't overwrite
// the corresponding parent columns.
$this->actingAs(User::factory()->editAccessories()->create())
->put(route('accessories.update', $accessory), [
'redirect_option' => 'index',
@ -120,8 +123,8 @@ class UpdateAccessoryTest extends TestCase
'location_id' => $locationB->id,
'model_number' => 'changed 1234',
'purchase_date' => '2024-10-11',
'purchase_cost' => '83.52',
'qty' => '5', // unchanged from factory value; edit ignores qty
'purchase_cost' => '42.00', // unchanged from create; edit ignores purchase_cost
'qty' => '5', // unchanged from create; edit ignores qty
'min_amt' => '10',
'notes' => 'A new note',
]);

View File

@ -59,14 +59,16 @@ class UpdateConsumableTest extends TestCase
public function test_can_update_consumable()
{
$consumable = Consumable::factory()->create();
$consumable = Consumable::factory()->create(['purchase_cost' => 42.00]);
$originalQty = (int) $consumable->qty;
$originalPurchaseCost = $consumable->purchase_cost;
$newSupplier = Supplier::factory()->create();
// qty is still ignored by the web edit form (flows through the
// adjust-quantity modal). order_number in the POST body silently
// drops because the parent column was renamed to legacy_order_number
// and taken out of fillable. supplier_id is editable again.
// qty, order_number, and purchase_cost are all create-only on
// the parent now. qty routes through adjust-quantity;
// order_number and purchase_cost ride on OrderItems. The edit
// form drops all three silently, so a POST body carrying them
// shouldn't overwrite the corresponding parent columns.
$editable = [
'company_id' => Company::factory()->create()->id,
'name' => 'My Consumable',
@ -76,7 +78,6 @@ class UpdateConsumableTest extends TestCase
'model_number' => '8765',
'item_no' => '5678',
'purchase_date' => '2024-12-05',
'purchase_cost' => '89.45',
'min_amt' => '7',
'notes' => 'Some Notes',
];
@ -87,12 +88,14 @@ class UpdateConsumableTest extends TestCase
'category_type' => 'consumable',
'order_number' => 'ignored-908',
'qty' => '9999',
'purchase_cost' => '89.45', // dropped — see comment above
'supplier_id' => $newSupplier->id,
])
->assertRedirect(route('consumables.index'));
$this->assertDatabaseHas('consumables', $editable + [
'qty' => $originalQty,
'purchase_cost' => $originalPurchaseCost,
'supplier_id' => $newSupplier->id,
]);
}