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

pishps314 cypress #836

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Controller/Api/Order/RefundControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function refundOrderID(RequestDataBag $data, Context $context): JsonRespo
$context
);

if ($response->getStatusCode() === 200 && $response->getContent() !== false) {
if ($response->getStatusCode() === 200 && $response->getContent() !== false && count($items) > 0) {
$refundId = json_decode($response->getContent(), true)['refundId'];
try {
$this->creditNoteService->addCreditNoteToOrder($orderId, $refundId, $items, $context);
Expand Down Expand Up @@ -220,8 +220,13 @@ public function cancel(RequestDataBag $data, Context $context): JsonResponse
try {
$this->creditNoteService->cancelCreditNoteToOrder($orderId, $refundId, $context);
} catch (CreditNoteException $exception) {
$this->logger->error($exception->getMessage(), ['code' => $exception->getCode(),]);
return $this->buildErrorResponse($exception->getMessage());
if ($exception->getCode() === CreditNoteException::CODE_REMOVING_CREDIT_NOTE_LINE_ITEMS) {
$this->logger->error($exception->getMessage(), ['code' => $exception->getCode(),]);
return $this->buildErrorResponse($exception->getMessage());
}
if ($exception->getCode() === CreditNoteException::CODE_WARNING_LEVEL) {
$this->logger->warning($exception->getMessage(), ['code' => $exception->getCode(),]);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Service/Refund/Exceptions/CreditNoteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class CreditNoteException extends \Exception
{
public const CODE_ADDING_CREDIT_NOTE_LINE_ITEMS = 1;
public const CODE_REMOVING_CREDIT_NOTE_LINE_ITEMS = 2;
public const CODE_WARNING_LEVEL = 3;

final private function __construct(string $message, int $code)
{
parent::__construct($message, $code);
Expand All @@ -17,8 +19,8 @@ public static function forAddingLineItems(string $message): CreditNoteException
return new self($message, self::CODE_ADDING_CREDIT_NOTE_LINE_ITEMS);
}

public static function forRemovingLineItems(string $message): CreditNoteException
public static function forRemovingLineItems(string $message, int $code = self::CODE_REMOVING_CREDIT_NOTE_LINE_ITEMS): CreditNoteException
{
return new self($message, self::CODE_REMOVING_CREDIT_NOTE_LINE_ITEMS);
return new self($message, $code);
}
}
10 changes: 8 additions & 2 deletions src/Service/Refund/RefundCreditNoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ public function cancelCreditNoteToOrder(string $orderId, string $refundId, Conte
$lineItems = $order->getLineItems();

if ($lineItems === null) {
throw CreditNoteException::forRemovingLineItems(sprintf('No line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId));
throw CreditNoteException::forRemovingLineItems(
sprintf('No line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId),
CreditNoteException::CODE_WARNING_LEVEL
);
}

$ids = [];
Expand All @@ -170,7 +173,10 @@ public function cancelCreditNoteToOrder(string $orderId, string $refundId, Conte
}

if (empty($ids)) {
throw CreditNoteException::forRemovingLineItems(sprintf('No credit note line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId));
throw CreditNoteException::forRemovingLineItems(
sprintf('No credit note line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId),
CreditNoteException::CODE_WARNING_LEVEL
);
}

$this->orderLineItemRepository->delete($ids, $context);
Expand Down
24 changes: 23 additions & 1 deletion tests/Cypress/cypress/e2e/storefront/refund/refund.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ context("Order Refunds", () => {
// now start the partial refund
refundManager.fullRefund(REFUND_DESCRIPTION, REFUND_INTERNAL_DESCRIPTION);

// verify that our refund now exists
cy.wait(5000); // wait for the page to reload

adminOrders.openRefundManager();

cy.wait(1500);

// // verify that our refund now exists
repoRefundManager.getFirstRefundStatusLabel().contains('Pending');

repoRefundManager.getFirstRefundPublicDescriptionLabel().contains(REFUND_DESCRIPTION);
Expand Down Expand Up @@ -108,6 +114,10 @@ context("Order Refunds", () => {
// now start the partial refund
refundManager.partialAmountRefund(2, REFUND_DESCRIPTION);

cy.wait(5000); // wait for the page to reload

adminOrders.openRefundManager();

// verify that our refund now exists
repoRefundManager.getFirstRefundStatusLabel().contains('Pending');
repoRefundManager.getFirstRefundPublicDescriptionLabel().contains(REFUND_DESCRIPTION);
Expand Down Expand Up @@ -144,6 +154,10 @@ context("Order Refunds", () => {
// now start the partial refund with a custom amount
refundManager.partialAmountRefund(2, REFUND_DESCRIPTION);

cy.wait(5000); // wait for the page to reload

adminOrders.openRefundManager();

// -------------------------------------------------------------------------------

repoRefundManager.getFirstRefundStatusLabel().contains('Pending');
Expand Down Expand Up @@ -188,6 +202,10 @@ context("Order Refunds", () => {
// now start the full refund
refundManager.fullRefund(REFUND_DESCRIPTION, '');

cy.wait(5000); // wait for the page to reload

adminOrders.openRefundManager();

// verify that our refund now exists
repoRefundManager.getFirstRefundStatusLabel().contains('Pending');
repoRefundManager.getFirstRefundPublicDescriptionLabel().contains(REFUND_DESCRIPTION);
Expand All @@ -204,6 +222,10 @@ context("Order Refunds", () => {
// now start another full refund
refundManager.fullRefund(REFUND_DESCRIPTION, '');

cy.wait(5000); // wait for the page to reload

adminOrders.openRefundManager();

cy.contains(CANCELED_REFUND_STATUS_LABEL).should('not.exist');

// second cancel should clear the history
Expand Down
Loading