@labdigital/commercetools-mock 2.57.0 → 2.57.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/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { beforeEach } from "node:test";
|
|
1
2
|
import type {
|
|
2
3
|
Cart,
|
|
3
4
|
LineItem,
|
|
@@ -5,6 +6,7 @@ import type {
|
|
|
5
6
|
} from "@commercetools/platform-sdk";
|
|
6
7
|
import { describe, expect, test } from "vitest";
|
|
7
8
|
import type { Config } from "~src/config";
|
|
9
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
8
10
|
import { InMemoryStorage } from "~src/storage";
|
|
9
11
|
import { OrderRepository } from "./index";
|
|
10
12
|
|
|
@@ -16,6 +18,10 @@ describe("Order repository", () => {
|
|
|
16
18
|
};
|
|
17
19
|
const repository = new OrderRepository(config);
|
|
18
20
|
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
storage.clear();
|
|
23
|
+
});
|
|
24
|
+
|
|
19
25
|
test("create from cart", async () => {
|
|
20
26
|
const cart: Cart = {
|
|
21
27
|
id: "b3875a58-4ab2-4aaa-b399-184ce7561c27",
|
|
@@ -183,6 +189,88 @@ describe("Order repository", () => {
|
|
|
183
189
|
expect(result.store).toEqual(cart.store);
|
|
184
190
|
});
|
|
185
191
|
|
|
192
|
+
test("create order in store", async () => {
|
|
193
|
+
storage.add("dummy", "store", {
|
|
194
|
+
...getBaseResourceProperties(),
|
|
195
|
+
id: "store-123",
|
|
196
|
+
key: "testStore",
|
|
197
|
+
name: { "en-US": "Test Store" },
|
|
198
|
+
countries: [{ code: "NL" }],
|
|
199
|
+
languages: ["en-US"],
|
|
200
|
+
distributionChannels: [],
|
|
201
|
+
supplyChannels: [],
|
|
202
|
+
productSelections: [],
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
storage.add("dummy", "business-unit", {
|
|
206
|
+
...getBaseResourceProperties(),
|
|
207
|
+
id: "business-unit-123",
|
|
208
|
+
unitType: "Company",
|
|
209
|
+
key: "test-business-unit",
|
|
210
|
+
status: "Active",
|
|
211
|
+
storeMode: "Explicit",
|
|
212
|
+
name: "Test Business Unit",
|
|
213
|
+
addresses: [],
|
|
214
|
+
associateMode: "Explicit",
|
|
215
|
+
associates: [],
|
|
216
|
+
topLevelUnit: {
|
|
217
|
+
typeId: "business-unit",
|
|
218
|
+
key: "test-business-unit",
|
|
219
|
+
},
|
|
220
|
+
approvalRuleMode: "Explicit",
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
storage.add("dummy", "customer", {
|
|
224
|
+
...getBaseResourceProperties(),
|
|
225
|
+
id: "customer-123",
|
|
226
|
+
email: "test@example.com",
|
|
227
|
+
firstName: "John",
|
|
228
|
+
lastName: "Doe",
|
|
229
|
+
password: "hashed-password",
|
|
230
|
+
addresses: [],
|
|
231
|
+
defaultShippingAddressId: "",
|
|
232
|
+
defaultBillingAddressId: "",
|
|
233
|
+
customerNumber: "CUST-001",
|
|
234
|
+
externalId: "",
|
|
235
|
+
key: "test-customer",
|
|
236
|
+
stores: [],
|
|
237
|
+
isEmailVerified: true,
|
|
238
|
+
authenticationMode: "Password" as const,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const draft: OrderImportDraft = {
|
|
242
|
+
orderNumber: "100000002",
|
|
243
|
+
totalPrice: {
|
|
244
|
+
centAmount: 1000,
|
|
245
|
+
currencyCode: "EUR",
|
|
246
|
+
},
|
|
247
|
+
paymentState: "Paid",
|
|
248
|
+
customLineItems: [],
|
|
249
|
+
lineItems: [],
|
|
250
|
+
store: {
|
|
251
|
+
typeId: "store",
|
|
252
|
+
key: "testStore",
|
|
253
|
+
},
|
|
254
|
+
businessUnit: {
|
|
255
|
+
typeId: "business-unit",
|
|
256
|
+
key: "test-business-unit",
|
|
257
|
+
},
|
|
258
|
+
customerId: "customer-123",
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const ctx = { projectKey: "dummy", storeKey: "testStore" };
|
|
262
|
+
const result = repository.import(ctx, draft);
|
|
263
|
+
|
|
264
|
+
expect(result.orderNumber).toBe("100000002");
|
|
265
|
+
expect(result.store?.key).toBe("testStore");
|
|
266
|
+
expect(result.businessUnit?.key).toBe("test-business-unit");
|
|
267
|
+
expect(result.customerId).toBe("customer-123");
|
|
268
|
+
expect(result.totalPrice.centAmount).toBe(1000);
|
|
269
|
+
expect(result.totalPrice.currencyCode).toBe("EUR");
|
|
270
|
+
expect(result.orderState).toBe("Open");
|
|
271
|
+
expect(result.paymentState).toBe("Paid");
|
|
272
|
+
});
|
|
273
|
+
|
|
186
274
|
test("import exiting product", async () => {
|
|
187
275
|
storage.add("dummy", "product", {
|
|
188
276
|
id: "15fc56ba-a74e-4cf8-b4b0-bada5c101541",
|
|
@@ -120,6 +120,10 @@ export class OrderRepository extends AbstractResourceRepository<"order"> {
|
|
|
120
120
|
this._storage,
|
|
121
121
|
),
|
|
122
122
|
customerEmail: draft.customerEmail,
|
|
123
|
+
customerId: draft.customerId,
|
|
124
|
+
businessUnit: draft.businessUnit?.key
|
|
125
|
+
? { typeId: "business-unit", key: draft.businessUnit.key }
|
|
126
|
+
: undefined,
|
|
123
127
|
lastMessageSequenceNumber: 0,
|
|
124
128
|
orderNumber: draft.orderNumber,
|
|
125
129
|
orderState: draft.orderState || "Open",
|