toHaveKeys([ShouldQueue::class, ShouldBeUnique::class]) ->and($job->uniqueFor)->toBe(3600) ->and($job->uniqueId())->toBe('fetch-and-upsert-arcadia-product-incos'); }); it('executes SynchronizeProductIncosWithArcadiaApi via Executor in handle', function (): void { // GIVEN /** @var Executor&\Mockery\MockInterface $executor */ $executor = \Mockery::mock(Executor::class); /** @var ArcadiaIncoService&\Mockery\MockInterface $arcadiaService */ $arcadiaService = \Mockery::mock(ArcadiaIncoService::class); $action = new SynchronizeProductIncosWithArcadiaApi($arcadiaService, new NullLogger()); $job = new FetchAndUpsertArcadiaProductIncos(); $executor->shouldReceive('execute') ->once() ->with($action, \Mockery::type(ActionInputEmpty::class)) ->andReturn(0); // WHEN $job->handle($executor, $action); // THEN expect(\Mockery::getContainer()->mockery_getExpectationCount())->toBeGreaterThan(0); }); it('synchronizes product incos via dispatchSync using mocked ArcadiaIncoService', function (): void { // GIVEN $range = new Range(); $range->name = 'Gamme ' . uniqid(); $range->status = true; $range->order = random_int(1, 9999); $range->picture_alt = 'alt'; $range->picture_title = 'title'; $range->save(); $product = new Product([ 'range_id' => $range->id, 'name' => 'Produit ' . uniqid(), 'brand' => ProductBrand::loue, 'invoicing_unit' => InvoicingUnit::PCE, 'sell_unit' => SellUnit::PCE, 'order_unit' => OrderUnit::PCE, 'tax_rate' => TaxRate::TVA_20, 'description' => 'Description test', 'status' => true, ]); $product->order = random_int(1, 999999); $product->price = Money::EUR(1000); $product->short_description = 'Court'; $product->picture_alt = 'alt'; $product->picture_title = 'title'; $product->picture_large_alt = 'alt'; $product->picture_large_title = 'title'; $product->save(); $inco = new ProductInco(); $inco->product_id = (string) $product->id; $inco->no_art = 1001; $inco->ingredients = 'Anciens ingrédients'; $inco->save(); $data = new ArcadiaIncoDataDto( noArt: 1001, name: 'P1', libelle: 'Produit 1', brand: 'LDC', ingredients: '

Nouveaux ingrédients

', preparation: null, servings: null, allergens: 'Gluten', sellingArgument: null, nutriscore: Nutriscore::A, nutriscoreArgs: null, nutrition: new NutritionalValues(refWeightG: 100.0, kj: 550.0), ); /** @var ArcadiaIncoService&\Mockery\MockInterface $arcadiaService */ $arcadiaService = \Mockery::mock(ArcadiaIncoService::class); $arcadiaService->shouldReceive('fetchInco') ->with(1001) ->once() ->andReturn($data); app()->instance(ArcadiaIncoService::class, $arcadiaService); // WHEN FetchAndUpsertArcadiaProductIncos::dispatchSync(); // THEN $fresh = ProductInco::query()->find($inco->id); expect($fresh?->ingredients)->toBe('

Nouveaux ingrédients

') ->and($fresh?->allergens)->toBe('Gluten') ->and($fresh?->nutriscore)->toBe(Nutriscore::A); }); });