Skip to content

Commit 7948f69

Browse files
authored
feat: added additional project configuration options, added defaults (#333)
This pull request introduces several enhancements and updates to the project endpoints to better align with commercetools defaults, adds new configuration options, and updates dependencies. The main focus is on expanding the configurability and default values for project resources, especially around carts, shopping lists, and business units. **Project endpoint enhancements and configuration updates:** * Added support for configuring `priceRoundingMode` and `taxRoundingMode` in the `carts` object, including new update actions and default values. [[1]](diffhunk://#diff-8a1447b63ad4d4114de7dbab424c233fd7853b4411a3b893f9aa7193179a1e54R69-R82) [[2]](diffhunk://#diff-8a1447b63ad4d4114de7dbab424c233fd7853b4411a3b893f9aa7193179a1e54R105-R120) [[3]](diffhunk://#diff-5ba5f0356b6cd3a69be2ac6ebd1dd9abf7156c1c9c0b896644a68545b8e850c4R18-R19) [[4]](diffhunk://#diff-93a01d1904095ea8c898bef510a995ab54b7eb417d69d5b32aee964d20f3296fR83-R87) * Introduced `shoppingListsConfiguration` with default values and update actions, ensuring shopping lists have a default `deleteDaysAfterLastModification` value. [[1]](diffhunk://#diff-8a1447b63ad4d4114de7dbab424c233fd7853b4411a3b893f9aa7193179a1e54R69-R82) [[2]](diffhunk://#diff-5ba5f0356b6cd3a69be2ac6ebd1dd9abf7156c1c9c0b896644a68545b8e850c4R44-R51) [[3]](diffhunk://#diff-93a01d1904095ea8c898bef510a995ab54b7eb417d69d5b32aee964d20f3296fR83-R87) * Added support for configuring `businessUnits` search indexing status, including new update actions and default values. [[1]](diffhunk://#diff-8a1447b63ad4d4114de7dbab424c233fd7853b4411a3b893f9aa7193179a1e54R141-R153) [[2]](diffhunk://#diff-5ba5f0356b6cd3a69be2ac6ebd1dd9abf7156c1c9c0b896644a68545b8e850c4R44-R51) [[3]](diffhunk://#diff-93a01d1904095ea8c898bef510a995ab54b7eb417d69d5b32aee964d20f3296fR105-R107) **Repository and resource improvements:** * Set the default `isActive` property to `true` when creating new discount groups in `DiscountGroupRepository`. **Dependency updates:** * Upgraded `@commercetools/platform-sdk` from version 8.14.0 to 8.16.0 to ensure compatibility with new features and endpoints. **Changelog:** * Added a changeset documenting the additional features and updated project starting defaults for commercetools alignment.
1 parent 27c3980 commit 7948f69

File tree

8 files changed

+371
-216
lines changed

8 files changed

+371
-216
lines changed

.changeset/evil-moose-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": minor
3+
---
4+
5+
Added additional features to project endpoints, updated project starting defaults to align with commercetools

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/express": "^5.0.1",
4545
"@changesets/changelog-github": "0.5.1",
4646
"@changesets/cli": "2.28.1",
47-
"@commercetools/platform-sdk": "8.14.0",
47+
"@commercetools/platform-sdk": "8.16.0",
4848
"@types/basic-auth": "1.1.8",
4949
"@types/body-parser": "1.19.5",
5050
"@types/express-serve-static-core": "^5.0.6",
@@ -70,4 +70,4 @@
7070
"publishConfig": {
7171
"access": "public"
7272
}
73-
}
73+
}

pnpm-lock.yaml

Lines changed: 299 additions & 214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/repositories/discount-group/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class DiscountGroupRepository extends AbstractResourceRepository<"discoun
2323
name: draft.name,
2424
key: draft.key,
2525
sortOrder: draft.sortOrder,
26+
isActive: true,
2627
};
2728
return this.saveNew(context, resource);
2829
}

