'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'); });