u
This commit is contained in:
@@ -84,8 +84,26 @@ async function run() {
|
||||
assert.equal(order.number, 'AU-1001');
|
||||
console.log('Order created:', order.number);
|
||||
|
||||
const carrier = await store.carrier.create(googleAuthId, {
|
||||
name: 'DHL',
|
||||
hasPackages: true,
|
||||
isReverse: false,
|
||||
});
|
||||
assert.equal(carrier.name, 'DHL');
|
||||
assert.equal(carrier.hasPackages, true);
|
||||
assert.equal(carrier.isReverse, false);
|
||||
const shipping = { carrierId: carrier.id, type: 'parcel', state: 'draft' };
|
||||
|
||||
// 0. Shipment without shipping is rejected
|
||||
await assert.rejects(
|
||||
() => store.shipment.create(googleAuthId, { orderId: order.id, lines: [{ sku: 'ITEM-A', amount: 1 }] }),
|
||||
{ message: 'Shipping is required' },
|
||||
);
|
||||
console.log('PASS: Shipment without shipping rejected');
|
||||
|
||||
// 1. Create Shipment 1: 6x Item A, 3x Item B -> AU-1001-L-1
|
||||
const shipment1 = await store.shipment.create(googleAuthId, {
|
||||
shipping,
|
||||
orderId: order.id,
|
||||
lines: [
|
||||
{ sku: 'ITEM-A', amount: 6 },
|
||||
@@ -100,6 +118,7 @@ async function run() {
|
||||
let ceilingErrorThrown = false;
|
||||
try {
|
||||
await store.shipment.create(googleAuthId, {
|
||||
shipping,
|
||||
orderId: order.id,
|
||||
lines: [{ sku: 'ITEM-A', amount: 5 }],
|
||||
});
|
||||
@@ -114,6 +133,7 @@ async function run() {
|
||||
let foreignArticleErrorThrown = false;
|
||||
try {
|
||||
await store.shipment.create(googleAuthId, {
|
||||
shipping,
|
||||
orderId: order.id,
|
||||
lines: [{ sku: 'ITEM-UNKNOWN', amount: 1 }],
|
||||
});
|
||||
@@ -126,6 +146,7 @@ async function run() {
|
||||
|
||||
// 3. Create Shipment 2: 4x Item A, 2x Item B -> AU-1001-L-2
|
||||
const shipment2 = await store.shipment.create(googleAuthId, {
|
||||
shipping,
|
||||
orderId: order.id,
|
||||
lines: [
|
||||
{ sku: 'ITEM-A', amount: 4 },
|
||||
@@ -140,6 +161,7 @@ async function run() {
|
||||
let exhaustedErrorThrown = false;
|
||||
try {
|
||||
await store.shipment.create(googleAuthId, {
|
||||
shipping,
|
||||
orderId: order.id,
|
||||
lines: [{ sku: 'ITEM-A', amount: 1 }],
|
||||
});
|
||||
@@ -150,16 +172,7 @@ async function run() {
|
||||
}
|
||||
assert.ok(exhaustedErrorThrown, 'Expected exhausted error to be thrown');
|
||||
|
||||
// 5. Add packages to Shipment 1 with tracking codes and carrier
|
||||
const carrier = await store.carrier.create(googleAuthId, {
|
||||
name: 'DHL',
|
||||
hasPackages: true,
|
||||
isReverse: false,
|
||||
});
|
||||
assert.equal(carrier.name, 'DHL');
|
||||
assert.equal(carrier.hasPackages, true);
|
||||
assert.equal(carrier.isReverse, false);
|
||||
|
||||
// 5. Add further packages to Shipment 1 with tracking codes
|
||||
const pkg1 = await store.shipping.create(googleAuthId, {
|
||||
manifestId: shipment1.id,
|
||||
carrierId: carrier.id,
|
||||
@@ -194,13 +207,13 @@ async function run() {
|
||||
// Check listByOrderId
|
||||
const orderShipments = await store.shipment.listByOrderId(googleAuthId, order.id);
|
||||
assert.equal(orderShipments.length, 2);
|
||||
assert.equal(orderShipments[0].shippings.length, 2);
|
||||
assert.equal(orderShipments[0].shippings.length, 3);
|
||||
console.log('PASS: store.shipment.listByOrderId returned both shipments');
|
||||
|
||||
// Check getById
|
||||
const fetchedShipment1 = await store.shipment.getById(googleAuthId, shipment1.id);
|
||||
assert.equal(fetchedShipment1.id, shipment1.id);
|
||||
assert.equal(fetchedShipment1.shippings.length, 2);
|
||||
assert.equal(fetchedShipment1.shippings.length, 3);
|
||||
console.log('PASS: store.shipment.getById returned shipment with shippings');
|
||||
|
||||
// 6. Transition Package 1 to shipped (should deduct ledger stock for Shipment 1 lines: 6 of Item A, 3 of Item B)
|
||||
@@ -253,6 +266,7 @@ async function run() {
|
||||
|
||||
// 9a. Ship ONE item (3x ITEM-A) via store.order.createShipment
|
||||
const shOne = await store.order.createShipment(googleAuthId, order2.id, {
|
||||
shipping,
|
||||
lines: [{ sku: 'ITEM-A', amount: 3 }],
|
||||
});
|
||||
assert.equal(shOne.number, 'AU-1002-L-1');
|
||||
@@ -268,6 +282,7 @@ async function run() {
|
||||
|
||||
// 9b. Ship SOME items with omitted amount (e.g. ITEM-A with no amount -> defaults to remaining 7)
|
||||
const shSome = await store.order.createShipment(googleAuthId, order2.id, {
|
||||
shipping,
|
||||
lines: [{ sku: 'ITEM-A' }],
|
||||
});
|
||||
assert.equal(shSome.number, 'AU-1002-L-2');
|
||||
@@ -282,7 +297,7 @@ async function run() {
|
||||
console.log('PASS: 9b. Shipped SOME items with omitted amount; ordersummary updated with shipped_quantity=10, is_shipped=0');
|
||||
|
||||
// 9c. Ship remaining items with explicit lines
|
||||
const shAll = await store.order.createShipment(googleAuthId, order2.id, { lines: [{ sku: 'ITEM-B', amount: 5 }] });
|
||||
const shAll = await store.order.createShipment(googleAuthId, order2.id, { shipping, lines: [{ sku: 'ITEM-B', amount: 5 }] });
|
||||
assert.equal(shAll.number, 'AU-1002-L-3');
|
||||
assert.equal(shAll.lines.length, 1);
|
||||
assert.equal(shAll.lines[0].sku, 'ITEM-B');
|
||||
|
||||
Reference in New Issue
Block a user