Skip to content

Commit

Permalink
feat: add changeTaxRoundingMode to cart mock (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
leongraumans authored Apr 30, 2024
1 parent 6c7317d commit 871e39a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-trains-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": patch
---

Add changeTaxRoundingMode to cart mock
9 changes: 9 additions & 0 deletions src/repositories/cart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type CartAddItemShippingAddressAction,
type CartAddLineItemAction,
type CartChangeLineItemQuantityAction,
type CartChangeTaxRoundingModeAction,
type CartRemoveDiscountCodeAction,
type CartRemoveLineItemAction,
type CartSetBillingAddressAction,
Expand Down Expand Up @@ -229,6 +230,14 @@ export class CartUpdateHandler
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
}

changeTaxRoundingMode(
_context: RepositoryContext,
resource: Writable<Cart>,
{ taxRoundingMode }: CartChangeTaxRoundingModeAction,
) {
resource.taxRoundingMode = taxRoundingMode;
}

recalculate() {
// Dummy action when triggering a recalculation of the cart
//
Expand Down
20 changes: 20 additions & 0 deletions src/services/cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ describe("Cart Update Actions", () => {
expect(response.body.lineItems).toHaveLength(0);
});

test("changeTaxRoundingMode", async () => {
assert(cart, "cart not created");

const response = await supertest(ctMock.app)
.post(`/dummy/carts/${cart.id}`)
.send({
version: 1,
actions: [
{
action: "changeTaxRoundingMode",
taxRoundingMode: "HalfUp",
},
],
});

expect(response.status).toBe(200);
expect(response.body.version).toBe(2);
expect(response.body.taxRoundingMode).toBe("HalfUp");
});

test("recalculate", async () => {
await supertest(ctMock.app)
.post(`/dummy/products`)
Expand Down

0 comments on commit 871e39a

Please sign in to comment.