Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GravendeelJochem committed Oct 30, 2024
1 parent c76ffc9 commit b328dd5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function calculate(): void
$shipmentOptions->largeFormat = TriStateService::DISABLED;
$shipmentOptions->return = TriStateService::DISABLED;

if ($shipmentOptions->insurance <= TriStateService::ENABLED) {
if ($shipmentOptions->insurance <= 1) {
$shipmentOptions->insurance = 10000;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\App\Order\Calculator\PostNl;

use MyParcelNL\Pdk\App\Order\Model\PdkOrder;
use MyParcelNL\Pdk\Shipment\Model\DeliveryOptions;
use MyParcelNL\Pdk\Shipment\Model\ShipmentOptions;
use MyParcelNL\Pdk\Tests\Uses\UsesMockPdkInstance;
use MyParcelNL\Pdk\Types\Service\TriStateService;
use function MyParcelNL\Pdk\Tests\factory;
use function MyParcelNL\Pdk\Tests\mockPdkProperty;
use function MyParcelNL\Pdk\Tests\usesShared;

usesShared(new UsesMockPdkInstance());

it('disables signature, only recipient, large format and return when receipt code is enabled', function () {
$reset = mockPdkProperty('orderCalculators', [PostNLReceiptCodeCalculator::class]);

$order = factory(PdkOrder::class)
->withShippingAddress(['cc' => 'NL'])
->withDeliveryOptions(
factory(DeliveryOptions::class)
->withShipmentOptions(
factory(ShipmentOptions::class)
->withSignature(TriStateService::ENABLED)
->withOnlyRecipient(TriStateService::ENABLED)
->withLargeFormat(TriStateService::ENABLED)
->withReturn(TriStateService::ENABLED)
->withReceiptCode(TriStateService::ENABLED)
)
)
->make();

$calculator = new PostNLReceiptCodeCalculator($order);
$calculator->calculate();

$shipmentOptions = $order->deliveryOptions->shipmentOptions;

expect($shipmentOptions->signature)->toBe(TriStateService::DISABLED)
->and($shipmentOptions->onlyRecipient)->toBe(TriStateService::DISABLED)
->and($shipmentOptions->largeFormat)->toBe(TriStateService::DISABLED)
->and($shipmentOptions->return)->toBe(TriStateService::DISABLED);

$reset();
});

0 comments on commit b328dd5

Please sign in to comment.