Skip to content

Commit

Permalink
[API] shipping with tracking code + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Mar 16, 2020
1 parent dc6e727 commit fa8b5c1
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Feature: Shipping a shipment from shipment list
And an email with the "UPS" shipment's confirmation for the "#00000001" order should be sent to "donald@duck.com"
And I should see the shipment of order "#00000001" as "Shipped"

@ui @email
@ui @api @email
Scenario: Shipping a shipment with tracking code from shipments index
When I browse shipments
And I ship the shipment of order "#00000001" with "AWDDXS-SAAQQ-SEFFX-CCDSE" tracking code
Then I should be notified that the shipment has been successfully shipped
And an email with the shipment's confirmation of the order "#00000001" should be sent to "donald@duck.com"

@ui @api @email
@ui @api
Scenario: Setting date when a shipment has been shipped
Given it is "20-02-2020 10:30:05" now
When I browse shipments
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Client/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function delete(string $id): Response;

public function filter(): Response;

public function applyTransition(string $id, string $transition): Response;
public function applyTransition(string $id, string $transition, array $content = []): Response;

public function buildCreateRequest(): void;

Expand Down
3 changes: 2 additions & 1 deletion src/Sylius/Behat/Client/ApiPlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public function filter(): Response
return $this->request($this->request);
}

public function applyTransition(string $id, string $transition): Response
public function applyTransition(string $id, string $transition, array $content = []): Response
{
$this->request->setContent($content);
return $this->request(Request::transition($this->resource, $id, $transition, $this->sharedStorage->get('token')));
}

Expand Down
26 changes: 18 additions & 8 deletions src/Sylius/Behat/Context/Api/Admin/ManagingShipmentsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function iBrowseShipments(): void
}

/**
* @When I choose :shipmentState as a shipment state
* @When I choose :state as a shipment state
*/
public function iChooseShipmentState(string $state): void
{
Expand Down Expand Up @@ -94,6 +94,18 @@ public function iShipShipmentOfOrder(OrderInterface $order): void
$this->client->applyTransition((string) $order->getShipments()->first()->getId(), ShipmentTransitions::TRANSITION_SHIP);
}

/**
* @When I ship the shipment of order :order with :trackingCode tracking code
*/
public function iShipTheShipmentOfOrderWithTrackingCode(OrderInterface $order, string $trackingCode): void
{
$this->client->applyTransition(
(string) $order->getShipments()->first()->getId(),
ShipmentTransitions::TRANSITION_SHIP,
['tracking' => $trackingCode]
);
}

/**
* @Then I should be notified that the shipment has been successfully shipped
*/
Expand Down Expand Up @@ -137,13 +149,11 @@ public function iShouldSeeShipmentForTheOrderInTheList(OrderInterface $order, in
*/
public function iShouldSeeTheShippingDateAs(OrderInterface $order, string $dateTime): void
{
$shipmentShowResponse = $this->client->show((string) $order->getShipments()->first()->getId());

if (
strtotime($this->responseChecker->getValue($shipmentShowResponse, 'shippedAt')) != strtotime($dateTime)
) {
throw new \InvalidArgumentException('Shipment was shipped in different date');
}
Assert::eq(
new \DateTime($this->responseChecker->getValue($this->client->show((string) $order->getShipments()->first()->getId()), 'shippedAt')),
new \DateTime($dateTime),
'Shipment was shipped in different date'
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(StateMachineFactoryInterface $stateMachineFactory)

public function ship(ShipmentInterface $data): ShipmentInterface
{
$this->applyTransition( $data, ShipmentTransitions::TRANSITION_SHIP);
$this->applyTransition($data, ShipmentTransitions::TRANSITION_SHIP);

return $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<itemOperation name="ship">
<attribute name="method">PATCH</attribute>
<attribute name="path">/shipments/{id}/ship</attribute>
<attribute name="controller">sylius.api.shipment_machine_transition_applicator::ship</attribute>
<attribute name="controller">sylius.api.shipment_state_machine_transition_applicator::ship</attribute>
</itemOperation>
</itemOperations>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<itemOperation name="get" />
</itemOperations>

<collectionOperations />

<property name="id" identifier="true" writable="false" />
</resource>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<attribute name="tracking">
<group>shipment:read</group>
<group>shipment:update</group>
</attribute>

<attribute name="shippedAt">
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<argument id="sm.factory" type="service" />
</service>

<service id="sylius.api.shipment_machine_transition_applicator" class="Sylius\Bundle\ApiBundle\Applicator\ShipmentStateMachineTransitionApplicator" public="true">
<service id="sylius.api.shipment_state_machine_transition_applicator" class="Sylius\Bundle\ApiBundle\Applicator\ShipmentStateMachineTransitionApplicator" public="true">
<argument id="sm.factory" type="service" />
</service>
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

final class ShipmentStateMachineTransitionApplicatorSpec extends ObjectBehavior
{
function let(StateMachineFactoryInterface $stateMachineFactory)
function let(StateMachineFactoryInterface $stateMachineFactory): void
{
$this->beConstructedWith($stateMachineFactory);
}
Expand Down

0 comments on commit fa8b5c1

Please sign in to comment.