commercetools-node-mock icon indicating copy to clipboard operation
commercetools-node-mock copied to clipboard

Add missing addParcelToDelivery order update action

Open Copilot opened this issue 4 months ago • 3 comments

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.

Copilot avatar Jul 15 '25 05:07 Copilot