Skip to content

Commit

Permalink
test: add initial 2.0.0 migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 21, 2023
1 parent 57b9331 commit 5750106
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 0 deletions.
133 changes: 133 additions & 0 deletions tests/Unit/Migration/V2_0_0_Pdk/MigrateCarrierSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Migration\V2_0_0_Pdk;

use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Settings\Contract\SettingsRepositoryInterface;
use MyParcelNL\PrestaShop\Migration\AbstractLegacyPsMigration;
use MyParcelNL\PrestaShop\Migration\Migration2_0_0;
use MyParcelNL\PrestaShop\Tests\Mock\MockPsDb;
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance;
use function MyParcelNL\Pdk\Tests\usesShared;
use function Spatie\Snapshots\assertMatchesJsonSnapshot;

usesShared(new UsesMockPsPdkInstance());

it('migrates carriers and their settings', function () {
MockPsDb::insertRows(AbstractLegacyPsMigration::LEGACY_TABLE_CARRIER_CONFIGURATION, [
['id_carrier' => 48, 'name' => 'carrierType', 'value' => 'postnl'],
['id_carrier' => 48, 'name' => 'dropOffDays', 'value' => null],
['id_carrier' => 48, 'name' => 'cutoff_exceptions', 'value' => null],
['id_carrier' => 48, 'name' => 'mondayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'tuesdayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'wednesdayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'thursdayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'fridayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'saturdayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'sundayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'deliveryDaysWindow', 'value' => null],
['id_carrier' => 48, 'name' => 'dropOffDelay', 'value' => null],
['id_carrier' => 48, 'name' => 'allowMondayDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'priceMondayDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'saturdayCutoffTime', 'value' => null],
['id_carrier' => 48, 'name' => 'allowMorningDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'priceMorningDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'allowEveningDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'priceEveningDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'allowSaturdayDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'priceSaturdayDelivery', 'value' => null],
['id_carrier' => 48, 'name' => 'allowSignature', 'value' => null],
['id_carrier' => 48, 'name' => 'priceSignature', 'value' => null],
['id_carrier' => 48, 'name' => 'allowOnlyRecipient', 'value' => null],
['id_carrier' => 48, 'name' => 'priceOnlyRecipient', 'value' => null],
['id_carrier' => 48, 'name' => 'allowPickupPoints', 'value' => null],
['id_carrier' => 48, 'name' => 'pricePickup', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_PACKAGE_TYPE', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_PACKAGE_FORMAT', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_AGE_CHECK', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_RETURN_PACKAGE', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_SIGNATURE_REQUIRED', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_INSURANCE', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_INSURANCE_FROM_PRICE', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT_BE', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT_EU', 'value' => null],
['id_carrier' => 48, 'name' => 'MYPARCELNL_RECIPIENT_ONLY', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_PACKAGE_TYPE', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_RECIPIENT_ONLY', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_AGE_CHECK', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_PACKAGE_FORMAT', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_RETURN_PACKAGE', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_SIGNATURE_REQUIRED', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_INSURANCE', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_INSURANCE_FROM_PRICE', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT_BE', 'value' => null],
['id_carrier' => 48, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT_EU', 'value' => null],
['id_carrier' => 48, 'name' => 'return_label_description', 'value' => null],
['id_carrier' => 49, 'name' => 'carrierType', 'value' => 'dhlforyou'],
['id_carrier' => 49, 'name' => 'dropOffDays', 'value' => ''],
['id_carrier' => 49, 'name' => 'cutoff_exceptions', 'value' => ''],
['id_carrier' => 49, 'name' => 'mondayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'tuesdayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'wednesdayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'thursdayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'fridayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'saturdayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'sundayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'deliveryDaysWindow', 'value' => '-1'],
['id_carrier' => 49, 'name' => 'dropOffDelay', 'value' => '0'],
['id_carrier' => 49, 'name' => 'allowMondayDelivery', 'value' => '0'],
['id_carrier' => 49, 'name' => 'priceMondayDelivery', 'value' => ''],
['id_carrier' => 49, 'name' => 'saturdayCutoffTime', 'value' => ''],
['id_carrier' => 49, 'name' => 'allowMorningDelivery', 'value' => '0'],
['id_carrier' => 49, 'name' => 'priceMorningDelivery', 'value' => ''],
['id_carrier' => 49, 'name' => 'allowEveningDelivery', 'value' => '0'],
['id_carrier' => 49, 'name' => 'priceEveningDelivery', 'value' => ''],
['id_carrier' => 49, 'name' => 'allowSaturdayDelivery', 'value' => ''],
['id_carrier' => 49, 'name' => 'priceSaturdayDelivery', 'value' => ''],
['id_carrier' => 49, 'name' => 'allowSignature', 'value' => '1'],
['id_carrier' => 49, 'name' => 'priceSignature', 'value' => '0.29'],
['id_carrier' => 49, 'name' => 'allowOnlyRecipient', 'value' => '1'],
['id_carrier' => 49, 'name' => 'priceOnlyRecipient', 'value' => '1.29'],
['id_carrier' => 49, 'name' => 'allowPickupPoints', 'value' => '1'],
['id_carrier' => 49, 'name' => 'pricePickup', 'value' => '4.95'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_PACKAGE_TYPE', 'value' => '1'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_PACKAGE_FORMAT', 'value' => '1'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_AGE_CHECK', 'value' => '0'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_RETURN_PACKAGE', 'value' => '0'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_SIGNATURE_REQUIRED', 'value' => '0'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_INSURANCE', 'value' => '0'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_INSURANCE_FROM_PRICE', 'value' => '10'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT', 'value' => '100'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT_BE', 'value' => '1000'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_INSURANCE_MAX_AMOUNT_EU', 'value' => '10000'],
['id_carrier' => 49, 'name' => 'MYPARCELNL_RECIPIENT_ONLY', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_PACKAGE_TYPE', 'value' => '1'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_RECIPIENT_ONLY', 'value' => '1'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_AGE_CHECK', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_PACKAGE_FORMAT', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_RETURN_PACKAGE', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_SIGNATURE_REQUIRED', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_INSURANCE', 'value' => '0'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_INSURANCE_FROM_PRICE', 'value' => '211'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT', 'value' => '212'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT_BE', 'value' => '213'],
['id_carrier' => 49, 'name' => 'return_MYPARCELNL_INSURANCE_MAX_AMOUNT_EU', 'value' => '214'],
], 'id_configuration');

/** @var \MyParcelNL\PrestaShop\Migration\Migration2_0_0 $migration */
$migration = Pdk::get(Migration2_0_0::class);
$migration->up();

/** @var SettingsRepositoryInterface $settingsRepository */
$settingsRepository = Pdk::get(SettingsRepositoryInterface::class);
$allSettings = $settingsRepository->all();

assertMatchesJsonSnapshot(
json_encode($allSettings->toArrayWithoutNull())
);
})->skip();
167 changes: 167 additions & 0 deletions tests/Unit/Migration/V2_0_0_Pdk/MigrateDeliveryOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Migration\V2_0_0_Pdk;

use MyParcelNL\Pdk\App\Order\Contract\PdkOrderRepositoryInterface;
use MyParcelNL\Pdk\Carrier\Model\Carrier;
use MyParcelNL\Pdk\Facade\Pdk;
use MyParcelNL\Pdk\Facade\Platform;
use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions;
use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions;
use MyParcelNL\Pdk\Tests\Factory\Collection\FactoryCollection;
use MyParcelNL\Pdk\Types\Service\TriStateService;
use MyParcelNL\PrestaShop\Migration\AbstractLegacyPsMigration;
use MyParcelNL\PrestaShop\Migration\Migration2_0_0;
use MyParcelNL\PrestaShop\Tests\Mock\MockPsDb;
use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance;
use Order as PsOrder;
use function MyParcelNL\Pdk\Tests\usesShared;
use function MyParcelNL\PrestaShop\psFactory;

usesShared(new UsesMockPsPdkInstance());

it('migrates delivery options', function (array $deliverySettings, array $extraOptions, array $result) {
(new FactoryCollection([
psFactory(PsOrder::class)->withIdCart(20),
]))->store();

MockPsDb::insertRows(AbstractLegacyPsMigration::LEGACY_TABLE_DELIVERY_SETTINGS, [
[
'id_cart' => 20,
'delivery_settings' => json_encode(
array_replace_recursive([
'carrier' => '',
'date' => '',
'deliveryType' => 'standard',
'packageType' => 'package',
'isPickup' => false,
'pickupLocation' => null,
'shipmentOptions' => [
'age_check' => null,
'extra_assurance' => null,
'hide_sender' => null,
'insurance' => null,
'label_description' => null,
'large_format' => null,
'only_recipient' => null,
'return' => null,
'same_day_delivery' => null,
'signature' => null,
],
], $deliverySettings)
),
'extra_options' => json_encode(
array_replace([
'labelAmount' => 1,
'digitalStampWeight' => 0,
], $extraOptions)
),
],
], 'id_delivery_setting');

/** @var \MyParcelNL\PrestaShop\Migration\Migration2_0_0 $migration */
$migration = Pdk::get(Migration2_0_0::class);
$migration->up();

$orderRepository = Pdk::get(PdkOrderRepositoryInterface::class);

$order = $orderRepository->get(1);
$deliveryOptionsArray = $order->deliveryOptions->toStorableArray();

expect($deliveryOptionsArray)->toEqual(
array_replace_recursive([
DeliveryOptions::CARRIER => Platform::get('defaultCarrier'),
DeliveryOptions::PACKAGE_TYPE => DeliveryOptions::PACKAGE_TYPE_PACKAGE_NAME,
DeliveryOptions::DELIVERY_TYPE => DeliveryOptions::DELIVERY_TYPE_STANDARD_NAME,
DeliveryOptions::LABEL_AMOUNT => 1,
DeliveryOptions::SHIPMENT_OPTIONS => [
ShipmentOptions::AGE_CHECK => TriStateService::INHERIT,
ShipmentOptions::DIRECT_RETURN => TriStateService::INHERIT,
ShipmentOptions::HIDE_SENDER => TriStateService::INHERIT,
ShipmentOptions::INSURANCE => TriStateService::INHERIT,
ShipmentOptions::LABEL_DESCRIPTION => TriStateService::INHERIT,
ShipmentOptions::LARGE_FORMAT => TriStateService::INHERIT,
ShipmentOptions::ONLY_RECIPIENT => TriStateService::INHERIT,
ShipmentOptions::SAME_DAY_DELIVERY => TriStateService::INHERIT,
ShipmentOptions::SIGNATURE => TriStateService::INHERIT,
],
], $result)
);
})
->with([
'defaults' => [
'delivery_settings' => [
'carrier' => Carrier::CARRIER_POSTNL_NAME,
],
'extra_options' => [],

'result' => [
DeliveryOptions::CARRIER => Carrier::CARRIER_POSTNL_NAME,
],
],

'dhlforyou with delivery date' => [
'delivery_settings' => [
'carrier' => 'dhlforyou',
'date' => '2023-04-07T00:00:00.000Z',
],
'extra_options' => [],

'result' => [
DeliveryOptions::CARRIER => Carrier::CARRIER_DHL_FOR_YOU_NAME,
DeliveryOptions::DATE => '2023-04-07T00:00:00.000Z',
],
],

'different label amount' => [
'delivery_settings' => [
'carrier' => Carrier::CARRIER_POSTNL_NAME,
],
'extra_options' => [
'labelAmount' => 5,
],

'result' => [
DeliveryOptions::CARRIER => Carrier::CARRIER_POSTNL_NAME,
DeliveryOptions::LABEL_AMOUNT => 5,
],
],

'all shipment options enabled' => [
'delivery_settings' => [
'carrier' => Carrier::CARRIER_DHL_FOR_YOU_NAME,
'shipmentOptions' => [
'signature' => true,
'insurance' => 2000,
'age_check' => true,
'only_recipient' => true,
'return' => true,
'same_day_delivery' => true,
'large_format' => true,
'label_description' => 'hello',
'hide_sender' => true,
'extra_assurance' => true,
],
],
'extra_options' => [],

'result' => [
DeliveryOptions::CARRIER => Carrier::CARRIER_DHL_FOR_YOU_NAME,
DeliveryOptions::SHIPMENT_OPTIONS => [
ShipmentOptions::LABEL_DESCRIPTION => 'hello',
ShipmentOptions::INSURANCE => 2000,
ShipmentOptions::AGE_CHECK => true,
ShipmentOptions::HIDE_SENDER => true,
ShipmentOptions::LARGE_FORMAT => true,
ShipmentOptions::ONLY_RECIPIENT => true,
ShipmentOptions::DIRECT_RETURN => true,
ShipmentOptions::SAME_DAY_DELIVERY => true,
ShipmentOptions::SIGNATURE => true,
],
],
],
])
->skip();
13 changes: 13 additions & 0 deletions tests/Unit/Migration/V2_0_0_Pdk/MigratePluginSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Migration\V2_0_0_Pdk;

use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance;
use function MyParcelNL\Pdk\Tests\usesShared;

usesShared(new UsesMockPsPdkInstance());

it('migrates plugin settings', function () {})->skip();
13 changes: 13 additions & 0 deletions tests/Unit/Migration/V2_0_0_Pdk/MigrateProductSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection,StaticClosureCanBeUsedInspection */

declare(strict_types=1);

namespace MyParcelNL\PrestaShop\Migration\V2_0_0_Pdk;

use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPsPdkInstance;
use function MyParcelNL\Pdk\Tests\usesShared;

usesShared(new UsesMockPsPdkInstance());

it('migrates product settings', function () {})->skip();

0 comments on commit 5750106

Please sign in to comment.