@labdigital/commercetools-mock 2.56.0 → 2.56.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.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +1 -1
- package/src/repositories/cart/helpers.ts +7 -2
- package/src/repositories/cart/index.test.ts +5 -0
- package/src/repositories/cart/index.ts +1 -1
- package/src/services/cart.test.ts +5 -2
package/package.json
CHANGED
|
@@ -346,7 +346,7 @@ export class CartUpdateHandler
|
|
|
346
346
|
context.projectKey,
|
|
347
347
|
{ money, name, slug, quantity, taxCategory, custom, priceMode, key },
|
|
348
348
|
this._storage,
|
|
349
|
-
resource.country,
|
|
349
|
+
resource.shippingAddress?.country ?? resource.country,
|
|
350
350
|
);
|
|
351
351
|
|
|
352
352
|
resource.customLineItems.push(customLineItem);
|
|
@@ -150,7 +150,6 @@ export const createCustomLineItemFromDraft = (
|
|
|
150
150
|
)
|
|
151
151
|
: undefined;
|
|
152
152
|
|
|
153
|
-
// Get the tax category to calculate taxed price
|
|
154
153
|
let taxCategory: TaxCategory | undefined = undefined;
|
|
155
154
|
if (taxCategoryRef) {
|
|
156
155
|
try {
|
|
@@ -167,7 +166,6 @@ export const createCustomLineItemFromDraft = (
|
|
|
167
166
|
centAmount: (draft.money.centAmount ?? 0) * quantity,
|
|
168
167
|
});
|
|
169
168
|
|
|
170
|
-
// Calculate taxed price if tax category is available
|
|
171
169
|
const taxedPrice = taxCategory
|
|
172
170
|
? calculateTaxedPrice(
|
|
173
171
|
totalPrice.centAmount,
|
|
@@ -177,6 +175,12 @@ export const createCustomLineItemFromDraft = (
|
|
|
177
175
|
)
|
|
178
176
|
: undefined;
|
|
179
177
|
|
|
178
|
+
const taxRate = taxCategory
|
|
179
|
+
? taxCategory.rates.find(
|
|
180
|
+
(rate) => !rate.country || rate.country === country,
|
|
181
|
+
)
|
|
182
|
+
: undefined;
|
|
183
|
+
|
|
180
184
|
return {
|
|
181
185
|
id: uuidv4(),
|
|
182
186
|
key: draft.key,
|
|
@@ -186,6 +190,7 @@ export const createCustomLineItemFromDraft = (
|
|
|
186
190
|
quantity: draft.quantity ?? 1,
|
|
187
191
|
state: [],
|
|
188
192
|
taxCategory: taxCategoryRef,
|
|
193
|
+
taxRate,
|
|
189
194
|
taxedPrice,
|
|
190
195
|
custom: createCustomFields(draft.custom, projectKey, storage),
|
|
191
196
|
discountedPricePerQuantity: [],
|
|
@@ -293,5 +293,10 @@ describe("Cart repository", () => {
|
|
|
293
293
|
expect(customLineItem.taxedPrice?.totalTax?.centAmount).toBe(210);
|
|
294
294
|
expect(customLineItem.taxedPrice?.taxPortions).toHaveLength(1);
|
|
295
295
|
expect(customLineItem.taxedPrice?.taxPortions[0].rate).toBe(0.21);
|
|
296
|
+
expect(customLineItem.taxRate).toBeDefined();
|
|
297
|
+
expect(customLineItem.taxRate?.amount).toBe(0.21);
|
|
298
|
+
expect(customLineItem.taxRate?.name).toBe("Standard VAT");
|
|
299
|
+
expect(customLineItem.taxRate?.includedInPrice).toBe(false);
|
|
300
|
+
expect(customLineItem.taxRate?.country).toBe("NL");
|
|
296
301
|
});
|
|
297
302
|
});
|
|
@@ -116,6 +116,7 @@ describe("Cart Update Actions", () => {
|
|
|
116
116
|
const createCart = async (currency: string) => {
|
|
117
117
|
const response = await supertest(ctMock.app).post("/dummy/carts").send({
|
|
118
118
|
currency,
|
|
119
|
+
country: "NL",
|
|
119
120
|
});
|
|
120
121
|
expect(response.status).toBe(201);
|
|
121
122
|
cart = response.body;
|
|
@@ -653,11 +654,11 @@ describe("Cart Update Actions", () => {
|
|
|
653
654
|
.post(`/dummy/carts/${cart.id}`)
|
|
654
655
|
.send({
|
|
655
656
|
version: 1,
|
|
656
|
-
actions: [{ action: "setCountry", country: "
|
|
657
|
+
actions: [{ action: "setCountry", country: "BE" }],
|
|
657
658
|
});
|
|
658
659
|
expect(response.status).toBe(200);
|
|
659
660
|
expect(response.body.version).toBe(2);
|
|
660
|
-
expect(response.body.country).toBe("
|
|
661
|
+
expect(response.body.country).toBe("BE");
|
|
661
662
|
});
|
|
662
663
|
|
|
663
664
|
test("setDirectDiscounts", async () => {
|
|
@@ -1399,6 +1400,8 @@ describe("Cart Update Actions", () => {
|
|
|
1399
1400
|
expect(customLineItem.totalPrice.centAmount).toBe(1000);
|
|
1400
1401
|
expect(customLineItem.taxCategory.id).toBe(taxCategory.id);
|
|
1401
1402
|
expect(customLineItem.taxedPrice).toBeDefined();
|
|
1403
|
+
expect(customLineItem.taxRate).toBeDefined();
|
|
1404
|
+
expect(customLineItem.taxRate.amount).toBe(0.21);
|
|
1402
1405
|
expect(customLineItem.id).toBeDefined();
|
|
1403
1406
|
expect(customLineItem.custom).toBeDefined();
|
|
1404
1407
|
expect(customLineItem.custom.fields.description).toBe(
|