@labdigital/commercetools-mock 2.45.1 → 2.47.0

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.
Files changed (80) hide show
  1. package/dist/index.cjs +614 -250
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +788 -59
  4. package/dist/index.d.ts +788 -59
  5. package/dist/index.js +602 -238
  6. package/dist/index.js.map +1 -1
  7. package/package.json +41 -48
  8. package/src/ctMock.ts +11 -13
  9. package/src/index.test.ts +5 -5
  10. package/src/lib/predicateParser.test.ts +91 -60
  11. package/src/lib/predicateParser.ts +38 -42
  12. package/src/lib/productSearchFilter.test.ts +18 -0
  13. package/src/lib/productSearchFilter.ts +7 -0
  14. package/src/lib/projectionSearchFilter.test.ts +17 -17
  15. package/src/lib/projectionSearchFilter.ts +2 -3
  16. package/src/oauth/server.test.ts +1 -1
  17. package/src/oauth/server.ts +11 -11
  18. package/src/priceSelector.ts +1 -1
  19. package/src/product-projection-search.ts +18 -19
  20. package/src/product-search.ts +48 -8
  21. package/src/repositories/business-unit.ts +17 -16
  22. package/src/repositories/cart/actions.ts +32 -32
  23. package/src/repositories/cart/helpers.ts +1 -1
  24. package/src/repositories/cart/index.ts +25 -8
  25. package/src/repositories/cart-discount/actions.ts +1 -4
  26. package/src/repositories/category/actions.ts +2 -6
  27. package/src/repositories/custom-object.ts +20 -21
  28. package/src/repositories/customer/actions.ts +4 -4
  29. package/src/repositories/errors.ts +1 -1
  30. package/src/repositories/extension.ts +2 -1
  31. package/src/repositories/helpers.ts +27 -27
  32. package/src/repositories/index.ts +17 -17
  33. package/src/repositories/my-customer.ts +1 -1
  34. package/src/repositories/my-order.ts +2 -2
  35. package/src/repositories/order/index.ts +1 -1
  36. package/src/repositories/product/actions.ts +1 -1
  37. package/src/repositories/quote/actions.ts +83 -0
  38. package/src/repositories/quote/index.ts +54 -0
  39. package/src/repositories/quote-request/actions.ts +84 -0
  40. package/src/repositories/quote-request/index.test.ts +167 -0
  41. package/src/repositories/quote-request/index.ts +67 -0
  42. package/src/repositories/quote-staged/actions.ts +84 -0
  43. package/src/repositories/quote-staged/index.ts +47 -0
  44. package/src/repositories/review.ts +4 -4
  45. package/src/repositories/shipping-method/actions.ts +17 -17
  46. package/src/repositories/shipping-method/index.ts +6 -6
  47. package/src/repositories/shopping-list/actions.ts +1 -1
  48. package/src/repositories/shopping-list/index.ts +9 -1
  49. package/src/repositories/subscription.ts +2 -4
  50. package/src/server.ts +3 -2
  51. package/src/services/abstract.ts +7 -7
  52. package/src/services/as-associate-order.test.ts +1 -1
  53. package/src/services/cart-discount.test.ts +1 -1
  54. package/src/services/cart.test.ts +40 -15
  55. package/src/services/category.test.ts +1 -1
  56. package/src/services/customer.test.ts +16 -55
  57. package/src/services/customer.ts +1 -1
  58. package/src/services/index.ts +20 -14
  59. package/src/services/inventory-entry.test.ts +5 -5
  60. package/src/services/my-cart.test.ts +2 -2
  61. package/src/services/my-customer.test.ts +2 -2
  62. package/src/services/order.test.ts +8 -8
  63. package/src/services/product-projection.test.ts +5 -5
  64. package/src/services/product-projection.ts +12 -14
  65. package/src/services/product.test.ts +155 -71
  66. package/src/services/quote-request.test.ts +59 -0
  67. package/src/services/quote-request.ts +16 -0
  68. package/src/services/quote-staged.ts +16 -0
  69. package/src/services/quote.ts +16 -0
  70. package/src/services/standalone-price.test.ts +4 -4
  71. package/src/services/state.test.ts +1 -1
  72. package/src/services/store.test.ts +2 -2
  73. package/src/services/tax-category.test.ts +1 -1
  74. package/src/shipping.ts +3 -3
  75. package/src/storage/in-memory.ts +55 -63
  76. package/src/testing/customer.ts +40 -0
  77. package/src/types.ts +51 -31
  78. package/src/repositories/quote-request.ts +0 -17
  79. package/src/repositories/quote.ts +0 -14
  80. package/src/repositories/staged-quote.ts +0 -17
