@labdigital/commercetools-mock 2.17.0 → 2.18.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 +4219 -3989
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +268 -415
- package/dist/index.d.ts +268 -415
- package/dist/index.js +4219 -3989
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +110 -67
- package/src/oauth/server.ts +161 -141
- package/src/oauth/store.ts +49 -44
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +75 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +31 -29
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +61 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +24 -24
- package/src/services/project.ts +17 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { SubscriptionRepository } from
|
|
3
|
-
import AbstractService from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { SubscriptionRepository } from "../repositories/subscription";
|
|
3
|
+
import AbstractService from "./abstract";
|
|
4
4
|
|
|
5
5
|
export class SubscriptionService extends AbstractService {
|
|
6
|
-
public repository: SubscriptionRepository
|
|
6
|
+
public repository: SubscriptionRepository;
|
|
7
7
|
|
|
8
8
|
constructor(parent: Router, repository: SubscriptionRepository) {
|
|
9
|
-
super(parent)
|
|
10
|
-
this.repository = repository
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
getBasePath() {
|
|
14
|
-
return
|
|
14
|
+
return "subscriptions";
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import type { TaxCategoryDraft } from
|
|
2
|
-
import supertest from
|
|
3
|
-
import { afterEach, describe, expect, test } from
|
|
4
|
-
import { CommercetoolsMock } from
|
|
1
|
+
import type { TaxCategoryDraft } from "@commercetools/platform-sdk";
|
|
2
|
+
import supertest from "supertest";
|
|
3
|
+
import { afterEach, describe, expect, test } from "vitest";
|
|
4
|
+
import { CommercetoolsMock } from "../index";
|
|
5
5
|
|
|
6
|
-
const ctMock = new CommercetoolsMock()
|
|
6
|
+
const ctMock = new CommercetoolsMock();
|
|
7
7
|
|
|
8
|
-
describe(
|
|
8
|
+
describe("Tax Category", () => {
|
|
9
9
|
afterEach(() => {
|
|
10
|
-
ctMock.clear()
|
|
11
|
-
})
|
|
12
|
-
test(
|
|
10
|
+
ctMock.clear();
|
|
11
|
+
});
|
|
12
|
+
test("Create tax category", async () => {
|
|
13
13
|
const draft: TaxCategoryDraft = {
|
|
14
|
-
name:
|
|
15
|
-
key:
|
|
14
|
+
name: "foo",
|
|
15
|
+
key: "standard",
|
|
16
16
|
rates: [],
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
const response = await supertest(ctMock.app)
|
|
19
|
-
.post(
|
|
20
|
-
.send(draft)
|
|
19
|
+
.post("/dummy/tax-categories")
|
|
20
|
+
.send(draft);
|
|
21
21
|
|
|
22
|
-
expect(response.status).toBe(201)
|
|
22
|
+
expect(response.status).toBe(201);
|
|
23
23
|
|
|
24
24
|
expect(response.body).toEqual({
|
|
25
25
|
createdAt: expect.anything(),
|
|
26
26
|
id: expect.anything(),
|
|
27
27
|
lastModifiedAt: expect.anything(),
|
|
28
|
-
name:
|
|
28
|
+
name: "foo",
|
|
29
29
|
rates: [],
|
|
30
|
-
key:
|
|
30
|
+
key: "standard",
|
|
31
31
|
version: 1,
|
|
32
|
-
})
|
|
33
|
-
})
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
34
|
|
|
35
|
-
test(
|
|
35
|
+
test("Get tax category", async () => {
|
|
36
36
|
const draft: TaxCategoryDraft = {
|
|
37
|
-
name:
|
|
38
|
-
key:
|
|
37
|
+
name: "foo",
|
|
38
|
+
key: "standard",
|
|
39
39
|
rates: [],
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
const createResponse = await supertest(ctMock.app)
|
|
42
|
-
.post(
|
|
43
|
-
.send(draft)
|
|
42
|
+
.post("/dummy/tax-categories")
|
|
43
|
+
.send(draft);
|
|
44
44
|
|
|
45
|
-
expect(createResponse.status).toBe(201)
|
|
45
|
+
expect(createResponse.status).toBe(201);
|
|
46
46
|
|
|
47
47
|
const response = await supertest(ctMock.app).get(
|
|
48
|
-
`/dummy/tax-categories/${createResponse.body.id}
|
|
49
|
-
)
|
|
48
|
+
`/dummy/tax-categories/${createResponse.body.id}`,
|
|
49
|
+
);
|
|
50
50
|
|
|
51
|
-
expect(response.status).toBe(200)
|
|
52
|
-
expect(response.body).toEqual(createResponse.body)
|
|
53
|
-
})
|
|
51
|
+
expect(response.status).toBe(200);
|
|
52
|
+
expect(response.body).toEqual(createResponse.body);
|
|
53
|
+
});
|
|
54
54
|
|
|
55
|
-
test(
|
|
55
|
+
test("Get tax category with key", async () => {
|
|
56
56
|
const draft: TaxCategoryDraft = {
|
|
57
|
-
name:
|
|
58
|
-
key:
|
|
57
|
+
name: "foo",
|
|
58
|
+
key: "standard",
|
|
59
59
|
rates: [],
|
|
60
|
-
}
|
|
60
|
+
};
|
|
61
61
|
const createResponse = await supertest(ctMock.app)
|
|
62
|
-
.post(
|
|
63
|
-
.send(draft)
|
|
62
|
+
.post("/dummy/tax-categories")
|
|
63
|
+
.send(draft);
|
|
64
64
|
|
|
65
|
-
expect(createResponse.status).toBe(201)
|
|
65
|
+
expect(createResponse.status).toBe(201);
|
|
66
66
|
|
|
67
67
|
const response = await supertest(ctMock.app)
|
|
68
68
|
.get(`/dummy/tax-categories/`)
|
|
69
|
-
.query({ where: `key="${createResponse.body.key}"` })
|
|
69
|
+
.query({ where: `key="${createResponse.body.key}"` });
|
|
70
70
|
|
|
71
|
-
expect(response.status).toBe(200)
|
|
71
|
+
expect(response.status).toBe(200);
|
|
72
72
|
expect(response.body).toEqual({
|
|
73
73
|
count: 1,
|
|
74
74
|
limit: 20,
|
|
75
75
|
offset: 0,
|
|
76
76
|
total: 1,
|
|
77
77
|
results: [createResponse.body],
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
})
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { TaxCategoryRepository } from
|
|
3
|
-
import AbstractService from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { TaxCategoryRepository } from "../repositories/tax-category";
|
|
3
|
+
import AbstractService from "./abstract";
|
|
4
4
|
|
|
5
5
|
export class TaxCategoryService extends AbstractService {
|
|
6
|
-
public repository: TaxCategoryRepository
|
|
6
|
+
public repository: TaxCategoryRepository;
|
|
7
7
|
|
|
8
8
|
constructor(parent: Router, repository: TaxCategoryRepository) {
|
|
9
|
-
super(parent)
|
|
10
|
-
this.repository = repository
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
getBasePath() {
|
|
14
|
-
return
|
|
14
|
+
return "tax-categories";
|
|
15
15
|
}
|
|
16
16
|
}
|
package/src/services/type.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { TypeRepository } from
|
|
3
|
-
import AbstractService from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { TypeRepository } from "../repositories/type";
|
|
3
|
+
import AbstractService from "./abstract";
|
|
4
4
|
|
|
5
5
|
export class TypeService extends AbstractService {
|
|
6
|
-
public repository: TypeRepository
|
|
6
|
+
public repository: TypeRepository;
|
|
7
7
|
|
|
8
8
|
constructor(parent: Router, repository: TypeRepository) {
|
|
9
|
-
super(parent)
|
|
10
|
-
this.repository = repository
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
getBasePath() {
|
|
14
|
-
return
|
|
14
|
+
return "types";
|
|
15
15
|
}
|
|
16
16
|
}
|
package/src/services/zone.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { ZoneRepository } from
|
|
3
|
-
import AbstractService from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { ZoneRepository } from "../repositories/zone";
|
|
3
|
+
import AbstractService from "./abstract";
|
|
4
4
|
|
|
5
5
|
export class ZoneService extends AbstractService {
|
|
6
|
-
public repository: ZoneRepository
|
|
6
|
+
public repository: ZoneRepository;
|
|
7
7
|
|
|
8
8
|
constructor(parent: Router, repository: ZoneRepository) {
|
|
9
|
-
super(parent)
|
|
10
|
-
this.repository = repository
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
getBasePath() {
|
|
14
|
-
return
|
|
14
|
+
return "zones";
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
Cart,
|
|
3
3
|
ShippingRate,
|
|
4
4
|
ShippingRatePriceTier,
|
|
5
|
-
} from
|
|
6
|
-
import { describe, expect, it } from
|
|
5
|
+
} from "@commercetools/platform-sdk";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
7
|
import {
|
|
8
8
|
markMatchingShippingRate,
|
|
9
9
|
markMatchingShippingRatePriceTiers,
|
|
10
|
-
} from
|
|
10
|
+
} from "./shippingCalculator";
|
|
11
11
|
|
|
12
12
|
// describe('markMatchingShippingMethods', () => {
|
|
13
13
|
// const zones: Record<string, Zone> = {
|
|
@@ -161,107 +161,107 @@ import {
|
|
|
161
161
|
// })
|
|
162
162
|
// })
|
|
163
163
|
|
|
164
|
-
describe(
|
|
164
|
+
describe("markMatchingShippingRate", () => {
|
|
165
165
|
const rate: ShippingRate = {
|
|
166
166
|
price: {
|
|
167
|
-
type:
|
|
168
|
-
currencyCode:
|
|
167
|
+
type: "centPrecision",
|
|
168
|
+
currencyCode: "EUR",
|
|
169
169
|
centAmount: 495,
|
|
170
170
|
fractionDigits: 2,
|
|
171
171
|
},
|
|
172
172
|
freeAbove: {
|
|
173
|
-
type:
|
|
174
|
-
currencyCode:
|
|
173
|
+
type: "centPrecision",
|
|
174
|
+
currencyCode: "USD",
|
|
175
175
|
centAmount: 5000,
|
|
176
176
|
fractionDigits: 2,
|
|
177
177
|
},
|
|
178
178
|
tiers: [],
|
|
179
|
-
}
|
|
179
|
+
};
|
|
180
180
|
|
|
181
|
-
it(
|
|
181
|
+
it("should mark the shipping rate as matching", () => {
|
|
182
182
|
const cart: Partial<Cart> = {
|
|
183
183
|
totalPrice: {
|
|
184
|
-
currencyCode:
|
|
184
|
+
currencyCode: "EUR",
|
|
185
185
|
centAmount: 1000,
|
|
186
186
|
fractionDigits: 2,
|
|
187
|
-
type:
|
|
187
|
+
type: "centPrecision",
|
|
188
188
|
},
|
|
189
|
-
}
|
|
189
|
+
};
|
|
190
190
|
|
|
191
|
-
const result = markMatchingShippingRate(cart as Cart, rate)
|
|
191
|
+
const result = markMatchingShippingRate(cart as Cart, rate);
|
|
192
192
|
expect(result).toMatchObject({
|
|
193
193
|
...rate,
|
|
194
194
|
isMatching: true,
|
|
195
|
-
})
|
|
196
|
-
})
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
197
|
|
|
198
|
-
it(
|
|
198
|
+
it("should mark the shipping rate as not matching", () => {
|
|
199
199
|
const cart: Partial<Cart> = {
|
|
200
200
|
totalPrice: {
|
|
201
|
-
currencyCode:
|
|
201
|
+
currencyCode: "USD",
|
|
202
202
|
centAmount: 1000,
|
|
203
203
|
fractionDigits: 2,
|
|
204
|
-
type:
|
|
204
|
+
type: "centPrecision",
|
|
205
205
|
},
|
|
206
|
-
}
|
|
206
|
+
};
|
|
207
207
|
|
|
208
|
-
const result = markMatchingShippingRate(cart as Cart, rate)
|
|
208
|
+
const result = markMatchingShippingRate(cart as Cart, rate);
|
|
209
209
|
expect(result).toMatchObject({
|
|
210
210
|
...rate,
|
|
211
211
|
isMatching: false,
|
|
212
|
-
})
|
|
213
|
-
})
|
|
214
|
-
})
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
215
|
|
|
216
|
-
describe(
|
|
217
|
-
it(
|
|
216
|
+
describe("markMatchingShippingRatePriceTiers", () => {
|
|
217
|
+
it("should handle CartValue types", () => {
|
|
218
218
|
const tiers: ShippingRatePriceTier[] = [
|
|
219
219
|
// Above 100 euro shipping is 4 euro
|
|
220
220
|
{
|
|
221
|
-
type:
|
|
221
|
+
type: "CartValue",
|
|
222
222
|
minimumCentAmount: 10000,
|
|
223
223
|
price: {
|
|
224
|
-
type:
|
|
225
|
-
currencyCode:
|
|
224
|
+
type: "centPrecision",
|
|
225
|
+
currencyCode: "EUR",
|
|
226
226
|
centAmount: 400,
|
|
227
227
|
fractionDigits: 2,
|
|
228
228
|
},
|
|
229
229
|
},
|
|
230
230
|
// Above 200 euro shipping is 3 euro
|
|
231
231
|
{
|
|
232
|
-
type:
|
|
232
|
+
type: "CartValue",
|
|
233
233
|
minimumCentAmount: 20000,
|
|
234
234
|
price: {
|
|
235
|
-
type:
|
|
236
|
-
currencyCode:
|
|
235
|
+
type: "centPrecision",
|
|
236
|
+
currencyCode: "EUR",
|
|
237
237
|
centAmount: 300,
|
|
238
238
|
fractionDigits: 2,
|
|
239
239
|
},
|
|
240
240
|
},
|
|
241
241
|
// Above 50 euro shipping is 5 euro
|
|
242
242
|
{
|
|
243
|
-
type:
|
|
243
|
+
type: "CartValue",
|
|
244
244
|
minimumCentAmount: 500,
|
|
245
245
|
price: {
|
|
246
|
-
type:
|
|
247
|
-
currencyCode:
|
|
246
|
+
type: "centPrecision",
|
|
247
|
+
currencyCode: "EUR",
|
|
248
248
|
centAmount: 700,
|
|
249
249
|
fractionDigits: 2,
|
|
250
250
|
},
|
|
251
251
|
},
|
|
252
|
-
]
|
|
252
|
+
];
|
|
253
253
|
|
|
254
254
|
// Create a cart with a total price of 90 euro
|
|
255
255
|
const cart: Partial<Cart> = {
|
|
256
256
|
totalPrice: {
|
|
257
|
-
currencyCode:
|
|
257
|
+
currencyCode: "EUR",
|
|
258
258
|
centAmount: 9000,
|
|
259
259
|
fractionDigits: 2,
|
|
260
|
-
type:
|
|
260
|
+
type: "centPrecision",
|
|
261
261
|
},
|
|
262
|
-
}
|
|
262
|
+
};
|
|
263
263
|
|
|
264
|
-
const result = markMatchingShippingRatePriceTiers(cart as Cart, tiers)
|
|
264
|
+
const result = markMatchingShippingRatePriceTiers(cart as Cart, tiers);
|
|
265
265
|
expect(result).toMatchObject([
|
|
266
266
|
{
|
|
267
267
|
minimumCentAmount: 10000,
|
|
@@ -275,6 +275,6 @@ describe('markMatchingShippingRatePriceTiers', () => {
|
|
|
275
275
|
minimumCentAmount: 500,
|
|
276
276
|
isMatching: true,
|
|
277
277
|
},
|
|
278
|
-
])
|
|
279
|
-
})
|
|
280
|
-
})
|
|
278
|
+
]);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
@@ -3,72 +3,72 @@ import {
|
|
|
3
3
|
CartValueTier,
|
|
4
4
|
ShippingRate,
|
|
5
5
|
ShippingRatePriceTier,
|
|
6
|
-
} from
|
|
6
|
+
} from "@commercetools/platform-sdk";
|
|
7
7
|
|
|
8
8
|
export const markMatchingShippingRate = (
|
|
9
9
|
cart: Cart,
|
|
10
|
-
shippingRate: ShippingRate
|
|
10
|
+
shippingRate: ShippingRate,
|
|
11
11
|
): ShippingRate => {
|
|
12
12
|
const isMatching =
|
|
13
|
-
shippingRate.price.currencyCode === cart.totalPrice.currencyCode
|
|
13
|
+
shippingRate.price.currencyCode === cart.totalPrice.currencyCode;
|
|
14
14
|
return {
|
|
15
15
|
...shippingRate,
|
|
16
16
|
tiers: markMatchingShippingRatePriceTiers(cart, shippingRate.tiers),
|
|
17
17
|
isMatching: isMatching,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
export const markMatchingShippingRatePriceTiers = (
|
|
22
22
|
cart: Cart,
|
|
23
|
-
tiers: ShippingRatePriceTier[]
|
|
23
|
+
tiers: ShippingRatePriceTier[],
|
|
24
24
|
): ShippingRatePriceTier[] => {
|
|
25
25
|
if (tiers.length === 0) {
|
|
26
|
-
return []
|
|
26
|
+
return [];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
if (new Set(tiers.map((tier) => tier.type)).size > 1) {
|
|
30
|
-
throw new Error("Can't handle multiple types of tiers")
|
|
30
|
+
throw new Error("Can't handle multiple types of tiers");
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const tierType = tiers[0].type
|
|
33
|
+
const tierType = tiers[0].type;
|
|
34
34
|
switch (tierType) {
|
|
35
|
-
case
|
|
36
|
-
return markMatchingCartValueTiers(cart, tiers as CartValueTier[])
|
|
35
|
+
case "CartValue":
|
|
36
|
+
return markMatchingCartValueTiers(cart, tiers as CartValueTier[]);
|
|
37
37
|
// case 'CartClassification':
|
|
38
38
|
// return markMatchingCartClassificationTiers(cart, tiers)
|
|
39
39
|
// case 'CartScore':
|
|
40
40
|
// return markMatchingCartScoreTiers(cart, tiers)
|
|
41
41
|
default:
|
|
42
|
-
throw new Error(`Unsupported tier type: ${tierType}`)
|
|
42
|
+
throw new Error(`Unsupported tier type: ${tierType}`);
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
|
|
46
46
|
const markMatchingCartValueTiers = (
|
|
47
47
|
cart: Cart,
|
|
48
|
-
tiers: readonly CartValueTier[]
|
|
48
|
+
tiers: readonly CartValueTier[],
|
|
49
49
|
): ShippingRatePriceTier[] => {
|
|
50
50
|
// Sort tiers from high to low since we only want to match the highest tier
|
|
51
51
|
const sortedTiers = [...tiers].sort(
|
|
52
|
-
(a, b) => b.minimumCentAmount - a.minimumCentAmount
|
|
53
|
-
)
|
|
52
|
+
(a, b) => b.minimumCentAmount - a.minimumCentAmount,
|
|
53
|
+
);
|
|
54
54
|
|
|
55
55
|
// Find the first tier that matches the cart and set the flag. We push
|
|
56
56
|
// the results into a map so that we can output the tiers in the same order as
|
|
57
57
|
// we received them.
|
|
58
|
-
const result: Record<number, ShippingRatePriceTier> = {}
|
|
59
|
-
let hasMatchingTier = false
|
|
58
|
+
const result: Record<number, ShippingRatePriceTier> = {};
|
|
59
|
+
let hasMatchingTier = false;
|
|
60
60
|
for (const tier of sortedTiers) {
|
|
61
61
|
const isMatching =
|
|
62
62
|
!hasMatchingTier &&
|
|
63
63
|
cart.totalPrice.currencyCode === tier.price.currencyCode &&
|
|
64
|
-
cart.totalPrice.centAmount >= tier.minimumCentAmount
|
|
64
|
+
cart.totalPrice.centAmount >= tier.minimumCentAmount;
|
|
65
65
|
|
|
66
|
-
if (isMatching) hasMatchingTier = true
|
|
66
|
+
if (isMatching) hasMatchingTier = true;
|
|
67
67
|
result[tier.minimumCentAmount] = {
|
|
68
68
|
...tier,
|
|
69
69
|
isMatching: isMatching,
|
|
70
|
-
}
|
|
70
|
+
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
return tiers.map((tier) => result[tier.minimumCentAmount])
|
|
74
|
-
}
|
|
73
|
+
return tiers.map((tier) => result[tier.minimumCentAmount]);
|
|
74
|
+
};
|
package/src/storage/abstract.ts
CHANGED
|
@@ -3,80 +3,82 @@ import type {
|
|
|
3
3
|
Project,
|
|
4
4
|
QueryParam,
|
|
5
5
|
ResourceIdentifier,
|
|
6
|
-
} from
|
|
7
|
-
import { PagedQueryResponseMap, ResourceMap, ResourceType } from
|
|
6
|
+
} from "@commercetools/platform-sdk";
|
|
7
|
+
import { PagedQueryResponseMap, ResourceMap, ResourceType } from "../types";
|
|
8
8
|
|
|
9
9
|
export type GetParams = {
|
|
10
|
-
expand?: string[]
|
|
11
|
-
}
|
|
10
|
+
expand?: string[];
|
|
11
|
+
};
|
|
12
12
|
|
|
13
13
|
export type QueryParams = {
|
|
14
|
-
expand?: string | string[]
|
|
15
|
-
sort?: string | string[]
|
|
16
|
-
limit?: number
|
|
17
|
-
offset?: number
|
|
18
|
-
withTotal?: boolean
|
|
19
|
-
where?: string | string[]
|
|
20
|
-
[key: string]: QueryParam
|
|
21
|
-
}
|
|
14
|
+
expand?: string | string[];
|
|
15
|
+
sort?: string | string[];
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
withTotal?: boolean;
|
|
19
|
+
where?: string | string[];
|
|
20
|
+
[key: string]: QueryParam;
|
|
21
|
+
};
|
|
22
22
|
|
|
23
23
|
export abstract class AbstractStorage {
|
|
24
|
-
abstract clear(): void
|
|
24
|
+
abstract clear(): void;
|
|
25
25
|
|
|
26
26
|
abstract all<RT extends ResourceType>(
|
|
27
27
|
projectKey: string,
|
|
28
|
-
typeId: RT
|
|
29
|
-
): Array<ResourceMap[RT]
|
|
28
|
+
typeId: RT,
|
|
29
|
+
): Array<ResourceMap[RT]>;
|
|
30
30
|
|
|
31
31
|
abstract add<RT extends ResourceType>(
|
|
32
32
|
projectKey: string,
|
|
33
33
|
typeId: RT,
|
|
34
|
-
obj: ResourceMap[RT]
|
|
35
|
-
):
|
|
34
|
+
obj: ResourceMap[RT],
|
|
35
|
+
): ResourceMap[RT];
|
|
36
36
|
|
|
37
37
|
abstract get<RT extends ResourceType>(
|
|
38
38
|
projectKey: string,
|
|
39
39
|
typeId: RT,
|
|
40
40
|
id: string,
|
|
41
|
-
params?: GetParams
|
|
42
|
-
): ResourceMap[RT] | null
|
|
41
|
+
params?: GetParams,
|
|
42
|
+
): ResourceMap[RT] | null;
|
|
43
43
|
|
|
44
44
|
abstract getByKey<RT extends ResourceType>(
|
|
45
45
|
projectKey: string,
|
|
46
46
|
typeId: RT,
|
|
47
47
|
key: string,
|
|
48
|
-
params: GetParams
|
|
49
|
-
): ResourceMap[RT] | null
|
|
48
|
+
params: GetParams,
|
|
49
|
+
): ResourceMap[RT] | null;
|
|
50
50
|
|
|
51
|
-
abstract addProject(projectKey: string): Project
|
|
52
|
-
|
|
53
|
-
abstract
|
|
51
|
+
abstract addProject(projectKey: string): Project;
|
|
52
|
+
|
|
53
|
+
abstract getProject(projectKey: string): Project;
|
|
54
|
+
|
|
55
|
+
abstract saveProject(project: Project): Project;
|
|
54
56
|
|
|
55
57
|
abstract delete<RT extends ResourceType>(
|
|
56
58
|
projectKey: string,
|
|
57
59
|
typeId: RT,
|
|
58
60
|
id: string,
|
|
59
|
-
params: GetParams
|
|
60
|
-
): ResourceMap[RT] | null
|
|
61
|
+
params: GetParams,
|
|
62
|
+
): ResourceMap[RT] | null;
|
|
61
63
|
|
|
62
64
|
abstract query<RT extends ResourceType>(
|
|
63
65
|
projectKey: string,
|
|
64
66
|
typeId: RT,
|
|
65
|
-
params: QueryParams
|
|
66
|
-
): PagedQueryResponseMap[RT]
|
|
67
|
+
params: QueryParams,
|
|
68
|
+
): PagedQueryResponseMap[RT];
|
|
67
69
|
|
|
68
70
|
abstract getByResourceIdentifier<RT extends ResourceType>(
|
|
69
71
|
projectKey: string,
|
|
70
|
-
identifier: ResourceIdentifier
|
|
71
|
-
): ResourceMap[RT]
|
|
72
|
+
identifier: ResourceIdentifier,
|
|
73
|
+
): ResourceMap[RT];
|
|
72
74
|
|
|
73
75
|
abstract expand<T>(
|
|
74
76
|
projectKey: string,
|
|
75
77
|
obj: T,
|
|
76
|
-
clause: undefined | string | string[]
|
|
77
|
-
): T
|
|
78
|
+
clause: undefined | string | string[],
|
|
79
|
+
): T;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export type ProjectStorage = {
|
|
81
|
-
[index in ResourceType]: Map<string, BaseResource
|
|
82
|
-
}
|
|
83
|
+
[index in ResourceType]: Map<string, BaseResource>;
|
|
84
|
+
};
|