-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(orders): fix error when weight is a string
INT-552 Resolves #256
- Loading branch information
1 parent
0c5c1ad
commit 0676ec5
Showing
6 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/Unit/Pdk/Product/Repository/PsPdkProductRepositoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Pdk\Product\Repository; | ||
|
||
use MyParcelNL\Pdk\App\Order\Contract\PdkProductRepositoryInterface; | ||
use MyParcelNL\Pdk\Facade\Pdk; | ||
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance; | ||
use Product; | ||
use ProductFactory; | ||
use function MyParcelNL\Pdk\Tests\usesShared; | ||
use function MyParcelNL\PrestaShop\psFactory; | ||
use function Spatie\Snapshots\assertMatchesJsonSnapshot; | ||
|
||
usesShared(new UsesMockPsPdkInstance()); | ||
|
||
it('creates a valid pdk product', function (ProductFactory $productFactory) { | ||
/** @var \MyParcelNL\Pdk\App\Order\Contract\PdkProductRepositoryInterface $productRepository */ | ||
$productRepository = Pdk::get(PdkProductRepositoryInterface::class); | ||
|
||
/** @var Product $psProduct */ | ||
$psProduct = $productFactory->store(); | ||
|
||
$pdkProduct = $productRepository->getProduct($psProduct->id); | ||
|
||
assertMatchesJsonSnapshot(json_encode($pdkProduct->toArrayWithoutNull(), JSON_THROW_ON_ERROR)); | ||
})->with([ | ||
'simple product' => function () { | ||
return psFactory(Product::class) | ||
->withPrice(1000) | ||
->withWeight(1); | ||
}, | ||
'product with weight as string' => function () { | ||
return psFactory(Product::class)->withWeight('234'); | ||
}, | ||
'unavailable virtual product' => function () { | ||
return psFactory(Product::class) | ||
->withIsAvailableForOrder(false) | ||
->withIsVirtual(true); | ||
}, | ||
]); |
30 changes: 30 additions & 0 deletions
30
...yTest__it_creates_a_valid_pdk_product_with_data_set_product_with_weight_as_string__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"externalIdentifier": "1", | ||
"isDeliverable": false, | ||
"name": "Test product", | ||
"price": { | ||
"amount": 0, | ||
"currency": "EUR" | ||
}, | ||
"weight": 234, | ||
"length": 0, | ||
"width": 0, | ||
"height": 0, | ||
"settings": { | ||
"id": "product", | ||
"countryOfOrigin": -1, | ||
"customsCode": -1, | ||
"disableDeliveryOptions": -1, | ||
"dropOffDelay": -1, | ||
"exportAgeCheck": -1, | ||
"exportHideSender": -1, | ||
"exportInsurance": -1, | ||
"exportLargeFormat": -1, | ||
"exportOnlyRecipient": -1, | ||
"exportReturn": -1, | ||
"exportSignature": -1, | ||
"fitInDigitalStamp": -1, | ||
"fitInMailbox": -1, | ||
"packageType": -1 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...roductRepositoryTest__it_creates_a_valid_pdk_product_with_data_set_simple_product__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"externalIdentifier": "1", | ||
"isDeliverable": false, | ||
"name": "Test product", | ||
"price": { | ||
"amount": 100000, | ||
"currency": "EUR" | ||
}, | ||
"weight": 1, | ||
"length": 0, | ||
"width": 0, | ||
"height": 0, | ||
"settings": { | ||
"id": "product", | ||
"countryOfOrigin": -1, | ||
"customsCode": -1, | ||
"disableDeliveryOptions": -1, | ||
"dropOffDelay": -1, | ||
"exportAgeCheck": -1, | ||
"exportHideSender": -1, | ||
"exportInsurance": -1, | ||
"exportLargeFormat": -1, | ||
"exportOnlyRecipient": -1, | ||
"exportReturn": -1, | ||
"exportSignature": -1, | ||
"fitInDigitalStamp": -1, | ||
"fitInMailbox": -1, | ||
"packageType": -1 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...oryTest__it_creates_a_valid_pdk_product_with_data_set_unavailable_virtual_product__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"externalIdentifier": "1", | ||
"isDeliverable": false, | ||
"name": "Test product", | ||
"price": { | ||
"amount": 0, | ||
"currency": "EUR" | ||
}, | ||
"weight": 0, | ||
"length": 0, | ||
"width": 0, | ||
"height": 0, | ||
"settings": { | ||
"id": "product", | ||
"countryOfOrigin": -1, | ||
"customsCode": -1, | ||
"disableDeliveryOptions": -1, | ||
"dropOffDelay": -1, | ||
"exportAgeCheck": -1, | ||
"exportHideSender": -1, | ||
"exportInsurance": -1, | ||
"exportLargeFormat": -1, | ||
"exportOnlyRecipient": -1, | ||
"exportReturn": -1, | ||
"exportSignature": -1, | ||
"fitInDigitalStamp": -1, | ||
"fitInMailbox": -1, | ||
"packageType": -1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters