From 39f3427efdb7704e2f323e7a88848deb92574a73 Mon Sep 17 00:00:00 2001 From: asafMasa Date: Thu, 28 Aug 2025 15:15:03 +0300 Subject: [PATCH 1/4] fix: enable update of metadata when same name is used in update parameters --- src/validator/validationManager.ts | 3 ++- .../metadata/metadataController.spec.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/validator/validationManager.ts b/src/validator/validationManager.ts index 122453a..bc7ea51 100644 --- a/src/validator/validationManager.ts +++ b/src/validator/validationManager.ts @@ -204,7 +204,8 @@ export class ValidationManager { if (payload.productName != undefined) { const records = await this.catalog.findRecords({ productName: payload.productName }); - if (records.length > 0) { + const differentRecordsWithSameName = records.filter((recordWithSameName) => recordWithSameName.id !== identifier); + if (differentRecordsWithSameName.length > 0) { refReason.outFailedReason = ERROR_METADATA_PRODUCT_NAME_UNIQUE!; return false; } diff --git a/tests/integration/metadata/metadataController.spec.ts b/tests/integration/metadata/metadataController.spec.ts index fe81b27..b5ed065 100644 --- a/tests/integration/metadata/metadataController.spec.ts +++ b/tests/integration/metadata/metadataController.spec.ts @@ -72,6 +72,25 @@ describe('MetadataController', function () { expect(response).toSatisfyApiSpec(); }); + it(`Should return 200 status code if record product name is my name (unique)`, async function () { + const identifier = faker.string.uuid(); + const payload = createUpdatePayload(); + const expected = createRecord(); + const record = createRecord(); + record.id = identifier + const linkUrl = extractLink(record.links); + await s3Helper.createFile(linkUrl, true); + mockAxios.get.mockResolvedValueOnce({ status: StatusCodes.OK, data: record }); + mockAxios.get.mockResolvedValueOnce({ data: [{ value: payload.classification }] as ILookupOption[] }); + mockAxios.post.mockResolvedValueOnce({ status: StatusCodes.OK, data: [record] }); + mockAxios.patch.mockResolvedValueOnce({ status: StatusCodes.OK, data: expected }); + + const response = await requestSender.updateMetadata(identifier, payload); + + expect(response.status).toBe(StatusCodes.OK); + expect(response).toSatisfyApiSpec(); + }); + it(`Should return 200 status code and metadata if payload is valid and footprint is 3D and pass footprint 2D to catalog`, async function () { const identifier = faker.string.uuid(); const payload = createUpdatePayload('Sphere'); From 3013f4ada4925bd5459b8f744dbf849da2f6e916 Mon Sep 17 00:00:00 2001 From: asafMasa Date: Thu, 28 Aug 2025 15:23:25 +0300 Subject: [PATCH 2/4] ci: update pull request workflow --- .github/workflows/pull_request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index c3a45da..53f37ed 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -4,7 +4,7 @@ on: [pull_request] jobs: pull_request: - uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v5.0.1 + uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v5.1.0 secrets: inherit with: openApiFilePath: './bundledApi.yaml' From 8792f6219020489fcefa6b5ca5651dbf80bbd399 Mon Sep 17 00:00:00 2001 From: asafMasa Date: Thu, 28 Aug 2025 15:28:03 +0300 Subject: [PATCH 3/4] chore: run lint fix --- tests/integration/metadata/metadataController.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/metadata/metadataController.spec.ts b/tests/integration/metadata/metadataController.spec.ts index b5ed065..d0fec96 100644 --- a/tests/integration/metadata/metadataController.spec.ts +++ b/tests/integration/metadata/metadataController.spec.ts @@ -77,7 +77,7 @@ describe('MetadataController', function () { const payload = createUpdatePayload(); const expected = createRecord(); const record = createRecord(); - record.id = identifier + record.id = identifier; const linkUrl = extractLink(record.links); await s3Helper.createFile(linkUrl, true); mockAxios.get.mockResolvedValueOnce({ status: StatusCodes.OK, data: record }); From 0c2040fa5869adc4b6ff78b58af842b327bb731a Mon Sep 17 00:00:00 2001 From: Asaf Masa Date: Sun, 31 Aug 2025 09:20:25 +0300 Subject: [PATCH 4/4] fix: fix update bug --- .github/workflows/pull_request.yaml | 2 +- src/validator/validationManager.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 53f37ed..40a5ef9 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -4,7 +4,7 @@ on: [pull_request] jobs: pull_request: - uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v5.1.0 + uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v4 secrets: inherit with: openApiFilePath: './bundledApi.yaml' diff --git a/src/validator/validationManager.ts b/src/validator/validationManager.ts index bc7ea51..2ea1829 100644 --- a/src/validator/validationManager.ts +++ b/src/validator/validationManager.ts @@ -204,8 +204,8 @@ export class ValidationManager { if (payload.productName != undefined) { const records = await this.catalog.findRecords({ productName: payload.productName }); - const differentRecordsWithSameName = records.filter((recordWithSameName) => recordWithSameName.id !== identifier); - if (differentRecordsWithSameName.length > 0) { + const differentRecordsWithSameNameExists = records.some((recordWithSameName) => recordWithSameName.id !== identifier); + if (differentRecordsWithSameNameExists) { refReason.outFailedReason = ERROR_METADATA_PRODUCT_NAME_UNIQUE!; return false; }