Warenwirtschaft: AP-09 bis AP-13 (Produktbestand, Set-Produkte, Ausschuss, Konzepte)
- AP-09 Produktbestand inkl. Bewegungshistorie (product_stock_movements, ProductStockService) - AP-10 Rohstoffbestand-Ansicht je Lager (RawMaterialStockController) - AP-11 Bestandsschwellen / Out-of-Stock-Handling fuer Produkte und Shop - AP-12 Ausgang/Ausschuss (stock_disposals, StockDisposalController, InventoryService) - Set-Produkte (product_set_items) inkl. Aufloesung - Produktentwicklung & Hinweise-Verwaltung (Notices) - AP-13 Entwicklungskonzept Shop-Bestandsabzug im Plan dokumentiert - Feature-Tests fuer neue Module + aktualisierter Entwicklungsplan Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
78679e0c55
commit
3ee2d756e9
63 changed files with 5968 additions and 901 deletions
135
tests/Feature/ProductOutOfStockTest.php
Normal file
135
tests/Feature/ProductOutOfStockTest.php
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Repositories\ProductRepository;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
function oosMakeUser(int $adminLevel = 1): User
|
||||
{
|
||||
$user = User::query()->create([
|
||||
'email' => uniqid('oos_', true).'@test.example',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
$user->forceFill([
|
||||
'admin' => $adminLevel,
|
||||
'confirmed' => true,
|
||||
'active' => true,
|
||||
'wizard' => 100,
|
||||
'blocked' => false,
|
||||
])->save();
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
|
||||
function oosMakeProduct(string $name): Product
|
||||
{
|
||||
return Product::query()->create([
|
||||
'name' => $name,
|
||||
'title' => $name,
|
||||
'active' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
test('repository berechnet out_of_stock_until aus tagesangabe', function () {
|
||||
$product = oosMakeProduct('OOS-Tage');
|
||||
|
||||
$repo = new ProductRepository($product);
|
||||
$repo->update([
|
||||
'id' => (string) $product->id,
|
||||
'name' => $product->name,
|
||||
'title' => $product->title,
|
||||
'active' => '1',
|
||||
'out_of_stock_active' => '1',
|
||||
'out_of_stock_days' => '14',
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
|
||||
expect($product->out_of_stock_indefinite)->toBeFalse();
|
||||
expect($product->out_of_stock_until)->not->toBeNull();
|
||||
expect($product->out_of_stock_until->isSameDay(now()->addDays(14)))->toBeTrue();
|
||||
expect($product->isOutOfStock())->toBeTrue();
|
||||
});
|
||||
|
||||
test('unbestimmt hat vorrang und nullt das datum', function () {
|
||||
$product = oosMakeProduct('OOS-Unbestimmt');
|
||||
|
||||
$repo = new ProductRepository($product);
|
||||
$repo->update([
|
||||
'id' => (string) $product->id,
|
||||
'name' => $product->name,
|
||||
'title' => $product->title,
|
||||
'active' => '1',
|
||||
'out_of_stock_active' => '1',
|
||||
'out_of_stock_days' => '14',
|
||||
'out_of_stock_indefinite' => '1',
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
|
||||
expect($product->out_of_stock_indefinite)->toBeTrue();
|
||||
expect($product->out_of_stock_until)->toBeNull();
|
||||
expect($product->isOutOfStock())->toBeTrue();
|
||||
expect($product->outOfStockNotice())->toBe('Zur Zeit nicht vorrätig');
|
||||
});
|
||||
|
||||
test('ohne aktivierung werden die felder geleert', function () {
|
||||
$product = oosMakeProduct('OOS-Aus');
|
||||
$product->update(['out_of_stock_until' => now()->addDays(5), 'out_of_stock_indefinite' => false]);
|
||||
|
||||
$repo = new ProductRepository($product);
|
||||
$repo->update([
|
||||
'id' => (string) $product->id,
|
||||
'name' => $product->name,
|
||||
'title' => $product->title,
|
||||
'active' => '1',
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
|
||||
expect($product->out_of_stock_until)->toBeNull();
|
||||
expect($product->out_of_stock_indefinite)->toBeFalse();
|
||||
expect($product->isOutOfStock())->toBeFalse();
|
||||
});
|
||||
|
||||
test('vergangenes datum gilt nicht als nicht vorrätig', function () {
|
||||
$product = oosMakeProduct('OOS-Vergangen');
|
||||
$product->update(['out_of_stock_until' => now()->subDays(2)]);
|
||||
$product->refresh();
|
||||
|
||||
expect($product->isOutOfStock())->toBeFalse();
|
||||
expect($product->outOfStockRemainingDays())->toBeNull();
|
||||
expect($product->outOfStockNotice())->toBeNull();
|
||||
});
|
||||
|
||||
test('hinweis zeigt verbleibende tage', function () {
|
||||
$product = oosMakeProduct('OOS-Hinweis');
|
||||
$product->update(['out_of_stock_until' => now()->addDays(5)]);
|
||||
$product->refresh();
|
||||
|
||||
expect($product->isOutOfStock())->toBeTrue();
|
||||
expect($product->outOfStockRemainingDays())->toBe(5);
|
||||
expect($product->outOfStockNotice())->toBe('In ca. 5 Tagen wieder da!');
|
||||
});
|
||||
|
||||
test('http-store speichert nicht-vorrätig mit tagen', function () {
|
||||
$this->actingAs(oosMakeUser(1), 'user');
|
||||
|
||||
$response = $this->post(route('admin_product_store'), [
|
||||
'id' => 'new',
|
||||
'name' => 'OOS-HTTP',
|
||||
'out_of_stock_active' => '1',
|
||||
'out_of_stock_days' => '7',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
$product = Product::query()->where('name', 'OOS-HTTP')->firstOrFail();
|
||||
expect($product->out_of_stock_until)->not->toBeNull();
|
||||
expect($product->out_of_stock_until->isSameDay(now()->addDays(7)))->toBeTrue();
|
||||
expect($product->isOutOfStock())->toBeTrue();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue