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).
114 lines
4 KiB
PHP
114 lines
4 KiB
PHP
<?php
|
|
|
|
use App\Models\Ingredient;
|
|
use App\Models\PackagingItem;
|
|
use App\Models\Supplier;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
function supplierDetailsUser(int $adminLevel): User
|
|
{
|
|
$user = User::query()->create([
|
|
'email' => uniqid('det_', true).'@test.example',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
$user->forceFill([
|
|
'admin' => $adminLevel,
|
|
'confirmed' => true,
|
|
'active' => true,
|
|
'wizard' => 100,
|
|
'blocked' => false,
|
|
])->save();
|
|
|
|
return $user->fresh();
|
|
}
|
|
|
|
test('supplier show displays assigned ingredients and packaging items', function () {
|
|
$supplier = Supplier::factory()->create(['name' => 'Detail-Lieferant']);
|
|
$ingredient = Ingredient::query()->create(['name' => 'Sheabutter', 'active' => true]);
|
|
$supplier->ingredients()->attach($ingredient->id);
|
|
$item = PackagingItem::factory()->create(['name' => 'Braunglas 50ml', 'supplier_id' => $supplier->id]);
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->get(route('admin.inventory.suppliers.show', $supplier))
|
|
->assertSuccessful()
|
|
->assertSee('Detail-Lieferant')
|
|
->assertSee('Sheabutter')
|
|
->assertSee('Braunglas 50ml')
|
|
->assertSee('Zugeordnete INCIs')
|
|
->assertSee('Zugeordnete Verpackungsartikel');
|
|
});
|
|
|
|
test('ingredient can be attached to supplier from details', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
$ingredient = Ingredient::query()->create(['name' => 'Lavendelöl', 'active' => true]);
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->post(route('admin.inventory.suppliers.ingredients.attach', $supplier), [
|
|
'ingredient_id' => $ingredient->id,
|
|
])->assertSuccessful()->assertSee('Lavendelöl');
|
|
|
|
expect($supplier->ingredients()->pluck('ingredients.id')->all())->toContain($ingredient->id);
|
|
});
|
|
|
|
test('ingredient can be detached from supplier', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
$ingredient = Ingredient::query()->create(['name' => 'Jojobaöl', 'active' => true]);
|
|
$supplier->ingredients()->attach($ingredient->id);
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->delete(route('admin.inventory.suppliers.ingredients.detach', [$supplier, $ingredient]))
|
|
->assertSuccessful();
|
|
|
|
expect($supplier->ingredients()->count())->toBe(0);
|
|
});
|
|
|
|
test('packaging item can be attached to supplier from details', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
$item = PackagingItem::factory()->create(['name' => 'Pumpspender', 'supplier_id' => null]);
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->post(route('admin.inventory.suppliers.packaging-items.attach', $supplier), [
|
|
'packaging_item_id' => $item->id,
|
|
])->assertSuccessful()->assertSee('Pumpspender');
|
|
|
|
expect($item->fresh()->supplier_id)->toBe($supplier->id);
|
|
});
|
|
|
|
test('packaging item can be detached from supplier', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
$item = PackagingItem::factory()->create(['name' => 'Faltschachtel', 'supplier_id' => $supplier->id]);
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->delete(route('admin.inventory.suppliers.packaging-items.detach', [$supplier, $item]))
|
|
->assertSuccessful();
|
|
|
|
expect($item->fresh()->supplier_id)->toBeNull();
|
|
});
|
|
|
|
test('attach ingredient validates ingredient exists', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
|
|
$this->actingAs(supplierDetailsUser(7), 'user');
|
|
|
|
$this->post(route('admin.inventory.suppliers.ingredients.attach', $supplier), [
|
|
'ingredient_id' => 999999,
|
|
])->assertSessionHasErrors('ingredient_id');
|
|
});
|
|
|
|
test('supplier details require admin level', function () {
|
|
$supplier = Supplier::factory()->create();
|
|
|
|
$this->actingAs(supplierDetailsUser(1), 'user');
|
|
|
|
$this->get(route('admin.inventory.suppliers.show', $supplier))
|
|
->assertRedirect();
|
|
});
|