From a17dcd55a71eafe2113f0f8edc988eda5b85c93c Mon Sep 17 00:00:00 2001 From: Thomas De Meyer Date: Tue, 22 Oct 2024 11:26:18 +0200 Subject: [PATCH 1/2] feat(project): added more support for project indexes --- .changeset/tough-bobcats-exercise.md | 5 ++++ package.json | 2 +- pnpm-lock.yaml | 34 ++++++++-------------------- src/repositories/project.ts | 27 +++++++++++++++++++++- src/storage/in-memory.ts | 6 +++++ 5 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 .changeset/tough-bobcats-exercise.md diff --git a/.changeset/tough-bobcats-exercise.md b/.changeset/tough-bobcats-exercise.md new file mode 100644 index 0000000..cb13d6a --- /dev/null +++ b/.changeset/tough-bobcats-exercise.md @@ -0,0 +1,5 @@ +--- +"@labdigital/commercetools-mock": minor +--- + +Added support for more search indexes on projects diff --git a/package.json b/package.json index 1d4a683..2adc8e3 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "devDependencies": { "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", - "@commercetools/platform-sdk": "7.11.0", + "@commercetools/platform-sdk": "7.17.0", "@stylistic/eslint-plugin": "^1.6.2", "@types/basic-auth": "^1.1.8", "@types/body-parser": "^1.19.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84e44e4..a5383a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -52,8 +52,8 @@ importers: specifier: ^2.27.1 version: 2.27.9 '@commercetools/platform-sdk': - specifier: 7.11.0 - version: 7.11.0 + specifier: 7.17.0 + version: 7.17.0 '@stylistic/eslint-plugin': specifier: ^1.6.2 version: 1.8.1(eslint@8.57.1)(typescript@5.6.2) @@ -248,8 +248,8 @@ packages: '@changesets/write@0.3.2': resolution: {integrity: sha512-kDxDrPNpUgsjDbWBvUo27PzKX4gqeKOlhibaOXDJA6kuBisGqNHv/HwGJrAu8U/dSf8ZEFIeHIPtvSlZI1kULw==} - '@commercetools/platform-sdk@7.11.0': - resolution: {integrity: sha512-8vlgiK6w8NewUZ60HUDJzdNUzDp2ByO+8fAH7aUTkt+suXYbG3Jl/k8brgX8JOn2AR4k7kC8g7sEHV6JUN8KzA==} + '@commercetools/platform-sdk@7.17.0': + resolution: {integrity: sha512-8W7STCwn1z+sJM0xraaRxA6SeQnHbfxOsVwBpKfQfWTEw1mK92WST+vVbLuZmRvsXNgvjuR8VwiI2n5wb/x7jw==} engines: {node: '>=14'} '@commercetools/sdk-client-v2@2.5.0': @@ -268,8 +268,8 @@ packages: resolution: {integrity: sha512-DhMXAA2yIch/AaGxy7st85Z1HFmeLtHWGkr9z5rX4xKjan4PHGB/IE5saAR+SNGHhs6+1Lp8vZEHDo3tFqVLmg==} engines: {node: '>=14'} - '@commercetools/ts-client@2.0.5': - resolution: {integrity: sha512-v1hdwMdyGV/ja+pdgTvnA/qLiZ67Zepbaj1WzucHa/ub9V78ZuezZTExTFKhSMFm5c+mMzLwq0UpacAYlu4nmA==} + '@commercetools/ts-client@2.1.0': + resolution: {integrity: sha512-xsZRMxSik24CcWuUclE4bjIArSkepGGcWkHbkp4HgORxstLPROeMo+1+vSSTigShQAm9CZeJvXe8cQc5zUtGhw==} engines: {node: '>=14'} '@cspotcode/source-map-support@0.8.1': @@ -1247,9 +1247,6 @@ packages: assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} - async-mutex@0.5.0: - resolution: {integrity: sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==} - asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} @@ -2975,10 +2972,6 @@ packages: resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==} engines: {node: '>= 0.4.0'} - uuid@10.0.0: - resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} - hasBin: true - uuid@9.0.1: resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} hasBin: true @@ -3344,13 +3337,13 @@ snapshots: human-id: 1.0.2 prettier: 2.8.8 - '@commercetools/platform-sdk@7.11.0': + '@commercetools/platform-sdk@7.17.0': dependencies: '@commercetools/sdk-client-v2': 2.5.0 '@commercetools/sdk-middleware-auth': 7.0.1 '@commercetools/sdk-middleware-http': 7.0.4 '@commercetools/sdk-middleware-logger': 3.0.0 - '@commercetools/ts-client': 2.0.5 + '@commercetools/ts-client': 2.1.0 transitivePeerDependencies: - encoding @@ -3371,13 +3364,10 @@ snapshots: '@commercetools/sdk-middleware-logger@3.0.0': {} - '@commercetools/ts-client@2.0.5': + '@commercetools/ts-client@2.1.0': dependencies: abort-controller: 3.0.0 - async-mutex: 0.5.0 - buffer: 6.0.3 node-fetch: 2.7.0 - uuid: 10.0.0 transitivePeerDependencies: - encoding @@ -4217,10 +4207,6 @@ snapshots: assertion-error@1.1.0: {} - async-mutex@0.5.0: - dependencies: - tslib: 2.7.0 - asynckit@0.4.0: {} available-typed-arrays@1.0.7: @@ -6007,8 +5993,6 @@ snapshots: utils-merge@1.0.1: {} - uuid@10.0.0: {} - uuid@9.0.1: {} v8-compile-cache-lib@3.0.1: {} diff --git a/src/repositories/project.ts b/src/repositories/project.ts index d193f89..e15b2f8 100644 --- a/src/repositories/project.ts +++ b/src/repositories/project.ts @@ -5,6 +5,7 @@ import type { ProjectChangeCountriesAction, ProjectChangeCountryTaxRateFallbackEnabledAction, ProjectChangeCurrenciesAction, + ProjectChangeCustomerSearchStatusAction, ProjectChangeLanguagesAction, ProjectChangeMessagesConfigurationAction, ProjectChangeNameAction, @@ -95,6 +96,18 @@ class ProjectUpdateHandler resource.currencies = currencies; } + changeCustomerSearchStatus( + context: RepositoryContext, + resource: Writable, + { status }: ProjectChangeCustomerSearchStatusAction, + ) { + if (!resource.searchIndexing?.customers) { + throw new Error("Invalid project state"); + } + resource.searchIndexing.customers.status = status; + resource.searchIndexing.customers.lastModifiedAt = new Date().toISOString(); + } + changeLanguages( context: RepositoryContext, resource: Writable, @@ -150,8 +163,20 @@ class ProjectUpdateHandler changeProductSearchIndexingEnabled( context: RepositoryContext, resource: Writable, - { enabled }: ProjectChangeProductSearchIndexingEnabledAction, + { enabled, mode }: ProjectChangeProductSearchIndexingEnabledAction, ) { + if (mode === "ProductsSearch") { + if (!resource.searchIndexing?.productsSearch) { + throw new Error("Invalid project state"); + } + resource.searchIndexing.productsSearch.status = enabled + ? "Activated" + : "Deactivated"; + resource.searchIndexing.productsSearch.lastModifiedAt = + new Date().toISOString(); + return; + } + if (!resource.searchIndexing?.products) { throw new Error("Invalid project state"); } diff --git a/src/storage/in-memory.ts b/src/storage/in-memory.ts index 944fb78..5969b26 100644 --- a/src/storage/in-memory.ts +++ b/src/storage/in-memory.ts @@ -87,9 +87,15 @@ export class InMemoryStorage extends AbstractStorage { products: { status: "Deactivated", }, + productsSearch: { + status: "Deactivated", + }, orders: { status: "Deactivated", }, + customers: { + status: "Deactivated", + }, }, version: 1, }; From 0b4d5b549e68c72db7f71b20c242c952b9e32211 Mon Sep 17 00:00:00 2001 From: Thomas De Meyer Date: Tue, 22 Oct 2024 11:31:17 +0200 Subject: [PATCH 2/2] feat(project): fixed tests --- src/services/project.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/services/project.test.ts b/src/services/project.test.ts index eb72d21..5792aab 100644 --- a/src/services/project.test.ts +++ b/src/services/project.test.ts @@ -39,12 +39,18 @@ describe("Project", () => { }, name: "", searchIndexing: { + customers: { + status: "Deactivated", + }, orders: { status: "Deactivated", }, products: { status: "Deactivated", }, + productsSearch: { + status: "Deactivated", + }, }, trialUntil: "2018-12", } as Project);