commercetools-node-mock
commercetools-node-mock copied to clipboard
Add missing addParcelToDelivery order update action
This PR implements the missing addParcelToDelivery order update action in the commercetools mock library.
Changes Made
Implementation
- Added
OrderAddParcelToDeliveryActionimport andParceltype to order actions - Implemented
addParcelToDeliverymethod inOrderUpdateHandlerclass - Added support for all optional parcel properties:
parcelKey- User-defined unique identifiermeasurements- Parcel dimensions and weighttrackingData- Shipment tracking informationitems- Line items or custom line items in the parcelcustom- Custom fields for the parcel
Features
- Supports identification of target delivery by either
deliveryIdordeliveryKey - 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
createCustomFieldshelper
Testing
- Added comprehensive test cases covering successful scenarios with both
deliveryIdanddeliveryKey - 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.