@labdigital/commercetools-mock 2.21.2 → 2.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +13 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +29 -0
- package/src/repositories/helpers.ts +1 -2
- package/src/repositories/order/index.ts +1 -0
- package/src/services/cart.test.ts +20 -0
package/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CartSetAnonymousIdAction,
|
|
3
|
+
CartSetCustomerIdAction,
|
|
2
4
|
CartUpdateAction,
|
|
3
5
|
type Address,
|
|
4
6
|
type AddressDraft,
|
|
@@ -6,6 +8,7 @@ import {
|
|
|
6
8
|
type CartAddItemShippingAddressAction,
|
|
7
9
|
type CartAddLineItemAction,
|
|
8
10
|
type CartChangeLineItemQuantityAction,
|
|
11
|
+
type CartChangeTaxRoundingModeAction,
|
|
9
12
|
type CartRemoveDiscountCodeAction,
|
|
10
13
|
type CartRemoveLineItemAction,
|
|
11
14
|
type CartSetBillingAddressAction,
|
|
@@ -227,6 +230,14 @@ export class CartUpdateHandler
|
|
|
227
230
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
228
231
|
}
|
|
229
232
|
|
|
233
|
+
changeTaxRoundingMode(
|
|
234
|
+
_context: RepositoryContext,
|
|
235
|
+
resource: Writable<Cart>,
|
|
236
|
+
{ taxRoundingMode }: CartChangeTaxRoundingModeAction,
|
|
237
|
+
) {
|
|
238
|
+
resource.taxRoundingMode = taxRoundingMode;
|
|
239
|
+
}
|
|
240
|
+
|
|
230
241
|
recalculate() {
|
|
231
242
|
// Dummy action when triggering a recalculation of the cart
|
|
232
243
|
//
|
|
@@ -281,6 +292,15 @@ export class CartUpdateHandler
|
|
|
281
292
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
282
293
|
}
|
|
283
294
|
|
|
295
|
+
setAnonymousId(
|
|
296
|
+
_context: RepositoryContext,
|
|
297
|
+
resource: Writable<Cart>,
|
|
298
|
+
{ anonymousId }: CartSetAnonymousIdAction,
|
|
299
|
+
) {
|
|
300
|
+
resource.anonymousId = anonymousId;
|
|
301
|
+
resource.customerId = undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
284
304
|
setBillingAddress(
|
|
285
305
|
context: RepositoryContext,
|
|
286
306
|
resource: Writable<Cart>,
|
|
@@ -309,6 +329,15 @@ export class CartUpdateHandler
|
|
|
309
329
|
resource.customerEmail = email;
|
|
310
330
|
}
|
|
311
331
|
|
|
332
|
+
setCustomerId(
|
|
333
|
+
_context: RepositoryContext,
|
|
334
|
+
resource: Writable<Cart>,
|
|
335
|
+
{ customerId }: CartSetCustomerIdAction,
|
|
336
|
+
) {
|
|
337
|
+
resource.anonymousId = undefined;
|
|
338
|
+
resource.customerId = customerId;
|
|
339
|
+
}
|
|
340
|
+
|
|
312
341
|
setCustomField(
|
|
313
342
|
context: RepositoryContext,
|
|
314
343
|
resource: Cart,
|
|
@@ -60,7 +60,6 @@ export const createCustomFields = (
|
|
|
60
60
|
if (!draft) return undefined;
|
|
61
61
|
if (!draft.type) return undefined;
|
|
62
62
|
if (!draft.type.typeId) return undefined;
|
|
63
|
-
if (!draft.fields) return undefined;
|
|
64
63
|
const typeResource = storage.getByResourceIdentifier(
|
|
65
64
|
projectKey,
|
|
66
65
|
draft.type,
|
|
@@ -77,7 +76,7 @@ export const createCustomFields = (
|
|
|
77
76
|
typeId: draft.type.typeId,
|
|
78
77
|
id: typeResource.id,
|
|
79
78
|
},
|
|
80
|
-
fields: draft.fields,
|
|
79
|
+
fields: draft.fields ?? {},
|
|
81
80
|
};
|
|
82
81
|
};
|
|
83
82
|
|
|
@@ -303,6 +303,26 @@ describe("Cart Update Actions", () => {
|
|
|
303
303
|
expect(response.body.lineItems).toHaveLength(0);
|
|
304
304
|
});
|
|
305
305
|
|
|
306
|
+
test("changeTaxRoundingMode", async () => {
|
|
307
|
+
assert(cart, "cart not created");
|
|
308
|
+
|
|
309
|
+
const response = await supertest(ctMock.app)
|
|
310
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
311
|
+
.send({
|
|
312
|
+
version: 1,
|
|
313
|
+
actions: [
|
|
314
|
+
{
|
|
315
|
+
action: "changeTaxRoundingMode",
|
|
316
|
+
taxRoundingMode: "HalfUp",
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(response.status).toBe(200);
|
|
322
|
+
expect(response.body.version).toBe(2);
|
|
323
|
+
expect(response.body.taxRoundingMode).toBe("HalfUp");
|
|
324
|
+
});
|
|
325
|
+
|
|
306
326
|
test("recalculate", async () => {
|
|
307
327
|
await supertest(ctMock.app)
|
|
308
328
|
.post(`/dummy/products`)
|