Skip to content

Commit d2e5bf8

Browse files
authored
feat: store key from draft on cart create (#340)
1 parent a5cc7d7 commit d2e5bf8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.changeset/gentle-pots-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": minor
3+
---
4+
5+
Feat: takes store key from cart draft if not avaiable from context

src/repositories/cart/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ describe("Cart repository", () => {
286286
expect(result.shippingInfo?.taxRate?.name).toBe("Standard VAT");
287287
});
288288

289+
test("create start with store from draft", () => {
290+
const ctx = { projectKey: "dummy" };
291+
const draft: CartDraft = {
292+
currency: "USD",
293+
store: { key: "draftStore", typeId: "store" },
294+
};
295+
const result = repository.create(ctx, draft);
296+
expect(result.store).toEqual({ typeId: "store", key: "draftStore" });
297+
});
298+
289299
test("create cart with business unit", async () => {
290300
storage.add("dummy", "business-unit", {
291301
...getBaseResourceProperties(),

src/repositories/cart/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
153153
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
154154
resource.store = context.storeKey
155155
? { typeId: "store", key: context.storeKey }
156-
: undefined;
156+
: draft.store?.key
157+
? { typeId: "store", key: draft.store.key }
158+
: undefined;
157159

158160
// Set shipping info after resource is created
159161
if (draft.shippingMethod) {

0 commit comments

Comments
 (0)