@@ -1,7 +1,9 @@
1
+ import assert from "node:assert";
1
2
  import type {
2
3
  Category,
3
4
  CategoryDraft,
4
5
  Image,
6
+ InventoryEntryDraft,
5
7
  PriceDraft,
6
8
  Product,
7
9
  ProductData,
@@ -18,9 +20,15 @@ import type {
18
20
  Type,
19
21
  TypeDraft,
20
22
  } from "@commercetools/platform-sdk";
21
- import assert from "assert";
22
23
  import supertest from "supertest";
23
- import { beforeAll, beforeEach, describe, expect, test } from "vitest";
24
+ import {
25
+ afterAll,
26
+ beforeAll,
27
+ beforeEach,
28
+ describe,
29
+ expect,
30
+ test,
31
+ } from "vitest";
24
32
  import { CommercetoolsMock } from "../index";
25
33
 
26
34
  const productTypeDraft: ProductTypeDraft = {
@@ -492,6 +500,10 @@ describe("Product update actions", () => {
492
500
  expect(response.status).toBe(201);
493
501
  });
494
502
 
503
+ afterAll(async () => {
504
+ ctMock.clear();
505
+ });
506
+
495
507
  test("setAttribute masterVariant (staged)", async () => {
496
508
  assert(productPublished, "product not created");
497
509
 
@@ -1488,76 +1500,148 @@ describe("Product update actions", () => {
1488
1500
  ?.myCustomField,
1489
1501
  ).toBe("MyRandomValue");
1490
1502
  });
1503
+ });
1491
1504
 
1492
- // Test the general product search implementation
1493
- describe("Product Search - Generic", () => {
1494
- test("Pagination", async () => {
1495
- {
1496
- const body: ProductSearchRequest = {
1497
- productProjectionParameters: {
1498
- storeProjection: "dummy-store",
1499
- localeProjection: ["en-US"],
1500
- priceCurrency: "EUR",
1501
- priceChannel: "dummy-channel",
1502
- expand: ["categories[*]", "categories[*].ancestors[*]"],
1503
- },
1504
- limit: 24,
1505
- };
1506
- const response = await supertest(ctMock.app)
1507
- .post("/dummy/products/search")
1508
- .send(body);
1509
-
1510
- const pagedSearchResponse: ProductPagedSearchResponse = response.body;
1511
- expect(pagedSearchResponse.limit).toBe(24);
1512
- expect(pagedSearchResponse.offset).toBe(0);
1513
- expect(pagedSearchResponse.total).toBeGreaterThan(0);
1514
-
1515
- // Deliberately not supported fow now
1516
- expect(pagedSearchResponse.facets).toEqual([]);
1517
-
1518
- const results: ProductSearchResult[] = pagedSearchResponse.results;
1519
- expect(results).toBeDefined();
1520
- expect(results.length).toBeGreaterThan(0);
1521
-
1522
- // Find product with sku "1337" to be part of the search results
1523
- const productFound = results.find(
1524
- (result) => result?.productProjection?.masterVariant?.sku === "1337",
1525
- );
1526
- expect(productFound).toBeDefined();
1527
-
1528
- const priceCurrencyMatch = results.find((result) =>
1529
- result?.productProjection?.masterVariant?.prices?.find(
1530
- (price) => price?.value?.currencyCode === "EUR",
1531
- ),
1532
- );
1533
- expect(priceCurrencyMatch).toBeDefined();
1534
- }
1535
- {
1536
- const body: ProductSearchRequest = {
1537
- limit: 88,
1538
- offset: 88,
1539
- };
1540
-
1541
- const response = await supertest(ctMock.app)
1542
- .post("/dummy/products/search")
1543
- .send(body);
1544
-
1545
- const pagedSearchResponse: ProductPagedSearchResponse = response.body;
1546
- expect(pagedSearchResponse.limit).toBe(88);
1547
- expect(pagedSearchResponse.offset).toBe(88);
1548
- expect(pagedSearchResponse.total).toBeGreaterThan(0);
1549
-
1550
- // No results, since we start at offset 88
1551
- const results: ProductSearchResult[] = pagedSearchResponse.results;
1552
- expect(results).toBeDefined();
1553
- expect(results.length).toBe(0);
1554
-
1555
- // Product with sku "1337" should not be part of the results
1556
- const productFound = results.find(
1557
- (result) => result?.productProjection?.masterVariant?.sku === "1337",
1558
- );
1559
- expect(productFound).toBeUndefined();
1560
- }
1505
+ // Test the general product search implementation
1506
+ describe("Product Search - Generic", () => {
1507
+ const ctMock = new CommercetoolsMock();
1508
+
1509
+ async function addInventoryEntry(sku: string, quantity: number) {
1510
+ const inventoryEntryDraft: InventoryEntryDraft = {
1511
+ key: `${sku}_stock`,
1512
+ sku,
1513
+ quantityOnStock: quantity,
1514
+ supplyChannel: {
1515
+ typeId: "channel",
1516
+ id: "dummy-inventory-channel",
1517
+ },
1518
+ };
1519
+
1520
+ await supertest(ctMock.app)
1521
+ .post("/dummy/inventory")
1522
+ .send(inventoryEntryDraft);
1523
+ }
1524
+
1525
+ beforeAll(async () => {
1526
+ await beforeAllProductTests(ctMock);
1527
+
1528
+ new Array(24).fill(null).forEach(async () => {
1529
+ const response = await supertest(ctMock.app)
1530
+ .post("/dummy/products")
1531
+ .send(publishedProductDraft);
1532
+
1533
+ expect(response.status).toBe(201);
1561
1534
  });
1562
1535
  });
1536
+
1537
+ test("Pagination", async () => {
1538
+ {
1539
+ const body: ProductSearchRequest = {
1540
+ productProjectionParameters: {
1541
+ storeProjection: "dummy-store",
1542
+ localeProjection: ["en-US"],
1543
+ priceCurrency: "EUR",
1544
+ priceChannel: "dummy-channel",
1545
+ expand: ["categories[*]", "categories[*].ancestors[*]"],
1546
+ },
1547
+ limit: 24,
1548
+ };
1549
+ const response = await supertest(ctMock.app)
1550
+ .post("/dummy/products/search")
1551
+ .send(body);
1552
+
1553
+ const pagedSearchResponse: ProductPagedSearchResponse = response.body;
1554
+ expect(pagedSearchResponse.limit).toBe(24);
1555
+ expect(pagedSearchResponse.offset).toBe(0);
1556
+ expect(pagedSearchResponse.total).toBeGreaterThan(0);
1557
+
1558
+ // Deliberately not supported fow now
1559
+ expect(pagedSearchResponse.facets).toEqual([]);
1560
+
1561
+ const results: ProductSearchResult[] = pagedSearchResponse.results;
1562
+ expect(results).toBeDefined();
1563
+ expect(results.length).toBeGreaterThan(0);
1564
+
1565
+ // Find product with sku "1337" to be part of the search results
1566
+ const productFound = results.find(
1567
+ (result) => result?.productProjection?.masterVariant?.sku === "1337",
1568
+ );
1569
+ expect(productFound).toBeDefined();
1570
+
1571
+ const priceCurrencyMatch = results.find((result) =>
1572
+ result?.productProjection?.masterVariant?.prices?.find(
1573
+ (price) => price?.value?.currencyCode === "EUR",
1574
+ ),
1575
+ );
1576
+ expect(priceCurrencyMatch).toBeDefined();
1577
+ }
1578
+ {
1579
+ const body: ProductSearchRequest = {
1580
+ limit: 88,
1581
+ offset: 88,
1582
+ };
1583
+
1584
+ const response = await supertest(ctMock.app)
1585
+ .post("/dummy/products/search")
1586
+ .send(body);
1587
+
1588
+ const pagedSearchResponse: ProductPagedSearchResponse = response.body;
1589
+ expect(pagedSearchResponse.limit).toBe(88);
1590
+ expect(pagedSearchResponse.offset).toBe(88);
1591
+ expect(pagedSearchResponse.total).toBeGreaterThan(0);
1592
+
1593
+ // No results, since we start at offset 88
1594
+ const results: ProductSearchResult[] = pagedSearchResponse.results;
1595
+ expect(results).toBeDefined();
1596
+ expect(results.length).toBe(0);
1597
+
1598
+ // Product with sku "1337" should not be part of the results
1599
+ const productFound = results.find(
1600
+ (result) => result?.productProjection?.masterVariant?.sku === "1337",
1601
+ );
1602
+ expect(productFound).toBeUndefined();
1603
+ }
1604
+ });
1605
+
1606
+ test("Filter on inventory", async () => {
1607
+ const body: ProductSearchRequest = {
1608
+ query: {
1609
+ exact: {
1610
+ field: "variants.availability.isOnStockForChannel",
1611
+ value: "dummy-inventory-channel",
1612
+ },
1613
+ },
1614
+ productProjectionParameters: {
1615
+ storeProjection: "dummy-store",
1616
+ localeProjection: ["en-US"],
1617
+ priceCurrency: "EUR",
1618
+ priceChannel: "dummy-channel",
1619
+ },
1620
+ limit: 1,
1621
+ };
1622
+
1623
+ const response1 = await supertest(ctMock.app)
1624
+ .post("/dummy/products/search")
1625
+ .send(body);
1626
+
1627
+ const pagedSearchResponse1: ProductPagedSearchResponse = response1.body;
1628
+
1629
+ expect(pagedSearchResponse1.results.length).toBe(0);
1630
+
1631
+ await addInventoryEntry(
1632
+ publishedProductDraft.variants?.[0]?.sku as string,
1633
+ 10,
1634
+ );
1635
+
1636
+ const response2 = await supertest(ctMock.app)
1637
+ .post("/dummy/products/search")
1638
+ .send(body);
1639
+
1640
+ const pagedSearchResponse2: ProductPagedSearchResponse = response2.body;
1641
+
1642
+ const productFound = pagedSearchResponse2.results.find(
1643
+ (result) => result?.productProjection?.masterVariant?.sku === "1337",
1644
+ );
1645
+ expect(productFound).toBeDefined();
1646
+ });
1563
1647
  });
@@ -0,0 +1,59 @@
1
+ import supertest from "supertest";
2
+ import { afterEach, describe, expect, it } from "vitest";
3
+ import { customerDraftFactory } from "~src/testing/customer";
4
+ import { CommercetoolsMock } from "../index";
5
+
6
+ describe("Quote Request Create", () => {
7
+ const ctMock = new CommercetoolsMock();
8
+
9
+ afterEach(() => {
10
+ ctMock.clear();
11
+ });
12
+
13
+ it("should create a quote request", async () => {
14
+ const customer = await customerDraftFactory(ctMock).create();
15
+ let response = await supertest(ctMock.app)
16
+ .post("/dummy/carts")
17
+ .send({
18
+ currency: "EUR",
19
+ customerId: customer.id,
20
+ custom: {
21
+ type: {
22
+ key: "my-cart",
23
+ },
24
+ fields: {
25
+ description: "example description",
26
+ },
27
+ },
28
+ });
29
+ expect(response.status).toBe(201);
30
+ const cart = response.body;
31
+
32
+ response = await supertest(ctMock.app)
33
+ .post("/dummy/quote-requests")
34
+ .send({
35
+ cart: {
36
+ typeId: "cart",
37
+ id: cart.id,
38
+ },
39
+ cartVersion: cart.version,
40
+ });
41
+ expect(response.status).toBe(201);
42
+ const quote = response.body;
43
+
44
+ expect(quote.cart).toEqual({
45
+ typeId: "cart",
46
+ id: cart.id,
47
+ });
48
+
49
+ response = await supertest(ctMock.app)
50
+ .get(`/dummy/quote-requests/${quote.id}`)
51
+ .send();
52
+
53
+ const quoteResult = response.body;
54
+ expect(quoteResult.cart).toEqual({
55
+ typeId: "cart",
56
+ id: cart.id,
57
+ });
58
+ });
59
+ });
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { QuoteRequestRepository } from "~src/repositories/quote-request";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class QuoteRequestService extends AbstractService {
6
+ public repository: QuoteRequestRepository;
7
+
8
+ constructor(parent: Router, repository: QuoteRequestRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "quote-requests";
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { StagedQuoteRepository } from "~src/repositories/quote-staged";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class StagedQuoteService extends AbstractService {
6
+ public repository: StagedQuoteRepository;
7
+
8
+ constructor(parent: Router, repository: StagedQuoteRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "staged-quotes";
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { QuoteRepository } from "~src/repositories/quote";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class QuoteService extends AbstractService {
6
+ public repository: QuoteRepository;
7
+
8
+ constructor(parent: Router, repository: QuoteRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "quotes";
15
+ }
16
+ }
@@ -120,7 +120,7 @@ describe("Standalone price Actions", () => {
120
120
 
121
121
  test("changeValue", async () => {
122
122
  const response = await supertest(ctMock.app)
123
- .post("/dummy/standalone-prices/" + id)
123
+ .post(`/dummy/standalone-prices/${id}`)
124
124
  .send({
125
125
  version: 1,
126
126
  actions: [
@@ -159,7 +159,7 @@ describe("Standalone price Actions", () => {
159
159
 
160
160
  test("setActive", async () => {
161
161
  const response = await supertest(ctMock.app)
162
- .post("/dummy/standalone-prices/" + id)
162
+ .post(`/dummy/standalone-prices/${id}`)
163
163
  .send({
164
164
  version: 1,
165
165
  actions: [
@@ -195,7 +195,7 @@ describe("Standalone price Actions", () => {
195
195
 
196
196
  test("setDiscounted", async () => {
197
197
  const response = await supertest(ctMock.app)
198
- .post("/dummy/standalone-prices/" + id)
198
+ .post(`/dummy/standalone-prices/${id}`)
199
199
  .send({
200
200
  version: 1,
201
201
  actions: [
@@ -250,7 +250,7 @@ describe("Standalone price Actions", () => {
250
250
  });
251
251
 
252
252
  const response2 = await supertest(ctMock.app)
253
- .post("/dummy/standalone-prices/" + id)
253
+ .post(`/dummy/standalone-prices/${id}`)
254
254
  .send({
255
255
  version: 2,
256
256
  actions: [
@@ -1,4 +1,4 @@
1
- import { type StateDraft } from "@commercetools/platform-sdk";
1
+ import type { StateDraft } from "@commercetools/platform-sdk";
2
2
  import supertest from "supertest";
3
3
  import { describe, expect, test } from "vitest";
4
4
  import { CommercetoolsMock } from "../index";
@@ -21,7 +21,7 @@ describe("Store", () => {
21
21
  });
22
22
 
23
23
  const response = await supertest(ctMock.app).get(
24
- `/dummy/stores/key=STOREKEY`,
24
+ "/dummy/stores/key=STOREKEY",
25
25
  );
26
26
 
27
27
  expect(response.status).toBe(200);
@@ -54,7 +54,7 @@ describe("Store", () => {
54
54
  });
55
55
 
56
56
  const response = await supertest(ctMock.app).get(
57
- `/dummy/stores/key=DOESNOTEXIST`,
57
+ "/dummy/stores/key=DOESNOTEXIST",
58
58
  );
59
59
 
60
60
  expect(response.status).toBe(404);
@@ -65,7 +65,7 @@ describe("Tax Category", () => {
65
65
  expect(createResponse.status).toBe(201);
66
66
 
67
67
  const response = await supertest(ctMock.app)
68
- .get(`/dummy/tax-categories/`)
68
+ .get("/dummy/tax-categories/")
69
69
  .query({ where: `key="${createResponse.body.key}"` });
70
70
 
71
71
  expect(response.status).toBe(200);
package/src/shipping.ts CHANGED
@@ -106,12 +106,12 @@ export const getShippingMethodsMatchingCart = (
106
106
  context.projectKey,
107
107
  "shipping-method",
108
108
  {
109
- "where": [
110
- `zoneRates(zone(id in (:zoneIds)))`,
109
+ where: [
110
+ "zoneRates(zone(id in (:zoneIds)))",
111
111
  `zoneRates(shippingRates(price(currencyCode="${cart.totalPrice.currencyCode}")))`,
112
112
  ],
113
113
  "var.zoneIds": zoneIds,
114
- "expand": params.expand,
114
+ expand: params.expand,
115
115
  },
116
116
  );
117
117
 
@@ -1,47 +1,47 @@
1
+ import assert from "node:assert";
1
2
  import type {
2
3
  InvalidJsonInputError,
3
4
  ReferencedResourceNotFoundError,
4
5
  ShoppingListLineItem,
5
6
  } from "@commercetools/platform-sdk";
6
- import {
7
- type AssociateRole,
8
- type AttributeGroup,
9
- type BusinessUnit,
10
- type Cart,
11
- type CartDiscount,
12
- type Category,
13
- type Channel,
14
- type CustomObject,
15
- type Customer,
16
- type CustomerGroup,
17
- type DiscountCode,
18
- type Extension,
19
- type InvalidInputError,
20
- type InventoryEntry,
21
- type Order,
22
- type PagedQueryResponse,
23
- type Payment,
24
- type Product,
25
- type ProductDiscount,
26
- type ProductProjection,
27
- type ProductTailoring,
28
- type ProductType,
29
- type Project,
30
- type Quote,
31
- type QuoteRequest,
32
- type Reference,
33
- type ResourceIdentifier,
34
- type ShippingMethod,
35
- type ShoppingList,
36
- type StagedQuote,
37
- type State,
38
- type Store,
39
- type Subscription,
40
- type TaxCategory,
41
- type Type,
42
- type Zone,
7
+ import type {
8
+ AssociateRole,
9
+ AttributeGroup,
10
+ BusinessUnit,
11
+ Cart,
12
+ CartDiscount,
13
+ Category,
14
+ Channel,
15
+ CustomObject,
16
+ Customer,
17
+ CustomerGroup,
18
+ DiscountCode,
19
+ Extension,
20
+ InvalidInputError,
21
+ InventoryEntry,
22
+ Order,
23
+ PagedQueryResponse,
24
+ Payment,
25
+ Product,
26
+ ProductDiscount,
27
+ ProductProjection,
28
+ ProductTailoring,
29
+ ProductType,
30
+ Project,
31
+ Quote,
32
+ QuoteRequest,
33
+ Reference,
34
+ ResourceIdentifier,
35
+ ShippingMethod,
36
+ ShoppingList,
37
+ StagedQuote,
38
+ State,
39
+ Store,
40
+ Subscription,
41
+ TaxCategory,
42
+ Type,
43
+ Zone,
43
44
  } from "@commercetools/platform-sdk";
44
- import assert from "assert";
45
45
  import { CommercetoolsError } from "~src/exceptions";
46
46
  import { cloneObject } from "../helpers";
47
47
  import { parseExpandClause } from "../lib/expandParser";
@@ -174,38 +174,38 @@ export class InMemoryStorage extends AbstractStorage {
174
174
  "associate-role": new Map<string, AssociateRole>(),
175
175
  "attribute-group": new Map<string, AttributeGroup>(),
176
176
  "business-unit": new Map<string, BusinessUnit>(),
177
- "cart": new Map<string, Cart>(),
177
+ cart: new Map<string, Cart>(),
178
178
  "cart-discount": new Map<string, CartDiscount>(),
179
- "category": new Map<string, Category>(),
180
- "channel": new Map<string, Channel>(),
181
- "customer": new Map<string, Customer>(),
179
+ category: new Map<string, Category>(),
180
+ channel: new Map<string, Channel>(),
181
+ customer: new Map<string, Customer>(),
182
182
  "customer-group": new Map<string, CustomerGroup>(),
183
183
  "discount-code": new Map<string, DiscountCode>(),
184
- "extension": new Map<string, Extension>(),
184
+ extension: new Map<string, Extension>(),
185
185
  "inventory-entry": new Map<string, InventoryEntry>(),
186
186
  "key-value-document": new Map<string, CustomObject>(),
187
- "order": new Map<string, Order>(),
187
+ order: new Map<string, Order>(),
188
188
  "order-edit": new Map<string, any>(),
189
- "payment": new Map<string, Payment>(),
190
- "product": new Map<string, Product>(),
191
- "quote": new Map<string, Quote>(),
189
+ payment: new Map<string, Payment>(),
190
+ product: new Map<string, Product>(),
191
+ quote: new Map<string, Quote>(),
192
192
  "quote-request": new Map<string, QuoteRequest>(),
193
193
  "product-discount": new Map<string, ProductDiscount>(),
194
194
  "product-selection": new Map<string, any>(),
195
195
  "product-type": new Map<string, ProductType>(),
196
196
  "product-projection": new Map<string, ProductProjection>(),
197
197
  "product-tailoring": new Map<string, ProductTailoring>(),
198
- "review": new Map<string, any>(),
198
+ review: new Map<string, any>(),
199
199
  "shipping-method": new Map<string, ShippingMethod>(),
200
200
  "staged-quote": new Map<string, StagedQuote>(),
201
- "state": new Map<string, State>(),
202
- "store": new Map<string, Store>(),
201
+ state: new Map<string, State>(),
202
+ store: new Map<string, Store>(),
203
203
  "shopping-list": new Map<string, ShoppingList>(),
204
204
  "standalone-price": new Map<string, any>(),
205
- "subscription": new Map<string, Subscription>(),
205
+ subscription: new Map<string, Subscription>(),
206
206
  "tax-category": new Map<string, TaxCategory>(),
207
- "type": new Map<string, Type>(),
208
- "zone": new Map<string, Zone>(),
207
+ type: new Map<string, Type>(),
208
+ zone: new Map<string, Zone>(),
209
209
  };
210
210
  }
211
211
  return projectStorage;
@@ -416,11 +416,7 @@ export class InMemoryStorage extends AbstractStorage {
416
416
 
417
417
  throw new CommercetoolsError<ReferencedResourceNotFoundError>({
418
418
  code: "ReferencedResourceNotFound",
419
- message:
420
- `The referenced object of type '${identifier.typeId}' with id ` +
421
- `'${identifier.id}' was not found. It either doesn't exist, or it ` +
422
- `can't be accessed from this endpoint (e.g., if the endpoint ` +
423
- `filters by store or customer account).`,
419
+ message: `The referenced object of type '${identifier.typeId}' with id '${identifier.id}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
424
420
  typeId: identifier.typeId,
425
421
  id: identifier.id,
426
422
  });
@@ -438,11 +434,7 @@ export class InMemoryStorage extends AbstractStorage {
438
434
 
439
435
  throw new CommercetoolsError<ReferencedResourceNotFoundError>({
440
436
  code: "ReferencedResourceNotFound",
441
- message:
442
- `The referenced object of type '${identifier.typeId}' with key ` +
443
- `'${identifier.key}' was not found. It either doesn't exist, or it ` +
444
- `can't be accessed from this endpoint (e.g., if the endpoint ` +
445
- `filters by store or customer account).`,
437
+ message: `The referenced object of type '${identifier.typeId}' with key '${identifier.key}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
446
438
  typeId: identifier.typeId,
447
439
  key: identifier.key,
448
440
  });
@@ -0,0 +1,40 @@
1
+ import type { Customer, CustomerDraft } from "@commercetools/platform-sdk";
2
+ import { Factory } from "fishery";
3
+ import supertest from "supertest";
4
+ import type { CommercetoolsMock } from "~src/ctMock";
5
+
6
+ export const customerDraftFactory = (m: CommercetoolsMock) =>
7
+ Factory.define<CustomerDraft, CustomerDraft, Customer>(({ onCreate }) => {
8
+ onCreate(async (draft) => {
9
+ const response = await supertest(m.app)
10
+ .post("/dummy/customers")
11
+ .send(draft);
12
+
13
+ return response.body.customer;
14
+ });
15
+
16
+ return {
17
+ email: "customer@example.com",
18
+ firstName: "John",
19
+ lastName: "Doe",
20
+ locale: "nl-NL",
21
+ password: "my-secret-pw",
22
+ addresses: [
23
+ {
24
+ firstName: "John",
25
+ lastName: "Doe",
26
+ streetName: "Street name",
27
+ streetNumber: "42",
28
+ postalCode: "1234 AB",
29
+ city: "Utrecht",
30
+ country: "NL",
31
+ company: "Lab Digital",
32
+ phone: "+31612345678",
33
+ email: "customer@example.com",
34
+ },
35
+ ],
36
+ isEmailVerified: false,
37
+ stores: [],
38
+ authenticationMode: "Password",
39
+ };
40
+ });