- products.batch_prefix (z. B. TP1) mit Eingabefeld in der Warenwirtschaft-Card - Product::suggestedBatchNumber(): Praefix + Produktionsdatum ttmmjj (TP1 + 15.06.26 => TP1150626), Vorbelegung in der Produktion folgt mit AP-28 - Repository trimmt, leeres Praefix => null Tests: BatchPrefixTest (6 gruen), volle Suite 184 gruen, 657 Assertions Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
78 lines
2.9 KiB
PHP
78 lines
2.9 KiB
PHP
<?php
|
|
|
|
use App\Models\Product;
|
|
use App\Repositories\ProductRepository;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
test('chargen-praefix wird am produkt gespeichert und getrimmt', function () {
|
|
$product = Product::query()->create(['name' => 'AP24-Tattoocreme', 'title' => 'AP24-Tattoocreme', 'active' => true]);
|
|
|
|
$repo = new ProductRepository($product);
|
|
$repo->update([
|
|
'id' => (string) $product->id,
|
|
'name' => $product->name,
|
|
'title' => $product->title,
|
|
'active' => '1',
|
|
'batch_prefix' => ' TP1 ',
|
|
]);
|
|
|
|
expect($product->fresh()->batch_prefix)->toBe('TP1');
|
|
});
|
|
|
|
test('leeres praefix wird als null gespeichert', function () {
|
|
$product = Product::query()->create(['name' => 'AP24-Leer', 'title' => 'AP24-Leer', 'active' => true, 'batch_prefix' => 'ALT1']);
|
|
|
|
$repo = new ProductRepository($product);
|
|
$repo->update([
|
|
'id' => (string) $product->id,
|
|
'name' => $product->name,
|
|
'title' => $product->title,
|
|
'active' => '1',
|
|
'batch_prefix' => ' ',
|
|
]);
|
|
|
|
expect($product->fresh()->batch_prefix)->toBeNull();
|
|
});
|
|
|
|
test('suggestedBatchNumber setzt praefix und datum ttmmjj zusammen', function () {
|
|
$product = Product::query()->create(['name' => 'AP24-Vorschlag', 'title' => 'AP24-Vorschlag', 'active' => true, 'batch_prefix' => 'TP1']);
|
|
|
|
// Beispiel aus der Anforderung: TP1 + 15.06.2026 => TP1150626
|
|
expect($product->suggestedBatchNumber(Carbon::create(2026, 6, 15)))->toBe('TP1150626');
|
|
});
|
|
|
|
test('suggestedBatchNumber nutzt heute als default-datum', function () {
|
|
$this->travelTo(Carbon::create(2026, 7, 6));
|
|
|
|
$product = Product::query()->create(['name' => 'AP24-Heute', 'title' => 'AP24-Heute', 'active' => true, 'batch_prefix' => 'KP1']);
|
|
|
|
expect($product->suggestedBatchNumber())->toBe('KP1060726');
|
|
});
|
|
|
|
test('ohne praefix gibt es keinen vorschlag', function () {
|
|
$product = Product::query()->create(['name' => 'AP24-Ohne', 'title' => 'AP24-Ohne', 'active' => true]);
|
|
|
|
expect($product->suggestedBatchNumber(Carbon::create(2026, 6, 15)))->toBeNull();
|
|
});
|
|
|
|
test('produktformular zeigt das praefix-feld', function () {
|
|
$user = User::query()->create([
|
|
'email' => uniqid('ap24_', true).'@test.example',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
$user->forceFill(['admin' => 7, 'confirmed' => true, 'active' => true, 'wizard' => 100, 'blocked' => false])->save();
|
|
|
|
$product = Product::query()->create(['name' => 'AP24-Form', 'title' => 'AP24-Form', 'active' => true, 'batch_prefix' => 'TP1']);
|
|
|
|
$this->actingAs($user->fresh(), 'user');
|
|
$response = $this->get(route('admin_product_edit', $product->id));
|
|
|
|
$response->assertSuccessful();
|
|
$response->assertSee('Chargen-Nr.-Präfix');
|
|
$response->assertSee('value="TP1"', false);
|
|
});
|