Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-pots-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": minor
---

Feat: takes store key from cart draft if not avaiable from context
10 changes: 10 additions & 0 deletions src/repositories/cart/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ describe("Cart repository", () => {
expect(result.shippingInfo?.taxRate?.name).toBe("Standard VAT");
});

test("create start with store from draft", () => {
const ctx = { projectKey: "dummy" };
const draft: CartDraft = {
currency: "USD",
store: { key: "draftStore", typeId: "store" },
};
const result = repository.create(ctx, draft);
expect(result.store).toEqual({ typeId: "store", key: "draftStore" });
});

test("create cart with business unit", async () => {
storage.add("dummy", "business-unit", {
...getBaseResourceProperties(),
Expand Down
4 changes: 3 additions & 1 deletion src/repositories/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
resource.store = context.storeKey
? { typeId: "store", key: context.storeKey }
: undefined;
: draft.store?.key
? { typeId: "store", key: draft.store.key }
: undefined;

// Set shipping info after resource is created
if (draft.shippingMethod) {
Expand Down
Loading