@labdigital/commercetools-mock 2.34.2 → 2.34.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
- "version": "2.34.2",
3
+ "version": "2.34.3",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
@@ -0,0 +1,151 @@
1
+ import type { CartDraft, LineItem } from "@commercetools/platform-sdk";
2
+ import { describe, expect, test } from "vitest";
3
+ import { InMemoryStorage } from "~src/storage";
4
+ import { CartRepository } from "./index";
5
+
6
+ describe("Cart repository", () => {
7
+ const storage = new InMemoryStorage();
8
+ const repository = new CartRepository(storage);
9
+
10
+ test("create cart in store", async () => {
11
+ storage.add("dummy", "product", {
12
+ createdAt: "",
13
+ lastModifiedAt: "",
14
+ productType: {
15
+ typeId: "product-type",
16
+ id: "fake-product-type-id",
17
+ },
18
+ version: 1,
19
+ id: "15fc56ba-a74e-4cf8-b4b0-bada5c101541",
20
+ masterData: {
21
+ current: {
22
+ name: { "nl-NL": "Dummy" },
23
+ slug: { "nl-NL": "Dummy" },
24
+ categories: [],
25
+ masterVariant: {
26
+ sku: "MYSKU",
27
+ id: 1,
28
+ prices: [
29
+ {
30
+ id: "fake-price-id",
31
+ value: {
32
+ currencyCode: "EUR",
33
+ centAmount: 1000,
34
+ type: "centPrecision",
35
+ fractionDigits: 2,
36
+ },
37
+ country: "NL",
38
+ },
39
+ ],
40
+ },
41
+ variants: [],
42
+ searchKeywords: {},
43
+ },
44
+ published: false,
45
+ staged: {
46
+ name: { "nl-NL": "Dummy" },
47
+ slug: { "nl-NL": "Dummy" },
48
+ categories: [],
49
+ masterVariant: {
50
+ sku: "MYSKU",
51
+ id: 1,
52
+ prices: [
53
+ {
54
+ id: "fake-price-id",
55
+ value: {
56
+ currencyCode: "EUR",
57
+ centAmount: 1000,
58
+ type: "centPrecision",
59
+ fractionDigits: 2,
60
+ },
61
+ country: "NL",
62
+ },
63
+ ],
64
+ },
65
+ variants: [],
66
+ searchKeywords: {},
67
+ },
68
+ hasStagedChanges: false,
69
+ },
70
+ });
71
+
72
+ const cart: CartDraft = {
73
+ anonymousId: "1234567890",
74
+ billingAddress: {
75
+ id: "1234567890",
76
+ country: "NL",
77
+ firstName: "John",
78
+ lastName: "Doe",
79
+ streetName: "Main Street",
80
+ streetNumber: "123",
81
+ postalCode: "123456",
82
+ },
83
+ country: "NL",
84
+ currency: "EUR",
85
+ customerEmail: "john.doe@example.com",
86
+ customLineItems: [],
87
+ inventoryMode: "None",
88
+ itemShippingAddresses: [],
89
+ lineItems: [
90
+ {
91
+ id: "15fc56ba-a74e-4cf8-b4b0-bada5c101541",
92
+ sku: "MYSKU",
93
+ variantId: 1,
94
+ quantity: 1,
95
+ variant: {
96
+ prices: [
97
+ {
98
+ id: "fake-price-id",
99
+ value: {
100
+ currencyCode: "EUR",
101
+ centAmount: 1000,
102
+ type: "centPrecision",
103
+ fractionDigits: 2,
104
+ },
105
+ country: "NL",
106
+ },
107
+ ],
108
+ },
109
+ } as unknown as LineItem,
110
+ ],
111
+ origin: "Customer",
112
+ shipping: [],
113
+ shippingAddress: {
114
+ id: "1234567890",
115
+ country: "NL",
116
+ firstName: "John",
117
+ lastName: "Doe",
118
+ streetName: "Main Street",
119
+ streetNumber: "123",
120
+ postalCode: "123456",
121
+ },
122
+ shippingMode: "Single",
123
+ taxMode: "Platform",
124
+ taxRoundingMode: "HalfEven",
125
+ taxCalculationMode: "UnitPriceLevel",
126
+ };
127
+
128
+ const ctx = { projectKey: "dummy", storeKey: "dummyStore" };
129
+
130
+ const result = repository.create(ctx, cart);
131
+ expect(result.id).toBeDefined();
132
+
133
+ const items = repository.query(ctx);
134
+ expect(items.count).toBe(1);
135
+
136
+ expect(result.anonymousId).toEqual(cart.anonymousId);
137
+ expect(result.billingAddress).toEqual(cart.billingAddress);
138
+ expect(result.country).toEqual(cart.country);
139
+ expect(result.customerEmail).toEqual(cart.customerEmail);
140
+ expect(result.customerId).toEqual(cart.customerId);
141
+ expect(result.locale).toEqual(cart.locale);
142
+ expect(result.origin).toEqual(cart.origin);
143
+ expect(result.shipping).toEqual(cart.shipping);
144
+ expect(result.shippingAddress).toEqual(cart.shippingAddress);
145
+ expect(result.shippingMode).toEqual(cart.shippingMode);
146
+ expect(result.taxCalculationMode).toEqual(cart.taxCalculationMode);
147
+ expect(result.taxMode).toEqual(cart.taxMode);
148
+ expect(result.taxRoundingMode).toEqual(cart.taxRoundingMode);
149
+ expect(result.store?.key).toEqual(ctx.storeKey);
150
+ });
151
+ });
@@ -39,8 +39,13 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
39
39
 
40
40
  const resource: Writable<Cart> = {
41
41
  ...getBaseResourceProperties(),
42
+ anonymousId: draft.anonymousId,
43
+ billingAddress: draft.billingAddress
44
+ ? createAddress(draft.billingAddress, context.projectKey, this._storage)
45
+ : undefined,
42
46
  cartState: "Active",
43
47
  country: draft.country,
48
+ customerEmail: draft.customerEmail,
44
49
  customLineItems: [],
45
50
  directDiscounts: [],
46
51
  discountCodes: [],
@@ -58,11 +63,13 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
58
63
  fractionDigits: 0,
59
64
  },
60
65
  shippingMode: "Single",
61
- shippingAddress: createAddress(
62
- draft.shippingAddress,
63
- context.projectKey,
64
- this._storage,
65
- ),
66
+ shippingAddress: draft.shippingAddress
67
+ ? createAddress(
68
+ draft.shippingAddress,
69
+ context.projectKey,
70
+ this._storage,
71
+ )
72
+ : undefined,
66
73
  shipping: [],
67
74
  origin: draft.origin ?? "Customer",
68
75
  refusedGifts: [],
@@ -73,6 +80,9 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
73
80
  ),
74
81
  };
75
82
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
83
+ resource.store = context.storeKey
84
+ ? { typeId: "store", key: context.storeKey }
85
+ : undefined;
76
86
 
77
87
  return this.saveNew(context, resource);
78
88
  }