gruene-seele/tests/Feature/IngredientOrderFieldsTest.php
Kevin Adametz 78679e0c55 Warenwirtschaft: AP-00 bis AP-08 + aktualisierter Entwicklungsplan
Umsetzung der Warenwirtschafts-/Produktmanagement-Erweiterung gemaess
Entwicklungsplan V4.0:

- AP-00: Regressionsbasis fuer 5.1-Features (ProductPhase51Test)
- AP-01: URL-Bugfixes B1/B2 (suppliers/packaging-items, breitere url-Spalten)
- AP-04/04.1: iPad-taugliche, vereinheitlichte Tabellen-Aktionen
- AP-05: Einstellungen "Allgemein" mit UST-Saetzen (tax_rates) und
  Lieferzeit-Vorlagen (delivery_times, inkl. Tage-Feld)
- AP-06: Lieferanten um Bestellweg, Bestell-Mail/-URL und Lieferzeit erweitert
- AP-07/07.1: INCI um Lieferanten-Mehrfachwahl, UST und Lieferzeit erweitert;
  Lieferanten-Detailansicht im Modal mit pflegbaren INCI-/Verpackungslisten
- AP-08: Einkauf um UST-Snapshot, Netto/Brutto-Automatik und Duplizieren erweitert

Entwicklungsplan aktualisiert: alle Klaerungspunkte (§5) vom Kunden beantwortet
und in die jeweiligen APs eingearbeitet (AP-02/03/09/13/15), neues AP-18
(Hinweise-Doku unter Einstellungen) ergaenzt. Naechster Schritt eindeutig
markiert: AP-09 (Produktion auf Hersteller-Rezeptur, kein Fallback, Warnung).
2026-06-02 16:30:42 +00:00

135 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Models\DeliveryTime;
use App\Models\Ingredient;
use App\Models\Supplier;
use App\Models\TaxRate;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
function ingredientOrderUser(int $adminLevel): User
{
$user = User::query()->create([
'email' => uniqid('ing_', true).'@test.example',
'password' => bcrypt('password'),
]);
$user->forceFill([
'admin' => $adminLevel,
'confirmed' => true,
'active' => true,
'wizard' => 100,
'blocked' => false,
])->save();
return $user->fresh();
}
function ingredientOrderSupplier(string $name): Supplier
{
return Supplier::factory()->create([
'name' => $name,
'active' => true,
]);
}
test('ingredient form shows suppliers, tax rates and delivery time templates', function () {
$supplier = ingredientOrderSupplier('Aktiv-Lieferant');
TaxRate::query()->create(['name' => 'Standard', 'percent' => 19, 'active' => true, 'pos' => 0]);
DeliveryTime::query()->create(['label' => '35 Werktage', 'days' => 5, 'active' => true, 'pos' => 0]);
DeliveryTime::query()->create(['label' => 'Inaktiv-Vorlage', 'active' => false, 'pos' => 1]);
$this->actingAs(ingredientOrderUser(7), 'user');
$this->get(route('admin_product_ingredient_edit', 'new'))
->assertSuccessful()
->assertSee('supplier_ids')
->assertSee('tax_rate_id')
->assertSee('Aktiv-Lieferant')
->assertSee('35 Werktage')
->assertSee('data-days="5"', false)
->assertDontSee('Inaktiv-Vorlage');
});
test('ingredient can be stored with tax rate, delivery time and suppliers', function () {
$taxRate = TaxRate::query()->create(['name' => 'Standard', 'percent' => 19, 'active' => true, 'pos' => 0]);
$supplierA = ingredientOrderSupplier('Lieferant A');
$supplierB = ingredientOrderSupplier('Lieferant B');
$this->actingAs(ingredientOrderUser(7), 'user');
$this->post(route('admin_product_ingredient_store'), [
'id' => 'new',
'name' => 'Sheabutter',
'active' => '1',
'tax_rate_id' => (string) $taxRate->id,
'delivery_time' => '35 Werktage',
'delivery_time_days' => '5',
'supplier_ids' => [(string) $supplierA->id, (string) $supplierB->id],
])->assertRedirect(route('admin_product_ingredients'));
$ingredient = Ingredient::query()->where('name', 'Sheabutter')->firstOrFail();
expect($ingredient->tax_rate_id)->toBe($taxRate->id)
->and($ingredient->delivery_time)->toBe('35 Werktage')
->and($ingredient->delivery_time_days)->toBe(5)
->and($ingredient->suppliers()->pluck('suppliers.id')->all())
->toEqualCanonicalizing([$supplierA->id, $supplierB->id]);
});
test('ingredient suppliers are synced on update', function () {
$supplierA = ingredientOrderSupplier('Lieferant A');
$supplierB = ingredientOrderSupplier('Lieferant B');
$ingredient = Ingredient::query()->create([
'name' => 'Lavendelöl',
'active' => true,
]);
$ingredient->suppliers()->sync([$supplierA->id]);
$this->actingAs(ingredientOrderUser(7), 'user');
$this->post(route('admin_product_ingredient_store'), [
'id' => (string) $ingredient->id,
'name' => 'Lavendelöl',
'active' => '1',
'supplier_ids' => [(string) $supplierB->id],
])->assertRedirect(route('admin_product_ingredients'));
expect($ingredient->fresh()->suppliers()->pluck('suppliers.id')->all())
->toEqualCanonicalizing([$supplierB->id]);
});
test('ingredient delivery time days must be an integer', function () {
$this->actingAs(ingredientOrderUser(7), 'user');
$this->post(route('admin_product_ingredient_store'), [
'id' => 'new',
'name' => 'Falsche-Tage',
'active' => '1',
'delivery_time_days' => 'viele',
])->assertSessionHasErrors('delivery_time_days');
});
test('ingredient tax rate must exist', function () {
$this->actingAs(ingredientOrderUser(7), 'user');
$this->post(route('admin_product_ingredient_store'), [
'id' => 'new',
'name' => 'Falscher-Steuersatz',
'active' => '1',
'tax_rate_id' => '999999',
])->assertSessionHasErrors('tax_rate_id');
});
test('ingredient name is required', function () {
$this->actingAs(ingredientOrderUser(7), 'user');
$this->post(route('admin_product_ingredient_store'), [
'id' => 'new',
'name' => '',
'active' => '1',
])->assertSessionHasErrors('name');
});