Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remember when order is auto exported #331

Merged
merged 11 commits into from
Feb 4, 2025
Prev Previous commit
Next Next commit
test: add test and update relevant snapshots
joerivanveen committed Jan 27, 2025
commit 154bff045c0dae0111d75f5384b365867a22b16e
35 changes: 35 additions & 0 deletions tests/Unit/App/Action/Backend/Order/ExportOrderActionTest.php
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions;
use MyParcelNL\Pdk\Shipment\Model\RetailLocation;
use MyParcelNL\Pdk\Shipment\Model\RetailLocationFactory;
use MyParcelNL\Pdk\Tests\Api\Response\ExampleGetShipmentLabelsLinkResponse;
use MyParcelNL\Pdk\Tests\Api\Response\ExampleGetShipmentLabelsLinkV2Response;
use MyParcelNL\Pdk\Tests\Api\Response\ExampleGetShipmentsResponse;
use MyParcelNL\Pdk\Tests\Api\Response\ExamplePostOrderNotesResponse;
@@ -52,6 +53,40 @@
'order mode' => [true],
]);

dataset('action type toggle', [
'auto' => 'automatic',
'manual' => 'manual',
]);

it('remembers whether it was auto exported', function (string $actionType) {
$orderFactory = factory(PdkOrderCollection::class)->push(
factory(PdkOrder::class)
->withDeliveryOptions(
factory(DeliveryOptions::class)
->withCarrier(Carrier::CARRIER_UPS_NAME)
->withDeliveryType(DeliveryOptions::DELIVERY_TYPE_EXPRESS_NAME)
)
->toTheNetherlands()
);
$orders = new Collection($orderFactory->make());

$orderFactory->store();

MockApi::enqueue(new ExamplePostShipmentsResponse());
MockApi::enqueue(new ExampleGetShipmentLabelsLinkResponse());
MockApi::enqueue(new ExamplePostShipmentsResponse());
MockApi::enqueue(new ExampleGetShipmentLabelsLinkResponse());

$response = Actions::execute(PdkBackendActions::EXPORT_ORDERS, [
'actionType' => $actionType,
'orderIds' => $orders
->pluck('externalIdentifier')
->toArray(),
]);
expect(json_decode($response->getContent(), false)->data->orders[0]->autoExported)->toBe('automatic' === $actionType);
})
->with('action type toggle');

it('exports order', function (
bool $orderMode,
CarrierSettingsFactory $carrierSettingsFactory,