Skip to content

Add missing addParcelToDelivery order update action #309

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 15, 2025

This PR implements the missing addParcelToDelivery order update action in the commercetools mock library.

Changes Made

Implementation

  • Added OrderAddParcelToDeliveryAction import and Parcel type to order actions
  • Implemented addParcelToDelivery method in OrderUpdateHandler class
  • Added support for all optional parcel properties:
    • parcelKey - User-defined unique identifier
    • measurements - Parcel dimensions and weight
    • trackingData - Shipment tracking information
    • items - Line items or custom line items in the parcel
    • custom - Custom fields for the parcel

Features

  • Supports identification of target delivery by either deliveryId or deliveryKey
  • Proper validation with clear error messages for invalid inputs
  • Generates proper parcel objects with base resource properties (id, version, createdAt, etc.)
  • Integrates with existing custom fields handling via createCustomFields helper

Testing

  • Added comprehensive test cases covering successful scenarios with both deliveryId and deliveryKey
  • Tests all parcel properties (measurements, tracking data, items)
  • Includes error handling tests for missing delivery identifiers and non-existent deliveries
  • All existing tests continue to pass, ensuring no regressions

Example Usage

// Add a parcel to a delivery by ID
{
  action: "addParcelToDelivery",
  deliveryId: "delivery-123",
  parcelKey: "parcel-001",
  measurements: {
    heightInMillimeter: 100,
    lengthInMillimeter: 200,
    widthInMillimeter: 150,
    weightInGram: 500
  },
  trackingData: {
    trackingId: "TRACK123",
    carrier: "DHL"
  },
  items: [
    {
      id: "line-item-1",
      quantity: 1
    }
  ]
}

Fixes #284.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

changeset-bot bot commented Jul 15, 2025

🦋 Changeset detected

Latest commit: 08ad0e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@labdigital/commercetools-mock Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Copilot Copilot AI changed the title [WIP] add missing addParcelToDelivery to order updates Add missing addParcelToDelivery order update action Jul 15, 2025
@Copilot Copilot AI requested a review from mvantellingen July 15, 2025 05:35
Copilot finished work on behalf of mvantellingen July 15, 2025 05:35
@mvantellingen
Copy link
Member

@copilot the server should not return a 500 error when a parcel is not found, use CommercetoolsError to properly return a 4xx error. If you dont know, just use invalidinput for now.

Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

@copilot the server should not return a 500 error when a parcel is not found, use CommercetoolsError to properly return a 4xx error. If you dont know, just use invalidinput for now.

Fixed the error handling to use CommercetoolsError with InvalidInput code instead of regular Error. Now returns proper 4xx status codes (400) instead of 500. Commit: 2e4f9d7

Copilot finished work on behalf of mvantellingen July 15, 2025 05:57
@mvantellingen mvantellingen marked this pull request as ready for review July 15, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add missing addParcelToDelivery to order updates
2 participants