src/repositories/project.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
Project,
3+
ProjectChangeBusinessUnitSearchStatusAction,
34
ProjectChangeBusinessUnitStatusOnCreationAction,
45
ProjectChangeCartsConfigurationAction,
56
ProjectChangeCountriesAction,
@@ -10,7 +11,10 @@ import type {
1011
ProjectChangeMessagesConfigurationAction,
1112
ProjectChangeNameAction,
1213
ProjectChangeOrderSearchStatusAction,
14+
ProjectChangePriceRoundingModeAction,
1315
ProjectChangeProductSearchIndexingEnabledAction,
16+
ProjectChangeShoppingListsConfigurationAction,
17+
ProjectChangeTaxRoundingModeAction,
1418
ProjectSetExternalOAuthAction,
1519
ProjectSetShippingRateInputTypeAction,
1620
ProjectUpdateAction,
@@ -62,6 +66,20 @@ class ProjectUpdateHandler
6266
resource.carts = cartsConfiguration || {
6367
countryTaxRateFallbackEnabled: false,
6468
deleteDaysAfterLastModification: 90,
69+
priceRoundingMode: "HalfEven",
70+
taxRoundingMode: "HalfEven",
71+
};
72+
}
73+
74+
changeShoppingListsConfiguration(
75+
context: RepositoryContext,
76+
resource: Writable<Project>,
77+
{
78+
shoppingListsConfiguration,
79+
}: ProjectChangeShoppingListsConfigurationAction,
80+
) {
81+
resource.shoppingLists = shoppingListsConfiguration || {
82+
deleteDaysAfterLastModification: 90,
6583
};
6684
}
6785

@@ -84,6 +102,22 @@ class ProjectUpdateHandler
84102
countryTaxRateFallbackEnabled;
85103
}
86104

105+
changePriceRoundingMode(
106+
context: RepositoryContext,
107+
resource: Writable<Project>,
108+
{ priceRoundingMode }: ProjectChangePriceRoundingModeAction,
109+
) {
110+
resource.carts.priceRoundingMode = priceRoundingMode;
111+
}
112+
113+
changeTaxRoundingMode(
114+
context: RepositoryContext,
115+
resource: Writable<Project>,
116+
{ taxRoundingMode }: ProjectChangeTaxRoundingModeAction,
117+
) {
118+
resource.carts.taxRoundingMode = taxRoundingMode;
119+
}
120+
87121
changeCurrencies(
88122
context: RepositoryContext,
89123
resource: Writable<Project>,
@@ -104,6 +138,19 @@ class ProjectUpdateHandler
104138
resource.searchIndexing.customers.lastModifiedAt = new Date().toISOString();
105139
}
106140

141+
changeBusinessUnitSearchStatus(
142+
context: RepositoryContext,
143+
resource: Writable<Project>,
144+
{ status }: ProjectChangeBusinessUnitSearchStatusAction,
145+
) {
146+
if (!resource.searchIndexing?.businessUnits) {
147+
throw new Error("Invalid project state");
148+
}
149+
resource.searchIndexing.businessUnits.status = status;
150+
resource.searchIndexing.businessUnits.lastModifiedAt =
151+
new Date().toISOString();
152+
}
153+
107154
changeLanguages(
108155
context: RepositoryContext,
109156
resource: Writable<Project>,

src/services/discount-group.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("DiscountGroup", () => {
2727
createdAt: expect.anything(),
2828
id: expect.anything(),
2929
key: "premium-discount-group",
30+
isActive: true,
3031
lastModifiedAt: expect.anything(),
3132
name: {
3233
"en-GB": "Premium Discount Group",

src/services/project.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe("Project", () => {
1515
carts: {
1616
countryTaxRateFallbackEnabled: false,
1717
deleteDaysAfterLastModification: 90,
18+
priceRoundingMode: "HalfEven",
19+
taxRoundingMode: "HalfEven",
1820
},
1921
countries: [],
2022
createdAt: "2018-10-04T11:32:12.603Z",
@@ -39,8 +41,14 @@ describe("Project", () => {
3941
productsSearch: {
4042
status: "Deactivated",
4143
},
44+
businessUnits: {
45+
status: "Deactivated",
46+
},
4247
},
4348
trialUntil: "2018-12",
49+
shoppingLists: {
50+
deleteDaysAfterLastModification: 360,
51+
},
4452
} as Project);
4553
});
4654

src/storage/in-memory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export class InMemoryStorage extends AbstractStorage {
8080
carts: {
8181
countryTaxRateFallbackEnabled: false,
8282
deleteDaysAfterLastModification: 90,
83+
priceRoundingMode: "HalfEven",
84+
taxRoundingMode: "HalfEven",
85+
},
86+
shoppingLists: {
87+
deleteDaysAfterLastModification: 360,
8388
},
8489
messages: { enabled: false, deleteDaysAfterCreation: 15 },
8590
shippingRateInputType: undefined,
@@ -97,6 +102,9 @@ export class InMemoryStorage extends AbstractStorage {
97102
customers: {
98103
status: "Deactivated",
99104
},
105+
businessUnits: {
106+
status: "Deactivated",
107+
},
100108
},
101109
version: 1,
102110
};

0 commit comments

Comments
 (0)