@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.
- package/dist/index.cjs +614 -250
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +788 -59
- package/dist/index.d.ts +788 -59
- package/dist/index.js +602 -238
- package/dist/index.js.map +1 -1
- package/package.json +41 -48
- package/src/ctMock.ts +11 -13
- package/src/index.test.ts +5 -5
- package/src/lib/predicateParser.test.ts +91 -60
- package/src/lib/predicateParser.ts +38 -42
- package/src/lib/productSearchFilter.test.ts +18 -0
- package/src/lib/productSearchFilter.ts +7 -0
- package/src/lib/projectionSearchFilter.test.ts +17 -17
- package/src/lib/projectionSearchFilter.ts +2 -3
- package/src/oauth/server.test.ts +1 -1
- package/src/oauth/server.ts +11 -11
- package/src/priceSelector.ts +1 -1
- package/src/product-projection-search.ts +18 -19
- package/src/product-search.ts +48 -8
- package/src/repositories/business-unit.ts +17 -16
- package/src/repositories/cart/actions.ts +32 -32
- package/src/repositories/cart/helpers.ts +1 -1
- package/src/repositories/cart/index.ts +25 -8
- package/src/repositories/cart-discount/actions.ts +1 -4
- package/src/repositories/category/actions.ts +2 -6
- package/src/repositories/custom-object.ts +20 -21
- package/src/repositories/customer/actions.ts +4 -4
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.ts +2 -1
- package/src/repositories/helpers.ts +27 -27
- package/src/repositories/index.ts +17 -17
- package/src/repositories/my-customer.ts +1 -1
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order/index.ts +1 -1
- package/src/repositories/product/actions.ts +1 -1
- package/src/repositories/quote/actions.ts +83 -0
- package/src/repositories/quote/index.ts +54 -0
- package/src/repositories/quote-request/actions.ts +84 -0
- package/src/repositories/quote-request/index.test.ts +167 -0
- package/src/repositories/quote-request/index.ts +67 -0
- package/src/repositories/quote-staged/actions.ts +84 -0
- package/src/repositories/quote-staged/index.ts +47 -0
- package/src/repositories/review.ts +4 -4
- package/src/repositories/shipping-method/actions.ts +17 -17
- package/src/repositories/shipping-method/index.ts +6 -6
- package/src/repositories/shopping-list/actions.ts +1 -1
- package/src/repositories/shopping-list/index.ts +9 -1
- package/src/repositories/subscription.ts +2 -4
- package/src/server.ts +3 -2
- package/src/services/abstract.ts +7 -7
- package/src/services/as-associate-order.test.ts +1 -1
- package/src/services/cart-discount.test.ts +1 -1
- package/src/services/cart.test.ts +40 -15
- package/src/services/category.test.ts +1 -1
- package/src/services/customer.test.ts +16 -55
- package/src/services/customer.ts +1 -1
- package/src/services/index.ts +20 -14
- package/src/services/inventory-entry.test.ts +5 -5
- package/src/services/my-cart.test.ts +2 -2
- package/src/services/my-customer.test.ts +2 -2
- package/src/services/order.test.ts +8 -8
- package/src/services/product-projection.test.ts +5 -5
- package/src/services/product-projection.ts +12 -14
- package/src/services/product.test.ts +155 -71
- package/src/services/quote-request.test.ts +59 -0
- package/src/services/quote-request.ts +16 -0
- package/src/services/quote-staged.ts +16 -0
- package/src/services/quote.ts +16 -0
- package/src/services/standalone-price.test.ts +4 -4
- package/src/services/state.test.ts +1 -1
- package/src/services/store.test.ts +2 -2
- package/src/services/tax-category.test.ts +1 -1
- package/src/shipping.ts +3 -3
- package/src/storage/in-memory.ts +55 -63
- package/src/testing/customer.ts +40 -0
- package/src/types.ts +51 -31
- package/src/repositories/quote-request.ts +0 -17
- package/src/repositories/quote.ts +0 -14
- 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 {
|
|
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
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
253
|
+
.post(`/dummy/standalone-prices/${id}`)
|
|
254
254
|
.send({
|
|
255
255
|
version: 2,
|
|
256
256
|
actions: [
|
|
@@ -21,7 +21,7 @@ describe("Store", () => {
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
const response = await supertest(ctMock.app).get(
|
|
24
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
114
|
+
expand: params.expand,
|
|
115
115
|
},
|
|
116
116
|
);
|
|
117
117
|
|
package/src/storage/in-memory.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
177
|
+
cart: new Map<string, Cart>(),
|
|
178
178
|
"cart-discount": new Map<string, CartDiscount>(),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
184
|
+
extension: new Map<string, Extension>(),
|
|
185
185
|
"inventory-entry": new Map<string, InventoryEntry>(),
|
|
186
186
|
"key-value-document": new Map<string, CustomObject>(),
|
|
187
|
-
|
|
187
|
+
order: new Map<string, Order>(),
|
|
188
188
|
"order-edit": new Map<string, any>(),
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
198
|
+
review: new Map<string, any>(),
|
|
199
199
|
"shipping-method": new Map<string, ShippingMethod>(),
|
|
200
200
|
"staged-quote": new Map<string, StagedQuote>(),
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
205
|
+
subscription: new Map<string, Subscription>(),
|
|
206
206
|
"tax-category": new Map<string, TaxCategory>(),
|
|
207
|
-
|
|
208
|
-
|
|
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
|
+
});
|