diff --git a/tests/Unit/Migration/V2_0_0_Pdk/MigrateCarrierSettingsTest.php b/tests/Unit/Migration/V2_0_0_Pdk/MigrateCarrierSettingsTest.php new file mode 100644 index 00000000..34344d06 --- /dev/null +++ b/tests/Unit/Migration/V2_0_0_Pdk/MigrateCarrierSettingsTest.php @@ -0,0 +1,133 @@ + 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(); diff --git a/tests/Unit/Migration/V2_0_0_Pdk/MigrateDeliveryOptionsTest.php b/tests/Unit/Migration/V2_0_0_Pdk/MigrateDeliveryOptionsTest.php new file mode 100644 index 00000000..3f4bd3dc --- /dev/null +++ b/tests/Unit/Migration/V2_0_0_Pdk/MigrateDeliveryOptionsTest.php @@ -0,0 +1,167 @@ +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(); diff --git a/tests/Unit/Migration/V2_0_0_Pdk/MigratePluginSettingsTest.php b/tests/Unit/Migration/V2_0_0_Pdk/MigratePluginSettingsTest.php new file mode 100644 index 00000000..6fb6aa62 --- /dev/null +++ b/tests/Unit/Migration/V2_0_0_Pdk/MigratePluginSettingsTest.php @@ -0,0 +1,13 @@ +skip(); diff --git a/tests/Unit/Migration/V2_0_0_Pdk/MigrateProductSettingsTest.php b/tests/Unit/Migration/V2_0_0_Pdk/MigrateProductSettingsTest.php new file mode 100644 index 00000000..9c9c6e7a --- /dev/null +++ b/tests/Unit/Migration/V2_0_0_Pdk/MigrateProductSettingsTest.php @@ -0,0 +1,13 @@ +skip();