April 2026 waren Wirtschaft Feedback
This commit is contained in:
parent
02f2a4c23e
commit
9ce711d6b2
167 changed files with 25278 additions and 8518 deletions
92
tests/Feature/ProductPhase1Test.php
Normal file
92
tests/Feature/ProductPhase1Test.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Ingredient;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductIngredient;
|
||||
use App\Repositories\ProductRepository;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
test('product saves inci pivot pos gram factor and shelf life', function () {
|
||||
$product = Product::create([
|
||||
'name' => 'Salbe',
|
||||
'title' => 'Salbe',
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$a = Ingredient::create([
|
||||
'name' => 'Shea',
|
||||
'trans_name' => '',
|
||||
'inci' => 'Butyrospermum',
|
||||
'trans_inci' => '',
|
||||
'effect' => '',
|
||||
'trans_effect' => '',
|
||||
'active' => true,
|
||||
'pos' => 0,
|
||||
'default_factor' => 1.15,
|
||||
]);
|
||||
|
||||
$repo = new ProductRepository($product);
|
||||
$repo->update([
|
||||
'id' => (string) $product->id,
|
||||
'name' => $product->name,
|
||||
'title' => $product->title,
|
||||
'active' => '1',
|
||||
'product_inci_sync_sent' => '1',
|
||||
'pi_ingredient_id' => [(string) $a->id],
|
||||
'pi_gram' => ['10,5'],
|
||||
'pi_factor' => ['1,20'],
|
||||
'shelf_life_type' => 'fixed',
|
||||
'shelf_life_months' => '12',
|
||||
]);
|
||||
|
||||
$product->refresh();
|
||||
expect($product->shelf_life_type)->toBe('fixed');
|
||||
expect($product->shelf_life_months)->toBe(12);
|
||||
|
||||
$pivot = $product->p_ingredients()->where('ingredients.id', $a->id)->first();
|
||||
expect($pivot)->not->toBeNull();
|
||||
expect((float) $pivot->pivot->gram)->toBe(10.5);
|
||||
expect((float) $pivot->pivot->factor)->toBe(1.20);
|
||||
expect((int) $pivot->pivot->pos)->toBe(0);
|
||||
});
|
||||
|
||||
test('product copy preserves inci pivot fields', function () {
|
||||
$source = Product::create([
|
||||
'name' => 'Original',
|
||||
'title' => 'Original',
|
||||
'active' => true,
|
||||
'shelf_life_type' => 'pao',
|
||||
]);
|
||||
|
||||
$ing = Ingredient::create([
|
||||
'name' => 'Oel',
|
||||
'trans_name' => '',
|
||||
'inci' => 'Oil',
|
||||
'trans_inci' => '',
|
||||
'effect' => '',
|
||||
'trans_effect' => '',
|
||||
'active' => true,
|
||||
'pos' => 0,
|
||||
]);
|
||||
|
||||
ProductIngredient::create([
|
||||
'product_id' => $source->id,
|
||||
'ingredient_id' => $ing->id,
|
||||
'pos' => 2,
|
||||
'gram' => 3.25,
|
||||
'factor' => 1.08,
|
||||
]);
|
||||
|
||||
$repo = new ProductRepository(new Product);
|
||||
$copy = $repo->copy($source->fresh());
|
||||
|
||||
$row = ProductIngredient::where('product_id', $copy->id)->where('ingredient_id', $ing->id)->first();
|
||||
expect($row)->not->toBeNull();
|
||||
expect((float) $row->gram)->toBe(3.25);
|
||||
expect((float) $row->factor)->toBe(1.08);
|
||||
expect($row->pos)->toBe(2);
|
||||
expect($copy->shelf_life_type)->toBe('pao');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue