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: improve coverage
joerivanveen committed Jan 27, 2025
commit 31d1b2e43ce45bf5dcf2533b0629dd1c3ebe8613
42 changes: 39 additions & 3 deletions tests/Unit/App/Action/Backend/Order/ExportOrderActionTest.php
Original file line number Diff line number Diff line change
@@ -56,10 +56,9 @@
dataset('action type toggle', [
'auto' => 'automatic',
'manual' => 'manual',
'none' => null,
]);

it('remembers whether it was auto exported', function (?string $actionType) {
it('handles auto exported flag', function (?string $actionType) {
$orderFactory = factory(PdkOrderCollection::class)->push(
factory(PdkOrder::class)->toTheNetherlands()
);
@@ -70,7 +69,6 @@
MockApi::enqueue(new ExamplePostShipmentsResponse());
MockApi::enqueue(new ExampleGetShipmentLabelsLinkResponse());
MockApi::enqueue(new ExamplePostShipmentsResponse());
MockApi::enqueue(new ExampleGetShipmentLabelsLinkResponse());

$response = Actions::execute(PdkBackendActions::EXPORT_ORDERS, [
'actionType' => $actionType,
@@ -82,6 +80,44 @@
expect(json_decode($response->getContent(), false)->data->orders[0]->autoExported)->toBe(
'automatic' === $actionType
);

// if it was already auto-exported, you can not auto-export again
$orderFactory = factory(PdkOrderCollection::class)->push(
factory(PdkOrder::class)->toTheNetherlands()->withAutoExported('automatic' === $actionType)
);
$orders = new Collection($orderFactory->make());

$orderFactory->store();

MockApi::enqueue(new ExamplePostShipmentsResponse());

$response = Actions::execute(PdkBackendActions::EXPORT_ORDERS, [
'actionType' => 'automatic',
'orderIds' => $orders
->pluck('externalIdentifier')
->toArray(),
]);

expect(count(json_decode($response->getContent(), false)->data->orders[0]->shipments))->toBe('automatic' === $actionType ? 0 : 1);

// if it was already auto-exported, you can manually export it no problem
$orderFactory = factory(PdkOrderCollection::class)->push(
factory(PdkOrder::class)->toTheNetherlands()->withAutoExported('automatic' === $actionType)
);
$orders = new Collection($orderFactory->make());

$orderFactory->store();

MockApi::enqueue(new ExamplePostShipmentsResponse());

$response = Actions::execute(PdkBackendActions::EXPORT_ORDERS, [
'actionType' => 'manual',
'orderIds' => $orders
->pluck('externalIdentifier')
->toArray(),
]);

expect(count(json_decode($response->getContent(), false)->data->orders[0]->shipments))->toBe(1);
})
->with('action type toggle');