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).
176 lines
5.9 KiB
PHP
176 lines
5.9 KiB
PHP
<?php
|
||
|
||
use App\Models\Country;
|
||
use App\Models\DeliveryTime;
|
||
use App\Models\Supplier;
|
||
use App\User;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Tests\TestCase;
|
||
|
||
uses(TestCase::class, RefreshDatabase::class);
|
||
|
||
function supplierOrderUser(int $adminLevel): User
|
||
{
|
||
$user = User::query()->create([
|
||
'email' => uniqid('sup_', true).'@test.example',
|
||
'password' => bcrypt('password'),
|
||
]);
|
||
$user->forceFill([
|
||
'admin' => $adminLevel,
|
||
'confirmed' => true,
|
||
'active' => true,
|
||
'wizard' => 100,
|
||
'blocked' => false,
|
||
])->save();
|
||
|
||
return $user->fresh();
|
||
}
|
||
|
||
function supplierOrderCountry(): Country
|
||
{
|
||
return Country::query()->firstOrCreate(
|
||
['code' => 'DE'],
|
||
[
|
||
'phone' => '00',
|
||
'en' => 'Germany',
|
||
'de' => 'Deutschland',
|
||
'es' => 'Germany',
|
||
'fr' => 'Germany',
|
||
'it' => 'Germany',
|
||
'ru' => 'Germany',
|
||
'active' => true,
|
||
]
|
||
);
|
||
}
|
||
|
||
test('supplier form shows order fields and active delivery time templates', function () {
|
||
supplierOrderCountry();
|
||
DeliveryTime::query()->create(['label' => '3–5 Werktage', 'active' => true, 'pos' => 0]);
|
||
DeliveryTime::query()->create(['label' => 'Inaktiv-Vorlage', 'active' => false, 'pos' => 1]);
|
||
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->get(route('admin.inventory.suppliers.create'))
|
||
->assertSuccessful()
|
||
->assertSee('order_method')
|
||
->assertSee('delivery_time')
|
||
->assertSee('3–5 Werktage')
|
||
->assertDontSee('Inaktiv-Vorlage');
|
||
});
|
||
|
||
test('supplier can be stored with email order method', function () {
|
||
$country = supplierOrderCountry();
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->post(route('admin.inventory.suppliers.store'), [
|
||
'name' => 'Mail-Lieferant',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'order_method' => 'email',
|
||
'order_email' => 'bestellung@example.test',
|
||
'delivery_time' => '3–5 Werktage',
|
||
'delivery_time_days' => '5',
|
||
])->assertRedirect(route('admin.inventory.suppliers.index'));
|
||
|
||
$supplier = Supplier::query()->where('name', 'Mail-Lieferant')->firstOrFail();
|
||
|
||
expect($supplier->order_method)->toBe('email')
|
||
->and($supplier->order_email)->toBe('bestellung@example.test')
|
||
->and($supplier->delivery_time)->toBe('3–5 Werktage')
|
||
->and($supplier->delivery_time_days)->toBe(5);
|
||
});
|
||
|
||
test('supplier delivery time days must be an integer', function () {
|
||
$country = supplierOrderCountry();
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->post(route('admin.inventory.suppliers.store'), [
|
||
'name' => 'Falsche-Tage',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'delivery_time_days' => 'viele',
|
||
])->assertSessionHasErrors('delivery_time_days');
|
||
});
|
||
|
||
test('supplier form exposes delivery time template days for autofill', function () {
|
||
supplierOrderCountry();
|
||
DeliveryTime::query()->create(['label' => '3–5 Werktage', 'days' => 5, 'active' => true, 'pos' => 0]);
|
||
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->get(route('admin.inventory.suppliers.create'))
|
||
->assertSuccessful()
|
||
->assertSee('data-days="5"', false)
|
||
->assertSee('delivery_time_days');
|
||
});
|
||
|
||
test('supplier can be stored with online shop order method', function () {
|
||
$country = supplierOrderCountry();
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->post(route('admin.inventory.suppliers.store'), [
|
||
'name' => 'Shop-Lieferant',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'order_method' => 'online_shop',
|
||
'order_url' => 'https://shop.example.test/order?id=5&ref=abc',
|
||
])->assertRedirect(route('admin.inventory.suppliers.index'));
|
||
|
||
$supplier = Supplier::query()->where('name', 'Shop-Lieferant')->firstOrFail();
|
||
|
||
expect($supplier->order_method)->toBe('online_shop')
|
||
->and($supplier->order_url)->toBe('https://shop.example.test/order?id=5&ref=abc');
|
||
});
|
||
|
||
test('supplier order fields can be updated', function () {
|
||
$country = supplierOrderCountry();
|
||
$supplier = Supplier::query()->create([
|
||
'name' => 'Update-Lieferant',
|
||
'country_id' => $country->id,
|
||
'active' => true,
|
||
'order_method' => 'email',
|
||
'order_email' => 'alt@example.test',
|
||
]);
|
||
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->put(route('admin.inventory.suppliers.update', $supplier), [
|
||
'name' => 'Update-Lieferant',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'order_method' => 'online_shop',
|
||
'order_url' => 'https://neu.example.test',
|
||
'delivery_time' => '1–2 Wochen',
|
||
])->assertRedirect(route('admin.inventory.suppliers.index'));
|
||
|
||
$supplier->refresh();
|
||
|
||
expect($supplier->order_method)->toBe('online_shop')
|
||
->and($supplier->order_url)->toBe('https://neu.example.test')
|
||
->and($supplier->delivery_time)->toBe('1–2 Wochen');
|
||
});
|
||
|
||
test('supplier order method rejects invalid value', function () {
|
||
$country = supplierOrderCountry();
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->post(route('admin.inventory.suppliers.store'), [
|
||
'name' => 'Falscher-Bestellweg',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'order_method' => 'fax',
|
||
])->assertSessionHasErrors('order_method');
|
||
});
|
||
|
||
test('supplier order email must be valid email', function () {
|
||
$country = supplierOrderCountry();
|
||
$this->actingAs(supplierOrderUser(7), 'user');
|
||
|
||
$this->post(route('admin.inventory.suppliers.store'), [
|
||
'name' => 'Falsche-Mail',
|
||
'country_id' => (string) $country->id,
|
||
'active' => '1',
|
||
'order_method' => 'email',
|
||
'order_email' => 'keine-mail',
|
||
])->assertSessionHasErrors('order_email');
|
||
});
|