From fcef9765b6a0cf487f366b7cda96327ae8d74b74 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 11:08:38 +0100 Subject: [PATCH 01/77] Renaming --- packages/catalog-process/test/db.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 47e265d4c3..c787b0f37e 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -597,7 +597,7 @@ describe("database test", async () => { expect(writtenPayload.eServiceDescriptor).toEqual(expectedDescriptorV1); }); - it("should throw an eServiceNotFound if the eService doesn't exist", async () => { + it("should throw eServiceNotFound if the eService doesn't exist", async () => { await expect( catalogService.publishDescriptor( mockEService.id, From 57789f5ba05b6c8ae5ad02b58dd57c596fcf1c5d Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 12:16:39 +0100 Subject: [PATCH 02/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 169 +++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index c787b0f37e..d493955249 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -39,6 +39,7 @@ import { draftDescriptorAlreadyExists, eServiceCannotBeDeleted, eServiceCannotBeUpdated, + eServiceDescriptorNotFound, eServiceDescriptorWithoutInterface, eServiceDuplicate, eServiceNotFound, @@ -457,6 +458,41 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.updateDescriptor( + mockEService.id, + mockDescriptor.id, + buildDescriptorSeed(mockDescriptor), + getMockAuthData(mockEService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in published state", () => { + expect(1).toBe(1); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in deprecated state", () => { + expect(1).toBe(1); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in suspended state", () => { + expect(1).toBe(1); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in archived state", () => { + expect(1).toBe(1); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, @@ -607,6 +643,10 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); + it("TO DO should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + expect(1).toBe(1); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, @@ -647,6 +687,18 @@ describe("database test", async () => { ); }); + it("TO DO should throw notValidDescriptor if the descriptor is in deprecated state", () => { + expect(1).toBe(1); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in suspended state", () => { + expect(1).toBe(1); + }); + + it("TO DO should throw notValidDescriptor if the descriptor is in archived state", () => { + expect(1).toBe(1); + }); + it("should throw eServiceDescriptorWithoutInterface if the descriptor doesn't have an interface", async () => { const descriptor: Descriptor = { ...mockDescriptor, @@ -742,6 +794,10 @@ describe("database test", async () => { ).rejects.toThrowError(operationForbidden); }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { + expect(1).toBe(1); + }); + it("should throw notValidDescriptor if the descriptor is in draft state", async () => { const descriptor: Descriptor = { ...mockDescriptor, @@ -762,6 +818,48 @@ describe("database test", async () => { notValidDescriptor(descriptor.id, descriptorState.draft) ); }); + + it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.suspendDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.suspended) + ); + }); + + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.suspendDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); + }); }); describe("activate descriptor", () => { @@ -813,6 +911,10 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { + expect(1).toBe(1); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, @@ -852,6 +954,69 @@ describe("database test", async () => { notValidDescriptor(descriptor.id, descriptorState.draft) ); }); + + it("should throw notValidDescriptor if the descriptor is in published state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.published, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.activateDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.published) + ); + }); + + it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.activateDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.deprecated) + ); + }); + + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.activateDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); + }); }); describe("clone descriptor", () => { @@ -913,6 +1078,10 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { + expect(1).toBe(1); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, From 9fe891414405eb7e9f6478ea7f3183fb3cd43680 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 12:16:58 +0100 Subject: [PATCH 03/77] Use retrieveDescriptor --- packages/catalog-process/src/services/catalogService.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 22b9d821d3..318be90f0d 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -798,12 +798,7 @@ export function updateDescriptorLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + const descriptor = retrieveDescriptor(descriptorId, eService); if (descriptor.state !== descriptorState.draft) { throw notValidDescriptor(descriptorId, descriptor.state.toString()); From a64efaf67081d9d698f9ce7b61d4f43465516785 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 12:27:39 +0100 Subject: [PATCH 04/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 163 ++++++++++++++++++++--- 1 file changed, 147 insertions(+), 16 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index d493955249..5e5e92556d 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -477,20 +477,96 @@ describe("database test", async () => { ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in published state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in published state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.published, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.updateDescriptor( + eService.id, + descriptor.id, + buildDescriptorSeed(descriptor), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(mockDescriptor.id, descriptorState.published) + ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in deprecated state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.updateDescriptor( + eService.id, + descriptor.id, + buildDescriptorSeed(descriptor), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(mockDescriptor.id, descriptorState.deprecated) + ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in suspended state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.updateDescriptor( + eService.id, + descriptor.id, + buildDescriptorSeed(descriptor), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(mockDescriptor.id, descriptorState.suspended) + ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in archived state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.updateDescriptor( + eService.id, + descriptor.id, + buildDescriptorSeed(descriptor), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(mockDescriptor.id, descriptorState.archived) + ); }); it("should throw operationForbidden if the requester is not the producer", async () => { @@ -643,8 +719,21 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); - it("TO DO should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { - expect(1).toBe(1); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.publishDescriptor( + eService.id, + mockDescriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); }); it("should throw operationForbidden if the requester is not the producer", async () => { @@ -794,8 +883,22 @@ describe("database test", async () => { ).rejects.toThrowError(operationForbidden); }); - it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { - expect(1).toBe(1); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.suspendDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(mockEService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); }); it("should throw notValidDescriptor if the descriptor is in draft state", async () => { @@ -911,8 +1014,22 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); - it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { - expect(1).toBe(1); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.activateDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(mockEService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); }); it("should throw operationForbidden if the requester is not the producer", async () => { @@ -1078,8 +1195,22 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); - it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", () => { - expect(1).toBe(1); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.archiveDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(mockEService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); }); it("should throw operationForbidden if the requester is not the producer", async () => { From 0e46486676b1f5f500340046f383be82651cd010 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 12:37:36 +0100 Subject: [PATCH 05/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 63 +++++++++++++++++++++--- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 5e5e92556d..89c9b435c4 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -776,16 +776,67 @@ describe("database test", async () => { ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in deprecated state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.publishDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.deprecated) + ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in suspended state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.publishDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.suspended) + ); }); - it("TO DO should throw notValidDescriptor if the descriptor is in archived state", () => { - expect(1).toBe(1); + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.publishDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); }); it("should throw eServiceDescriptorWithoutInterface if the descriptor doesn't have an interface", async () => { From 6b6149708d53f23833f5f0ea5ae375d288f7052d Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 15 Jan 2024 13:10:26 +0100 Subject: [PATCH 06/77] Minor refactor --- .../src/services/catalogService.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 318be90f0d..241ff1e20c 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -569,12 +569,7 @@ export function uploadDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + retrieveDescriptor(descriptorId, eService); return toCreateEventEServiceDocumentAdded( eServiceId, @@ -614,9 +609,7 @@ export async function deleteDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); + const descriptor = retrieveDescriptor(descriptorId, eService); const document = ( descriptor ? [...descriptor.docs, descriptor.interface] : [] @@ -653,12 +646,7 @@ export async function updateDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + const descriptor = retrieveDescriptor(descriptorId, eService); const document = ( descriptor ? [...descriptor.docs, descriptor.interface] : [] From d94ed28980b46fd71fb391b44b186cad0caff1be Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 15 Jan 2024 13:10:40 +0100 Subject: [PATCH 07/77] Implement tests --- packages/catalog-process/test/db.test.ts | 248 ++++++++++++++++++++++- packages/catalog-process/test/utils.ts | 23 +++ 2 files changed, 266 insertions(+), 5 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 89c9b435c4..52092fee90 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -41,6 +41,7 @@ import { eServiceCannotBeUpdated, eServiceDescriptorNotFound, eServiceDescriptorWithoutInterface, + eServiceDocumentNotFound, eServiceDuplicate, eServiceNotFound, notValidDescriptor, @@ -50,10 +51,12 @@ import { addOneEService, addOneTenant, buildDescriptorSeed, + buildInterfaceSeed, decodeProtobufPayload, getMockAgreement, getMockAuthData, getMockDescriptor, + getMockDocument, getMockEService, getMockTenant, readLastEventByStreamId, @@ -61,6 +64,7 @@ import { const mockEService = getMockEService(); const mockDescriptor = getMockDescriptor(); +const mockDocument = getMockDocument(); describe("database test", async () => { let eservices: EServiceCollection; @@ -1188,9 +1192,52 @@ describe("database test", async () => { }); describe("clone descriptor", () => { - it("TO DO implement after understanding file manager", () => { + it("TO DO should write on event-store for the cloning of a descriptor", () => { expect(1).toBe(1); }); + it("should throw eServiceNotFound if the eService doesn't exist", () => { + expect( + catalogService.cloneDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData() + ) + ).rejects.toThrowError(eServiceNotFound(mockEService.id)); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.cloneDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData() + ) + ).rejects.toThrowError(operationForbidden); + }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.cloneDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); }); describe("archive descriptor", () => { @@ -1267,7 +1314,7 @@ describe("database test", async () => { it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, - state: descriptorState.suspended, + state: descriptorState.draft, }; const eService: EService = { ...mockEService, @@ -1285,21 +1332,212 @@ describe("database test", async () => { }); describe("upload Document", () => { - it("TO DO implement after understanding file manager", () => { + it("TO DO should write on event-store for the upload of a document", () => { expect(1).toBe(1); }); + it("should throw eServiceNotFound if the eService doesn't exist", () => { + expect( + catalogService.uploadDocument( + mockEService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData() + ) + ).rejects.toThrowError(eServiceNotFound(mockEService.id)); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.uploadDocument( + eService.id, + descriptor.id, + buildInterfaceSeed(), + getMockAuthData() + ) + ).rejects.toThrowError(operationForbidden); + }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); }); describe("delete Document", () => { - it("TO DO implement after understanding file manager", () => { + it("TO DO should write on event-store for the deletion of a document", () => { expect(1).toBe(1); }); + it("should throw eServiceNotFound if the eService doesn't exist", async () => { + expect( + catalogService.deleteDocument( + mockEService.id, + mockDescriptor.id, + mockDocument.id, + getMockAuthData() + ) + ).rejects.toThrowError(eServiceNotFound(mockEService.id)); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData() + ) + ).rejects.toThrowError(operationForbidden); + }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.deleteDocument( + eService.id, + mockDescriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); + it("should throw eServiceDocumentNotFound if the document doesn't exist", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDocumentNotFound(eService.id, descriptor.id, mockDocument.id) + ); + }); }); describe("update Document", () => { - it("TO DO implement after understanding file manager", () => { + it("TO DO should write on event-store for the update of a document", () => { expect(1).toBe(1); }); + it("should throw eServiceNotFound if the eService doesn't exist", async () => { + expect( + catalogService.updateDocument( + mockEService.id, + mockDescriptor.id, + mockDocument.id, + { prettyName: "updated prettyName" }, + getMockAuthData() + ) + ).rejects.toThrowError(eServiceNotFound(mockEService.id)); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + descriptor.id, + mockDocument.id, + { prettyName: "updated prettyName" }, + getMockAuthData() + ) + ).rejects.toThrowError(operationForbidden); + }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + mockDescriptor.id, + uuidv4(), + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); + it("should throw eServiceDocumentNotFound if the document doesn't exist", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + descriptor.id, + mockDocument.id, + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + eServiceDocumentNotFound(eService.id, descriptor.id, mockDocument.id) + ); + }); }); }); diff --git a/packages/catalog-process/test/utils.ts b/packages/catalog-process/test/utils.ts index 4abc10dbb1..08630e69aa 100644 --- a/packages/catalog-process/test/utils.ts +++ b/packages/catalog-process/test/utils.ts @@ -9,6 +9,7 @@ import { v4 as uuidv4 } from "uuid"; import { Agreement, Descriptor, + Document, EService, EServiceEvent, Tenant, @@ -20,6 +21,7 @@ import { import { MessageType } from "@protobuf-ts/runtime"; import { toEServiceV1 } from "../src/model/domain/toEvent.js"; import { EServiceDescriptorSeed } from "../src/model/domain/models.js"; +import { ApiEServiceDescriptorDocumentSeed } from "../src/model/types.js"; export const writeEServiceInEventstore = async ( eService: EService, @@ -139,6 +141,27 @@ export const getMockDescriptor = (): Descriptor => ({ }, }); +export const buildInterfaceSeed = (): ApiEServiceDescriptorDocumentSeed => ({ + contentType: "json", + prettyName: "prettyName", + serverUrls: ["pagopa.it"], + documentId: "string", + kind: "INTERFACE", + filePath: "filePath", + fileName: "fileName", + checksum: "checksum", +}); + +export const getMockDocument = (): Document => ({ + name: "document name", + path: "document path", + id: uuidv4(), + prettyName: "pretty name", + contentType: "json", + checksum: uuidv4(), + uploadDate: new Date(), +}); + export const getMockTenant = (): Tenant => ({ name: "A tenant", id: uuidv4(), From ccd3fdc2a11fc5b1ff944df8b16f628d6c3031f6 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 16 Jan 2024 12:35:02 +0100 Subject: [PATCH 08/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 136 +++++++++++++++++++++-- 1 file changed, 126 insertions(+), 10 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 52092fee90..22df276f15 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable functional/no-let */ /* eslint-disable @typescript-eslint/no-floating-promises */ import { afterEach, beforeAll, describe, expect, it } from "vitest"; @@ -10,12 +11,16 @@ import { } from "pagopa-interop-commons"; import { IDatabase } from "pg-promise"; import { + ClonedEServiceAddedV1, Descriptor, EService, EServiceAddedV1, EServiceDeletedV1, EServiceDescriptorAddedV1, EServiceDescriptorUpdatedV1, + EServiceDocumentAddedV1, + EServiceDocumentDeletedV1, + EServiceDocumentUpdatedV1, EServiceUpdatedV1, EServiceWithDescriptorsDeletedV1, descriptorState, @@ -1192,8 +1197,36 @@ describe("database test", async () => { }); describe("clone descriptor", () => { - it("TO DO should write on event-store for the cloning of a descriptor", () => { - expect(1).toBe(1); + it("should write on event-store for the cloning of a descriptor", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + interface: getMockDocument(), + docs: [getMockDocument()], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + const newEService = await catalogService.cloneDescriptor( + eService.id, + descriptor.id, + getMockAuthData(eService.producerId) + ); + + const writtenEvent = await readLastEventByStreamId( + newEService.id, + postgresDB + ); + expect(writtenEvent.stream_id).toBe(newEService.id); + expect(writtenEvent.version).toBe("0"); + expect(writtenEvent.type).toBe("ClonedEServiceAdded"); + const writtenPayload = decodeProtobufPayload({ + messageType: ClonedEServiceAddedV1, + payload: writtenEvent.data, + }); + // TO DO check entire payload }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( @@ -1216,8 +1249,8 @@ describe("database test", async () => { await addOneEService(eService, postgresDB, eservices); expect( catalogService.cloneDescriptor( - mockEService.id, - mockDescriptor.id, + eService.id, + descriptor.id, getMockAuthData() ) ).rejects.toThrowError(operationForbidden); @@ -1332,8 +1365,36 @@ describe("database test", async () => { }); describe("upload Document", () => { - it("TO DO should write on event-store for the upload of a document", () => { - expect(1).toBe(1); + it("should write on event-store for the upload of a document", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + + await catalogService.uploadDocument( + eService.id, + descriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ); + + const writtenEvent = await readLastEventByStreamId( + eService.id, + postgresDB + ); + expect(writtenEvent.stream_id).toBe(eService.id); + expect(writtenEvent.version).toBe("1"); + expect(writtenEvent.type).toBe("EServiceDocumentAdded"); + const writtenPayload = decodeProtobufPayload({ + messageType: EServiceDocumentAddedV1, + payload: writtenEvent.data, + }); + // TO DO check entire payload }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( @@ -1385,8 +1446,35 @@ describe("database test", async () => { }); describe("delete Document", () => { - it("TO DO should write on event-store for the deletion of a document", () => { - expect(1).toBe(1); + it("should write on event-store for the deletion of a document", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + await catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ); + const writtenEvent = await readLastEventByStreamId( + eService.id, + postgresDB + ); + expect(writtenEvent.stream_id).toBe(eService.id); + expect(writtenEvent.version).toBe("1"); + expect(writtenEvent.type).toBe("EServiceDocumentDeleted"); + const writtenPayload = decodeProtobufPayload({ + messageType: EServiceDocumentDeletedV1, + payload: writtenEvent.data, + }); + // TO DO check entire payload }); it("should throw eServiceNotFound if the eService doesn't exist", async () => { expect( @@ -1462,8 +1550,36 @@ describe("database test", async () => { }); describe("update Document", () => { - it("TO DO should write on event-store for the update of a document", () => { - expect(1).toBe(1); + it("should write on event-store for the update of a document", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + await catalogService.updateDocument( + eService.id, + descriptor.id, + mockDocument.id, + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ); + const writtenEvent = await readLastEventByStreamId( + eService.id, + postgresDB + ); + expect(writtenEvent.stream_id).toBe(eService.id); + expect(writtenEvent.version).toBe("1"); + expect(writtenEvent.type).toBe("EServiceDocumentUpdated"); + const writtenPayload = decodeProtobufPayload({ + messageType: EServiceDocumentUpdatedV1, + payload: writtenEvent.data, + }); + // TO DO check entire payload }); it("should throw eServiceNotFound if the eService doesn't exist", async () => { expect( From 96daa0d4d65ff22334b2c839b980f11bc8096bda Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 16 Jan 2024 12:35:54 +0100 Subject: [PATCH 09/77] Add to do --- packages/catalog-process/test/db.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 22df276f15..34b3232a06 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-unused-vars */ // TO DO remove this line after all the tests are completed /* eslint-disable functional/no-let */ /* eslint-disable @typescript-eslint/no-floating-promises */ import { afterEach, beforeAll, describe, expect, it } from "vitest"; From 45ec14a23c3a2c47b84d8a3fedaf14539dbd4365 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 17 Jan 2024 13:49:05 +0100 Subject: [PATCH 10/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 208 ++++++++++++++++++++--- 1 file changed, 182 insertions(+), 26 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 1bd8188088..6a22abaa8f 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ // TO DO remove this line after all the tests are completed /* eslint-disable functional/no-let */ /* eslint-disable @typescript-eslint/no-floating-promises */ -import { afterEach, beforeAll, describe, expect, it } from "vitest"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { AgreementCollection, EServiceCollection, @@ -23,6 +23,7 @@ import { EServiceDocumentUpdatedV1, EServiceUpdatedV1, EServiceWithDescriptorsDeletedV1, + Tenant, descriptorState, operationForbidden, } from "pagopa-interop-models"; @@ -1659,17 +1660,31 @@ describe("database test", async () => { describe("ReadModel Service", () => { describe("getEservices", () => { - it("Should get eServices based on the given parameters", async () => { - const [organizationId1, organizationId2] = [uuidv4(), uuidv4()]; + let organizationId1: string; + let organizationId2: string; + let organizationId3: string; + let eService1: EService; + let eService2: EService; + let eService3: EService; + let eService4: EService; + let eService5: EService; + let eService6: EService; + let eService7: EService; + + beforeEach(async () => { + organizationId1 = uuidv4(); + organizationId2 = uuidv4(); + organizationId3 = uuidv4(); + const descriptor1: Descriptor = { ...mockDescriptor, id: uuidv4(), state: descriptorState.published, }; - const eService1: EService = { + eService1 = { ...mockEService, id: uuidv4(), - name: "eService 001", + name: "eService 001 test", descriptors: [descriptor1], producerId: organizationId1, }; @@ -1680,10 +1695,10 @@ describe("database test", async () => { id: uuidv4(), state: descriptorState.draft, }; - const eService2: EService = { + eService2 = { ...mockEService, id: uuidv4(), - name: "eService 002", + name: "eService 002 test", descriptors: [descriptor2], producerId: organizationId1, }; @@ -1694,10 +1709,10 @@ describe("database test", async () => { id: uuidv4(), state: descriptorState.published, }; - const eService3: EService = { + eService3 = { ...mockEService, id: uuidv4(), - name: "eService 003", + name: "eService 003 test", descriptors: [descriptor3], producerId: organizationId1, }; @@ -1708,10 +1723,10 @@ describe("database test", async () => { id: uuidv4(), state: descriptorState.draft, }; - const eService4: EService = { + eService4 = { ...mockEService, id: uuidv4(), - name: "eService 004", + name: "eService 004 test", producerId: organizationId2, descriptors: [descriptor4], }; @@ -1722,7 +1737,7 @@ describe("database test", async () => { id: uuidv4(), state: descriptorState.published, }; - const eService5: EService = { + eService5 = { ...mockEService, id: uuidv4(), name: "eService 005", @@ -1736,7 +1751,7 @@ describe("database test", async () => { id: uuidv4(), state: descriptorState.draft, }; - const eService6: EService = { + eService6 = { ...mockEService, id: uuidv4(), name: "eService 006", @@ -1745,7 +1760,28 @@ describe("database test", async () => { }; await addOneEService(eService6, postgresDB, eservices); - const result1 = await readModelService.getEServices( + const tenant: Tenant = { + ...getMockTenant(), + id: organizationId3, + }; + await addOneTenant(tenant, tenants); + const agreement1 = getMockAgreement({ + eServiceId: eService1.id, + descriptorId: descriptor1.id, + producerId: eService1.producerId, + consumerId: tenant.id, + }); + await addOneAgreement(agreement1, agreements); + const agreement2 = getMockAgreement({ + eServiceId: eService3.id, + descriptorId: descriptor3.id, + producerId: eService3.producerId, + consumerId: tenant.id, + }); + await addOneAgreement(agreement2, agreements); + }); + it("should get the eServices if they exist (parameters: eservicesIds)", async () => { + const response = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [eService1.id, eService2.id], @@ -1756,7 +1792,11 @@ describe("database test", async () => { 0, 50 ); - const result2 = await readModelService.getEServices( + expect(response.totalCount).toBe(2); + expect(response.results).toEqual([eService1, eService2]); + }); + it("should get the eServices if they exist (parameters: producersIds)", async () => { + const response = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1767,37 +1807,153 @@ describe("database test", async () => { 0, 50 ); - const result3 = await readModelService.getEServices( + expect(response.totalCount).toBe(3); + expect(response.results).toEqual([eService1, eService2, eService3]); + }); + it("should get the eServices if they exist (parameters: states)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(), + { + eservicesIds: [], + producersIds: [], + states: ["Draft"], + agreementStates: [], + }, + 0, + 50 + ); + expect(response.totalCount).toBe(3); + expect(response.results).toEqual([eService2, eService4, eService6]); + }); + it("should get the eServices if they exist (parameters: agreementStates)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(organizationId3), + { + eservicesIds: [], + producersIds: [], + states: [], + agreementStates: ["Active"], + }, + 0, + 50 + ); + expect(response.totalCount).toBe(2); + expect(response.results).toEqual([eService1, eService3]); + }); + it("should get the eServices if they exist (parameters: name)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(), + { + eservicesIds: [], + producersIds: [], + states: [], + agreementStates: [], + name: "test", + }, + 0, + 50 + ); + expect(response.totalCount).toBe(4); + expect(response.results).toEqual([ + eService1, + eService2, + eService3, + eService4, + ]); + }); + it("should get the eServices if they exist (parameters: states, agreementStates, name)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(organizationId3), + { + eservicesIds: [], + producersIds: [], + states: ["Published"], + agreementStates: ["Active"], + name: "test", + }, + 0, + 50 + ); + expect(response.totalCount).toBe(2); + expect(response.results).toEqual([eService1, eService3]); + }); + it("should not get the eServices if they don't exist (parameters: states, agreementStates, name)", async () => { + const response = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], producersIds: [], + states: ["Archived"], + agreementStates: ["Active"], + name: "test", + }, + 0, + 50 + ); + expect(response.totalCount).toBe(0); + expect(response.results).toEqual([]); + }); + it("should get the eServices if they exist (parameters: producersIds, states, name)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(), + { + eservicesIds: [], + producersIds: [organizationId2], states: ["Draft"], agreementStates: [], + name: "test", }, 0, 50 ); - const result4 = await readModelService.getEServices( + expect(response.totalCount).toBe(1); + expect(response.results).toEqual([eService4]); + }); + it("should not get the eServices if they don't exist (parameters: producersIds, states, name)", async () => { + const response = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], producersIds: [organizationId2], states: ["Draft"], agreementStates: [], + name: "not-existing", }, 0, 50 ); - // TO DO test with other parameters configuration - expect(result1.totalCount).toBe(2); - expect(result1.results).toEqual([eService1, eService2]); - expect(result2.totalCount).toBe(3); - expect(result2.results).toEqual([eService1, eService2, eService3]); - expect(result3.totalCount).toBe(3); - expect(result3.results).toEqual([eService2, eService4, eService6]); - expect(result4.totalCount).toBe(2); - expect(result4.results).toEqual([eService4, eService6]); + expect(response.totalCount).toBe(0); + expect(response.results).toEqual([]); + }); + it("should get the eServices if they exist (pagination: offset)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(), + { + eservicesIds: [], + producersIds: [], + states: [], + agreementStates: [], + }, + 0, + 5 + ); + expect(response.totalCount).toBe(6); + expect(response.results.length).toBe(5); + }); + it("should get the eServices if they exist (pagination: offset, limit)", async () => { + const response = await readModelService.getEServices( + getMockAuthData(), + { + eservicesIds: [], + producersIds: [], + states: [], + agreementStates: [], + }, + 5, + 5 + ); + expect(response.totalCount).toBe(6); + expect(response.results.length).toBe(1); }); }); From be8494685f00f6276841af173ef1bc7915fe4f00 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 17 Jan 2024 13:49:44 +0100 Subject: [PATCH 11/77] Fix in catalog readModelService --- packages/catalog-process/src/services/readModelService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/catalog-process/src/services/readModelService.ts b/packages/catalog-process/src/services/readModelService.ts index d9e2fef8af..c6adf408b6 100644 --- a/packages/catalog-process/src/services/readModelService.ts +++ b/packages/catalog-process/src/services/readModelService.ts @@ -319,7 +319,7 @@ export function readModelServiceBuilder( "data.producerId": { $in: producersIds }, }), ...ReadModelRepository.arrayToFilter(states, { - "data.state": { $elemMatch: { state: { $in: states } } }, + "data.state": { $in: states }, }), } satisfies ReadModelFilter, }, @@ -333,7 +333,7 @@ export function readModelServiceBuilder( }, ]; const data = await agreements.aggregate(aggregationPipeline).toArray(); - const result = z.array(Agreement).safeParse(data); + const result = z.array(Agreement).safeParse(data.map((a) => a.data)); if (!result.success) { logger.error( From 3d7d12a8e0f28efaea2f8876bed4999dfb9fd8df Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 17 Jan 2024 14:15:18 +0100 Subject: [PATCH 12/77] Remove not needed check --- packages/catalog-process/src/services/catalogService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 7d1af0843d..a3ba42cacd 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -602,9 +602,9 @@ export async function deleteDocumentLogic({ const descriptor = retrieveDescriptor(descriptorId, eService); - const document = ( - descriptor ? [...descriptor.docs, descriptor.interface] : [] - ).find((doc) => doc != null && doc.id === documentId); + const document = [...descriptor.docs, descriptor.interface].find( + (doc) => doc != null && doc.id === documentId + ); if (document === undefined) { throw eServiceDocumentNotFound(eServiceId, descriptorId, documentId); } From c68f0151953764e04fa127278ef7925828d0c5ef Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 09:49:58 +0100 Subject: [PATCH 13/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 125 +++++++++++++++-------- 1 file changed, 81 insertions(+), 44 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 6a22abaa8f..b19e5e7d7d 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1202,8 +1202,8 @@ describe("database test", async () => { const descriptor: Descriptor = { ...mockDescriptor, state: descriptorState.draft, - interface: getMockDocument(), - docs: [getMockDocument()], + interface: mockDocument, + docs: [mockDocument], }; const eService: EService = { ...mockEService, @@ -1669,7 +1669,6 @@ describe("database test", async () => { let eService4: EService; let eService5: EService; let eService6: EService; - let eService7: EService; beforeEach(async () => { organizationId1 = uuidv4(); @@ -1781,7 +1780,7 @@ describe("database test", async () => { await addOneAgreement(agreement2, agreements); }); it("should get the eServices if they exist (parameters: eservicesIds)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [eService1.id, eService2.id], @@ -1792,11 +1791,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(2); - expect(response.results).toEqual([eService1, eService2]); + expect(result.totalCount).toBe(2); + expect(result.results).toEqual([eService1, eService2]); }); it("should get the eServices if they exist (parameters: producersIds)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1807,11 +1806,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(3); - expect(response.results).toEqual([eService1, eService2, eService3]); + expect(result.totalCount).toBe(3); + expect(result.results).toEqual([eService1, eService2, eService3]); }); it("should get the eServices if they exist (parameters: states)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1822,11 +1821,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(3); - expect(response.results).toEqual([eService2, eService4, eService6]); + expect(result.totalCount).toBe(3); + expect(result.results).toEqual([eService2, eService4, eService6]); }); it("should get the eServices if they exist (parameters: agreementStates)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(organizationId3), { eservicesIds: [], @@ -1837,11 +1836,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(2); - expect(response.results).toEqual([eService1, eService3]); + expect(result.totalCount).toBe(2); + expect(result.results).toEqual([eService1, eService3]); }); it("should get the eServices if they exist (parameters: name)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1853,8 +1852,8 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(4); - expect(response.results).toEqual([ + expect(result.totalCount).toBe(4); + expect(result.results).toEqual([ eService1, eService2, eService3, @@ -1862,7 +1861,7 @@ describe("database test", async () => { ]); }); it("should get the eServices if they exist (parameters: states, agreementStates, name)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(organizationId3), { eservicesIds: [], @@ -1874,11 +1873,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(2); - expect(response.results).toEqual([eService1, eService3]); + expect(result.totalCount).toBe(2); + expect(result.results).toEqual([eService1, eService3]); }); it("should not get the eServices if they don't exist (parameters: states, agreementStates, name)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1890,11 +1889,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(0); - expect(response.results).toEqual([]); + expect(result.totalCount).toBe(0); + expect(result.results).toEqual([]); }); it("should get the eServices if they exist (parameters: producersIds, states, name)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1906,11 +1905,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(1); - expect(response.results).toEqual([eService4]); + expect(result.totalCount).toBe(1); + expect(result.results).toEqual([eService4]); }); it("should not get the eServices if they don't exist (parameters: producersIds, states, name)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1922,11 +1921,11 @@ describe("database test", async () => { 0, 50 ); - expect(response.totalCount).toBe(0); - expect(response.results).toEqual([]); + expect(result.totalCount).toBe(0); + expect(result.results).toEqual([]); }); it("should get the eServices if they exist (pagination: offset)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1937,11 +1936,11 @@ describe("database test", async () => { 0, 5 ); - expect(response.totalCount).toBe(6); - expect(response.results.length).toBe(5); + expect(result.totalCount).toBe(6); + expect(result.results.length).toBe(5); }); it("should get the eServices if they exist (pagination: offset, limit)", async () => { - const response = await readModelService.getEServices( + const result = await readModelService.getEServices( getMockAuthData(), { eservicesIds: [], @@ -1952,8 +1951,8 @@ describe("database test", async () => { 5, 5 ); - expect(response.totalCount).toBe(6); - expect(response.results.length).toBe(1); + expect(result.totalCount).toBe(6); + expect(result.results.length).toBe(1); }); }); @@ -1985,11 +1984,11 @@ describe("database test", async () => { }; await addOneEService(eService3, postgresDB, eservices); - const eService = await readModelService.getEServiceByNameAndProducerId({ + const result = await readModelService.getEServiceByNameAndProducerId({ name: "eService 001", producerId: organizationId1, }); - expect(eService?.data).toEqual(eService1); + expect(result?.data).toEqual(eService1); }); it("should not get the eService if it doesn't exist", async () => { const organizationId = uuidv4(); @@ -2009,11 +2008,11 @@ describe("database test", async () => { }; await addOneEService(eService2, postgresDB, eservices); - const eService = await readModelService.getEServiceByNameAndProducerId({ + const result = await readModelService.getEServiceByNameAndProducerId({ name: "not-existing", producerId: organizationId, }); - expect(eService).toBeUndefined(); + expect(result).toBeUndefined(); }); }); @@ -2055,15 +2054,15 @@ describe("database test", async () => { }; await addOneEService(eService3, postgresDB, eservices); - const eService = await readModelService.getEServiceById(eService1.id); - expect(eService?.data).toEqual(eService1); + const result = await readModelService.getEServiceById(eService1.id); + expect(result?.data).toEqual(eService1); }); it("should not get the eService if it doesn't exist", async () => { await addOneEService(mockEService, postgresDB, eservices); - const eService = await readModelService.getEServiceById(uuidv4()); - expect(eService).toBeUndefined(); + const result = await readModelService.getEServiceById(uuidv4()); + expect(result).toBeUndefined(); }); }); @@ -2117,5 +2116,43 @@ describe("database test", async () => { expect(consumers.totalCount).toBe(0); }); }); + + describe("getDocumentById", () => { + it("should get the document if it exists", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + id: uuidv4(), + name: "eService 001", + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + const result = await readModelService.getDocumentById( + eService.id, + descriptor.id, + mockDocument.id + ); + expect(result).toEqual(mockDocument); + }); + + it("should not get document if it doesn't exist", async () => { + const eService: EService = { + ...mockEService, + id: uuidv4(), + name: "eService 001", + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + const result = await readModelService.getDocumentById( + eService.id, + uuidv4(), + uuidv4() + ); + expect(result).toBeUndefined(); + }); + }); }); }); From ebaa361eb8c40cf75ad0fb1e13e6084756c66db0 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 09:58:56 +0100 Subject: [PATCH 14/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index bb6fd56e67..a327741370 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -56,6 +56,7 @@ export const documentUpdateDeleteErrorMapper = ( match(error.code) .with( "eServiceNotFound", + "eServiceDescriptorNotFound", "eServiceDocumentNotFound", () => HTTP_STATUS_NOT_FOUND ) From f55fbd16e5d7c1787c339a210bfc949a818bf3ba Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 10:41:19 +0100 Subject: [PATCH 15/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index a327741370..5c3e633ec0 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -36,6 +36,7 @@ export const deleteEServiceErrorMapper = ( match(error.code) .with("eServiceNotFound", () => HTTP_STATUS_NOT_FOUND) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) + .with("eserviceCannotBeUpdatedOrDeleted", () => HTTP_STATUS_BAD_REQUEST) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); export const documentCreateErrorMapper = ( From 719af1c1ded295ac97cdb3e06d287546207e15e5 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:02:45 +0100 Subject: [PATCH 16/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 5c3e633ec0..8dae15e888 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -107,6 +107,7 @@ export const publishDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("eServiceDescriptorWithoutInterface", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From c50049d89b943540f5a85088c840500665119dcd Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:04:53 +0100 Subject: [PATCH 17/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 85 +++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index b19e5e7d7d..f48a7cc70d 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -242,7 +242,7 @@ describe("database test", async () => { ).rejects.toThrowError(operationForbidden); }); - it("should throw eServiceCannotBeUpdated if the eService descriptor is not in draft state", async () => { + it("should throw eServiceCannotBeUpdated if the eService descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, state: descriptorState.published, @@ -264,6 +264,72 @@ describe("database test", async () => { ) ).rejects.toThrowError(eServiceCannotBeUpdated(eService.id)); }); + it("should throw eServiceCannotBeUpdated if the eService descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateEService( + eService.id, + { + name: "eService new name", + description: "eService description", + technology: "REST", + }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError(eServiceCannotBeUpdated(eService.id)); + }); + it("should throw eServiceCannotBeUpdated if the eService descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateEService( + eService.id, + { + name: "eService new name", + description: "eService description", + technology: "REST", + }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError(eServiceCannotBeUpdated(eService.id)); + }); + it("should throw eServiceCannotBeUpdated if the eService descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateEService( + eService.id, + { + name: "eService new name", + description: "eService description", + technology: "REST", + }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError(eServiceCannotBeUpdated(eService.id)); + }); }); describe("delete eService", () => { @@ -648,6 +714,23 @@ describe("database test", async () => { ).rejects.toThrowError(eServiceNotFound(mockEService.id)); }); + it("should throw eServiceDescriptorNotFound if the descriptor doesn't exist", async () => { + const eService: EService = { + ...mockEService, + descriptors: [], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDraftDescriptor( + mockEService.id, + mockDescriptor.id, + getMockAuthData(mockEService.producerId) + ) + ).rejects.toThrowError( + eServiceDescriptorNotFound(eService.id, mockDescriptor.id) + ); + }); + it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, From b02b13bd05e6d18e249e92c12981dbff4e7e375a Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:12:05 +0100 Subject: [PATCH 18/77] Remove error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 8dae15e888..67e4c6ad3c 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -159,6 +159,5 @@ export const archiveDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) - .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From ae6d93df60e75242a3039fe6272c0376771f2f37 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:20:49 +0100 Subject: [PATCH 19/77] Improve data coherence --- packages/catalog-process/test/db.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index f48a7cc70d..94bc204ba0 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -245,6 +245,7 @@ describe("database test", async () => { it("should throw eServiceCannotBeUpdated if the eService descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -311,6 +312,7 @@ describe("database test", async () => { it("should throw eServiceCannotBeUpdated if the eService descriptor is in deprecated state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.deprecated, }; const eService: EService = { @@ -372,6 +374,7 @@ describe("database test", async () => { it("should throw eServiceCannotBeDeleted if the eService has a descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -456,6 +459,7 @@ describe("database test", async () => { it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -522,6 +526,7 @@ describe("database test", async () => { it("should throw eServiceNotFound if the eService doesn't exist", () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; expect( @@ -556,6 +561,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -579,6 +585,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.deprecated, }; const eService: EService = { @@ -851,6 +858,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -872,6 +880,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.deprecated, }; const eService: EService = { @@ -1011,6 +1020,7 @@ describe("database test", async () => { it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -1219,6 +1229,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -1240,6 +1251,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.deprecated, }; const eService: EService = { @@ -1761,6 +1773,7 @@ describe("database test", async () => { const descriptor1: Descriptor = { ...mockDescriptor, id: uuidv4(), + interface: mockDocument, state: descriptorState.published, }; eService1 = { @@ -1789,6 +1802,7 @@ describe("database test", async () => { const descriptor3: Descriptor = { ...mockDescriptor, id: uuidv4(), + interface: mockDocument, state: descriptorState.published, }; eService3 = { @@ -1817,6 +1831,7 @@ describe("database test", async () => { const descriptor5: Descriptor = { ...mockDescriptor, id: uuidv4(), + interface: mockDocument, state: descriptorState.published, }; eService5 = { @@ -2103,6 +2118,7 @@ describe("database test", async () => { it("should get the eService if it exists", async () => { const descriptor1: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService1: EService = { @@ -2115,6 +2131,7 @@ describe("database test", async () => { const descriptor2: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService2: EService = { @@ -2127,6 +2144,7 @@ describe("database test", async () => { const descriptor3: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService3: EService = { @@ -2153,6 +2171,7 @@ describe("database test", async () => { it("should get the consumers of the given eService", async () => { const descriptor1: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService1: EService = { @@ -2182,6 +2201,7 @@ describe("database test", async () => { it("should not get any consumers, if no one is using the given eService", async () => { const descriptor1: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService1: EService = { From 6a23fa165a734b765c4670daa6283a7dd243b999 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 19 Jan 2024 13:25:56 +0100 Subject: [PATCH 20/77] Fix descriptor version --- packages/catalog-process/src/utilities/versionGenerator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/src/utilities/versionGenerator.ts b/packages/catalog-process/src/utilities/versionGenerator.ts index 303f9322a7..ac4db102ec 100644 --- a/packages/catalog-process/src/utilities/versionGenerator.ts +++ b/packages/catalog-process/src/utilities/versionGenerator.ts @@ -14,7 +14,7 @@ export const nextDescriptorVersion = (eservice: EService): string => { } return currentVersionNumber.data > max ? currentVersionNumber.data : max; - }, 0); + }, 1); return currentVersion.toString(); }; From 44e2f5188cbcd545a1ae56c7d3c3cd74df36be04 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 19 Jan 2024 13:26:25 +0100 Subject: [PATCH 21/77] Implement more tests --- packages/catalog-process/test/db.test.ts | 88 +++++++++++++++++++++--- packages/catalog-process/test/utils.ts | 12 ++-- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 94bc204ba0..42ee76df36 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1,6 +1,8 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ // TO DO remove this line after all the tests are completed +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable functional/no-let */ /* eslint-disable @typescript-eslint/no-floating-promises */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ + import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { AgreementCollection, @@ -13,6 +15,7 @@ import { IDatabase } from "pg-promise"; import { ClonedEServiceAddedV1, Descriptor, + Document, EService, EServiceAddedV1, EServiceDeletedV1, @@ -31,7 +34,11 @@ import { v4 as uuidv4 } from "uuid"; import { PostgreSqlContainer } from "@testcontainers/postgresql"; import { GenericContainer } from "testcontainers"; import { config } from "../src/utilities/config.js"; -import { toDescriptorV1, toEServiceV1 } from "../src/model/domain/toEvent.js"; +import { + toDescriptorV1, + toDocumentV1, + toEServiceV1, +} from "../src/model/domain/toEvent.js"; import { EServiceDescriptorSeed } from "../src/model/domain/models.js"; import { ReadModelService, @@ -57,13 +64,13 @@ import { addOneEService, addOneTenant, buildDescriptorSeed, - buildInterfaceSeed, decodeProtobufPayload, getMockAgreement, getMockAuthData, getMockDescriptor, getMockDocument, getMockEService, + buildInterfaceSeed, getMockTenant, readLastEventByStreamId, } from "./utils.js"; @@ -416,9 +423,10 @@ describe("database test", async () => { createdAt: new Date( Number(writtenPayload.eServiceDescriptor?.createdAt) ), - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion id: writtenPayload.eServiceDescriptor!.id, + serverUrls: [], }; + console.log(writtenPayload.eServiceDescriptor); expect(writtenPayload.eServiceId).toEqual(mockEService.id); expect(writtenPayload.eServiceDescriptor).toEqual( @@ -1322,7 +1330,40 @@ describe("database test", async () => { messageType: ClonedEServiceAddedV1, payload: writtenEvent.data, }); - // TO DO check entire payload + + const expectedInterface: Document = { + ...mockDocument, + id: writtenPayload.eService!.descriptors[0].interface!.id, + uploadDate: new Date( + writtenPayload.eService!.descriptors[0].docs[0].uploadDate + ), + path: writtenPayload.eService!.descriptors[0].interface!.path, + }; + const expectedDocument: Document = { + ...mockDocument, + id: writtenPayload.eService!.descriptors[0].docs[0].id, + uploadDate: new Date( + writtenPayload.eService!.descriptors[0].docs[0].uploadDate + ), + path: writtenPayload.eService!.descriptors[0].docs[0].path, + }; + const expectedDescriptor: Descriptor = { + ...descriptor, + id: writtenPayload.eService!.descriptors[0].id, + interface: expectedInterface, + createdAt: new Date( + Number(writtenPayload.eService?.descriptors[0].createdAt) + ), + docs: [expectedDocument], + }; + const expectedEService: EService = { + ...eService, + id: writtenPayload.eService!.id, + name: `${eService.name} - clone`, + descriptors: [expectedDescriptor], + createdAt: new Date(Number(writtenPayload.eService?.createdAt)), + }; + expect(writtenPayload.eService).toEqual(toEServiceV1(expectedEService)); }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( @@ -1490,7 +1531,21 @@ describe("database test", async () => { messageType: EServiceDocumentAddedV1, payload: writtenEvent.data, }); - // TO DO check entire payload + + expect(writtenPayload.eServiceId).toEqual(eService.id); + expect(writtenPayload.descriptorId).toEqual(descriptor.id); + expect(writtenPayload.isInterface).toEqual(true); + expect(writtenPayload.serverUrls).toEqual( + buildInterfaceSeed().serverUrls + ); + + const expectedDocument = { + ...mockDocument, + id: writtenPayload.document!.id, + checksum: writtenPayload.document!.checksum, + uploadDate: new Date(writtenPayload.document!.uploadDate), + }; + expect(writtenPayload.document).toEqual(toDocumentV1(expectedDocument)); }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( @@ -1570,7 +1625,10 @@ describe("database test", async () => { messageType: EServiceDocumentDeletedV1, payload: writtenEvent.data, }); - // TO DO check entire payload + + expect(writtenPayload.eServiceId).toEqual(eService.id); + expect(writtenPayload.descriptorId).toEqual(descriptor.id); + expect(writtenPayload.documentId).toEqual(mockDocument.id); }); it("should throw eServiceNotFound if the eService doesn't exist", async () => { expect( @@ -1675,7 +1733,21 @@ describe("database test", async () => { messageType: EServiceDocumentUpdatedV1, payload: writtenEvent.data, }); - // TO DO check entire payload + + expect(writtenPayload.eServiceId).toEqual(eService.id); + expect(writtenPayload.descriptorId).toEqual(descriptor.id); + expect(writtenPayload.documentId).toEqual(mockDocument.id); + expect(writtenPayload.serverUrls).toEqual( + buildInterfaceSeed().serverUrls + ); + + const expectedDocument = { + ...mockDocument, + prettyName: "updated prettyName", + }; + expect(writtenPayload.updatedDocument).toEqual( + toDocumentV1(expectedDocument) + ); }); it("should throw eServiceNotFound if the eService doesn't exist", async () => { expect( diff --git a/packages/catalog-process/test/utils.ts b/packages/catalog-process/test/utils.ts index 08630e69aa..a2d2b7b39f 100644 --- a/packages/catalog-process/test/utils.ts +++ b/packages/catalog-process/test/utils.ts @@ -124,7 +124,7 @@ export const getMockEService = (): EService => ({ export const getMockDescriptor = (): Descriptor => ({ id: uuidv4(), - version: "0", + version: "1", docs: [], state: descriptorState.draft, audience: [], @@ -132,7 +132,7 @@ export const getMockDescriptor = (): Descriptor => ({ dailyCallsPerConsumer: 10, dailyCallsTotal: 1000, createdAt: new Date(), - serverUrls: [], + serverUrls: ["pagopa.it"], agreementApprovalPolicy: "Automatic", attributes: { certified: [], @@ -145,7 +145,7 @@ export const buildInterfaceSeed = (): ApiEServiceDescriptorDocumentSeed => ({ contentType: "json", prettyName: "prettyName", serverUrls: ["pagopa.it"], - documentId: "string", + documentId: uuidv4(), kind: "INTERFACE", filePath: "filePath", fileName: "fileName", @@ -153,10 +153,10 @@ export const buildInterfaceSeed = (): ApiEServiceDescriptorDocumentSeed => ({ }); export const getMockDocument = (): Document => ({ - name: "document name", - path: "document path", + name: "fileName", + path: "filePath", id: uuidv4(), - prettyName: "pretty name", + prettyName: "prettyName", contentType: "json", checksum: uuidv4(), uploadDate: new Date(), From 7852f3a49aca1318c8672498fe6fca4fd7f568e5 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 19 Jan 2024 13:30:13 +0100 Subject: [PATCH 22/77] Remove console log --- packages/catalog-process/test/db.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 42ee76df36..fb031f0cd2 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -426,7 +426,6 @@ describe("database test", async () => { id: writtenPayload.eServiceDescriptor!.id, serverUrls: [], }; - console.log(writtenPayload.eServiceDescriptor); expect(writtenPayload.eServiceId).toEqual(mockEService.id); expect(writtenPayload.eServiceDescriptor).toEqual( From aecdecfa1d5fff1eb683907c08b6d6aaa9f18242 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 19 Jan 2024 13:47:09 +0100 Subject: [PATCH 23/77] Improve data coherence --- packages/catalog-process/test/db.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index fb031f0cd2..966164eb67 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -275,6 +275,7 @@ describe("database test", async () => { it("should throw eServiceCannotBeUpdated if the eService descriptor is in archived state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.archived, }; const eService: EService = { @@ -297,6 +298,7 @@ describe("database test", async () => { it("should throw eServiceCannotBeUpdated if the eService descriptor is in suspended state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -616,6 +618,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -639,6 +642,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in archived state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.archived, }; const eService: EService = { @@ -909,6 +913,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -930,6 +935,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in archived state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.archived, }; const eService: EService = { @@ -975,6 +981,7 @@ describe("database test", async () => { it("should write on event-store for the suspension of a descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.published, }; const eService: EService = { @@ -1086,6 +1093,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -1107,6 +1115,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in archived state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.archived, }; const eService: EService = { @@ -1130,6 +1139,7 @@ describe("database test", async () => { it("should write on event-store for the activation of a descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -1196,6 +1206,7 @@ describe("database test", async () => { it("should throw operationForbidden if the requester is not the producer", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { @@ -1280,6 +1291,7 @@ describe("database test", async () => { it("should throw notValidDescriptor if the descriptor is in archived state", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.archived, }; const eService: EService = { @@ -1413,6 +1425,7 @@ describe("database test", async () => { it("should write on event-store for the archiving of a descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, + interface: mockDocument, state: descriptorState.suspended, }; const eService: EService = { From b18320b2a2c5b61e85b4acb41ab48e89a772e4fa Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 11 Jan 2024 12:16:58 +0100 Subject: [PATCH 24/77] Use retrieveDescriptor --- packages/catalog-process/src/services/catalogService.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 0e4748b4ea..c285121030 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -789,12 +789,7 @@ export function updateDescriptorLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + const descriptor = retrieveDescriptor(descriptorId, eService); if (descriptor.state !== descriptorState.draft) { throw notValidDescriptor(descriptorId, descriptor.state.toString()); From 8bb624b1d3091cee2f54f98bfadf0d483291d322 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 15 Jan 2024 13:10:26 +0100 Subject: [PATCH 25/77] Minor refactor --- .../src/services/catalogService.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index c285121030..7d1af0843d 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -560,12 +560,7 @@ export function uploadDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + retrieveDescriptor(descriptorId, eService); return toCreateEventEServiceDocumentAdded( eServiceId, @@ -605,9 +600,7 @@ export async function deleteDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); + const descriptor = retrieveDescriptor(descriptorId, eService); const document = ( descriptor ? [...descriptor.docs, descriptor.interface] : [] @@ -644,12 +637,7 @@ export async function updateDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => d.id === descriptorId - ); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); - } + const descriptor = retrieveDescriptor(descriptorId, eService); const document = ( descriptor ? [...descriptor.docs, descriptor.interface] : [] From 38804b469aac75d69762617f338b7e5332490546 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 17 Jan 2024 13:49:44 +0100 Subject: [PATCH 26/77] Fix in catalog readModelService --- packages/catalog-process/src/services/readModelService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/catalog-process/src/services/readModelService.ts b/packages/catalog-process/src/services/readModelService.ts index d9e2fef8af..c6adf408b6 100644 --- a/packages/catalog-process/src/services/readModelService.ts +++ b/packages/catalog-process/src/services/readModelService.ts @@ -319,7 +319,7 @@ export function readModelServiceBuilder( "data.producerId": { $in: producersIds }, }), ...ReadModelRepository.arrayToFilter(states, { - "data.state": { $elemMatch: { state: { $in: states } } }, + "data.state": { $in: states }, }), } satisfies ReadModelFilter, }, @@ -333,7 +333,7 @@ export function readModelServiceBuilder( }, ]; const data = await agreements.aggregate(aggregationPipeline).toArray(); - const result = z.array(Agreement).safeParse(data); + const result = z.array(Agreement).safeParse(data.map((a) => a.data)); if (!result.success) { logger.error( From 863ae9249f03f774011085c5d4dc3ebd846865cb Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 17 Jan 2024 14:15:18 +0100 Subject: [PATCH 27/77] Remove not needed check --- packages/catalog-process/src/services/catalogService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 7d1af0843d..a3ba42cacd 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -602,9 +602,9 @@ export async function deleteDocumentLogic({ const descriptor = retrieveDescriptor(descriptorId, eService); - const document = ( - descriptor ? [...descriptor.docs, descriptor.interface] : [] - ).find((doc) => doc != null && doc.id === documentId); + const document = [...descriptor.docs, descriptor.interface].find( + (doc) => doc != null && doc.id === documentId + ); if (document === undefined) { throw eServiceDocumentNotFound(eServiceId, descriptorId, documentId); } From e7bfde5175d27e98dcfbdd15dca1e26fcfcb0846 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 09:58:56 +0100 Subject: [PATCH 28/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index bb6fd56e67..a327741370 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -56,6 +56,7 @@ export const documentUpdateDeleteErrorMapper = ( match(error.code) .with( "eServiceNotFound", + "eServiceDescriptorNotFound", "eServiceDocumentNotFound", () => HTTP_STATUS_NOT_FOUND ) From a8db816727bcd8043cba9ac526dd83ddebd2f048 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 10:41:19 +0100 Subject: [PATCH 29/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index a327741370..5c3e633ec0 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -36,6 +36,7 @@ export const deleteEServiceErrorMapper = ( match(error.code) .with("eServiceNotFound", () => HTTP_STATUS_NOT_FOUND) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) + .with("eserviceCannotBeUpdatedOrDeleted", () => HTTP_STATUS_BAD_REQUEST) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); export const documentCreateErrorMapper = ( From d4f7cedfd589a699c354fe41067a5b5de655e55f Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:02:45 +0100 Subject: [PATCH 30/77] Add missing error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 5c3e633ec0..8dae15e888 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -107,6 +107,7 @@ export const publishDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("eServiceDescriptorWithoutInterface", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 986ff04e5c08e68a569a2e049e5e0b6611ee8075 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 18 Jan 2024 11:12:05 +0100 Subject: [PATCH 31/77] Remove error --- packages/catalog-process/src/utilities/errorMappers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 8dae15e888..67e4c6ad3c 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -159,6 +159,5 @@ export const archiveDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) - .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From cff3ffb8bac00a4cd93d55d03c8d88657593b159 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 19 Jan 2024 13:25:56 +0100 Subject: [PATCH 32/77] Fix descriptor version --- packages/catalog-process/src/utilities/versionGenerator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/src/utilities/versionGenerator.ts b/packages/catalog-process/src/utilities/versionGenerator.ts index 303f9322a7..ac4db102ec 100644 --- a/packages/catalog-process/src/utilities/versionGenerator.ts +++ b/packages/catalog-process/src/utilities/versionGenerator.ts @@ -14,7 +14,7 @@ export const nextDescriptorVersion = (eservice: EService): string => { } return currentVersionNumber.data > max ? currentVersionNumber.data : max; - }, 0); + }, 1); return currentVersion.toString(); }; From a76a36949f82b898d1da518cee8d29d64e5b55b6 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 10:29:32 +0100 Subject: [PATCH 33/77] Fix tests --- packages/catalog-process/test/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/utils.ts b/packages/catalog-process/test/utils.ts index 4abc10dbb1..a6d49a7484 100644 --- a/packages/catalog-process/test/utils.ts +++ b/packages/catalog-process/test/utils.ts @@ -122,7 +122,7 @@ export const getMockEService = (): EService => ({ export const getMockDescriptor = (): Descriptor => ({ id: uuidv4(), - version: "0", + version: "1", docs: [], state: descriptorState.draft, audience: [], From 4ec69d1ccfdb3e844f0896ff92a0b9d53c821ee2 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 10:43:46 +0100 Subject: [PATCH 34/77] Refactor --- packages/catalog-process/src/services/catalogService.ts | 9 +++------ packages/catalog-process/src/utilities/errorMappers.ts | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index a3ba42cacd..74ca6b172d 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -732,13 +732,10 @@ export async function deleteDraftDescriptorLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = eService.data.descriptors.find( - (d: Descriptor) => - d.id === descriptorId && d.state === descriptorState.draft - ); + const descriptor = retrieveDescriptor(descriptorId, eService); - if (descriptor === undefined) { - throw eServiceDescriptorNotFound(eServiceId, descriptorId); + if (descriptor.state !== descriptorState.draft) { + throw notValidDescriptor(descriptorId, descriptor.state.toString()); } const interfacePath = descriptor.docs.find( diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 67e4c6ad3c..06bad07a1e 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -82,6 +82,7 @@ export const deleteDraftDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 56bf3e873aa8a0fd9eee2206d36dd0de88b216fc Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 13:39:16 +0100 Subject: [PATCH 35/77] Fix test --- packages/catalog-process/test/catalogService.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index 163e3052d5..69b26e0d1e 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -539,7 +539,7 @@ describe("CatalogService", () => { mockEservice.descriptors.map((d, i) => ({ ...d, state: descriptorState.archived, - version: i.toString(), + version: (i + 1).toString(), })) ); const event = createDescriptorLogic({ @@ -555,7 +555,7 @@ describe("CatalogService", () => { id: (event.event.data as { eServiceDescriptor: { id: string } }) .eServiceDescriptor.id, description: mockEserviceDescriptorSeed.description, - version: (descriptors.length - 1).toString(), + version: descriptors.length.toString(), interface: undefined, docs: [], state: toEServiceDescriptorStateV1("Draft"), From 523f9055b1fb89d5cb5d51f9014a4c51bc067141 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 13:48:31 +0100 Subject: [PATCH 36/77] Fix after merge --- packages/catalog-process/test/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/utils.ts b/packages/catalog-process/test/utils.ts index acd99594a7..476eff4e68 100644 --- a/packages/catalog-process/test/utils.ts +++ b/packages/catalog-process/test/utils.ts @@ -124,7 +124,7 @@ export const getMockEService = (): EService => ({ export const getMockDescriptor = (): Descriptor => ({ id: generateId(), - version: 1", + version: "1", docs: [], state: descriptorState.draft, audience: [], From 2721cd0b8e9dc56c8f9bc424084738db6ca19dd5 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 17:46:44 +0100 Subject: [PATCH 37/77] refactor string ids --- packages/catalog-process/test/db.test.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 966164eb67..e77603350b 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -28,7 +28,9 @@ import { EServiceWithDescriptorsDeletedV1, Tenant, descriptorState, + generateId, operationForbidden, + unsafeBrandId, } from "pagopa-interop-models"; import { v4 as uuidv4 } from "uuid"; import { PostgreSqlContainer } from "@testcontainers/postgresql"; @@ -425,7 +427,7 @@ describe("database test", async () => { createdAt: new Date( Number(writtenPayload.eServiceDescriptor?.createdAt) ), - id: writtenPayload.eServiceDescriptor!.id, + id: unsafeBrandId(writtenPayload.eServiceDescriptor!.id), serverUrls: [], }; @@ -1360,7 +1362,7 @@ describe("database test", async () => { }; const expectedDescriptor: Descriptor = { ...descriptor, - id: writtenPayload.eService!.descriptors[0].id, + id: unsafeBrandId(writtenPayload.eService!.descriptors[0].id), interface: expectedInterface, createdAt: new Date( Number(writtenPayload.eService?.descriptors[0].createdAt) @@ -1856,7 +1858,7 @@ describe("database test", async () => { const descriptor1: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), interface: mockDocument, state: descriptorState.published, }; @@ -1871,7 +1873,7 @@ describe("database test", async () => { const descriptor2: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), state: descriptorState.draft, }; eService2 = { @@ -1885,7 +1887,7 @@ describe("database test", async () => { const descriptor3: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), interface: mockDocument, state: descriptorState.published, }; @@ -1900,7 +1902,7 @@ describe("database test", async () => { const descriptor4: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), state: descriptorState.draft, }; eService4 = { @@ -1914,7 +1916,7 @@ describe("database test", async () => { const descriptor5: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), interface: mockDocument, state: descriptorState.published, }; @@ -1929,7 +1931,7 @@ describe("database test", async () => { const descriptor6: Descriptor = { ...mockDescriptor, - id: uuidv4(), + id: generateId(), state: descriptorState.draft, }; eService6 = { @@ -2335,7 +2337,7 @@ describe("database test", async () => { await addOneEService(eService, postgresDB, eservices); const result = await readModelService.getDocumentById( eService.id, - uuidv4(), + generateId(), uuidv4() ); expect(result).toBeUndefined(); From c99a5ae43fd5bdca89f46abc546c48622ca06872 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 22 Jan 2024 17:54:24 +0100 Subject: [PATCH 38/77] Improve check on version number --- packages/catalog-process/test/db.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index e77603350b..77cb623f88 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1363,6 +1363,7 @@ describe("database test", async () => { const expectedDescriptor: Descriptor = { ...descriptor, id: unsafeBrandId(writtenPayload.eService!.descriptors[0].id), + version: "1", interface: expectedInterface, createdAt: new Date( Number(writtenPayload.eService?.descriptors[0].createdAt) From b0ef45b1708e5c6811f97523ed736404d687c70b Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 23 Jan 2024 11:18:26 +0100 Subject: [PATCH 39/77] Edit test name --- packages/catalog-process/test/db.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 77cb623f88..9864fd67a7 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -2109,7 +2109,7 @@ describe("database test", async () => { expect(result.totalCount).toBe(0); expect(result.results).toEqual([]); }); - it("should get the eServices if they exist (pagination: offset)", async () => { + it("should get the eServices if they exist (pagination: limit)", async () => { const result = await readModelService.getEServices( getMockAuthData(), { From 23e82ee99d5c01aea3c07da2cdf718988fc04902 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 24 Jan 2024 10:48:24 +0100 Subject: [PATCH 40/77] Fix business logic --- .../src/services/catalogService.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 248f7a2808..97ab79f717 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -432,6 +432,8 @@ export function catalogServiceBuilder( authData, copyFile: fileManager.copy, eService, + getEServiceByNameAndProducerId: + readModelService.getEServiceByNameAndProducerId, }); await repository.createEvent(event); @@ -969,6 +971,7 @@ export async function cloneDescriptorLogic({ authData, copyFile, eService, + getEServiceByNameAndProducerId, }: { eServiceId: string; descriptorId: DescriptorId; @@ -981,12 +984,33 @@ export async function cloneDescriptorLogic({ name: string ) => Promise; eService: WithMetadata | undefined; + getEServiceByNameAndProducerId: ({ + name, + producerId, + }: { + name: string; + producerId: string; + }) => Promise | undefined>; }): Promise<{ eService: EService; event: CreateEvent }> { assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - const descriptor = retrieveDescriptor(descriptorId, eService); + const currentDate = new Date(); + const formattedDateAndTime = `${currentDate.toLocaleDateString( + "it-IT" + )} ${currentDate.toLocaleTimeString("it-IT")}`; + const clonedEServiceName = `${eService.data.name} - clone - ${formattedDateAndTime}`; + if ( + await getEServiceByNameAndProducerId({ + name: clonedEServiceName, + producerId: authData.organizationId, + }) + ) { + throw eServiceDuplicate(clonedEServiceName); + } + + const descriptor = retrieveDescriptor(descriptorId, eService); const sourceDocument = descriptor.docs[0]; const clonedDocumentId = uuidv4(); @@ -1040,7 +1064,7 @@ export async function cloneDescriptorLogic({ const draftCatalogItem: EService = { id: uuidv4(), producerId: eService.data.producerId, - name: `${eService.data.name} - clone`, + name: clonedEServiceName, description: eService.data.description, technology: eService.data.technology, attributes: eService.data.attributes, From 0eb90fe440376a925170a198828e94d84d4ac1bd Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 24 Jan 2024 10:48:38 +0100 Subject: [PATCH 41/77] Fix tests and add coverage --- .../test/catalogService.test.ts | 14 ++++- packages/catalog-process/test/db.test.ts | 61 ++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index 69b26e0d1e..653d35fd20 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -1,5 +1,5 @@ import { generateMock } from "@anatine/zod-mock"; -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { Descriptor, EService, @@ -1143,6 +1143,9 @@ describe("CatalogService", () => { }); describe("cloneDescriptor", () => { it("clone the eService", async () => { + vi.useFakeTimers(); + vi.setSystemTime(new Date()); + const eService: EService = { ...mockEservice, descriptors: [{ ...mockDescriptor, version: "1" }], @@ -1155,6 +1158,7 @@ describe("CatalogService", () => { authData, copyFile: () => Promise.resolve(""), eService: addMetadata(eService), + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }); expect(event.event.type).toBe("ClonedEServiceAdded"); const clonedDescriptor = ( @@ -1165,10 +1169,15 @@ describe("CatalogService", () => { createdAt: Date; interface: { id: string; uploadDate: Date }; }; + const currentDate = new Date(); expect(event.event.data).toMatchObject({ eService: { ...mockEserviceV1, - name: `${mockEserviceV1.name} - clone`, + name: `${ + mockEserviceV1.name + } - clone - ${currentDate.toLocaleDateString( + "it-IT" + )} ${currentDate.toLocaleTimeString("it-IT")}`, createdAt: ( event.event.data as unknown as { eService: { createdAt: Date } } ).eService.createdAt, @@ -1200,6 +1209,7 @@ describe("CatalogService", () => { ], }, }); + vi.useRealTimers(); }); it("returns an error if the eservice doesn't contains the descriptor", async () => { diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 9864fd67a7..a12705fbf9 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -3,7 +3,15 @@ /* eslint-disable @typescript-eslint/no-floating-promises */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import { + afterEach, + beforeAll, + beforeEach, + describe, + expect, + it, + vi, +} from "vitest"; import { AgreementCollection, EServiceCollection, @@ -1315,6 +1323,9 @@ describe("database test", async () => { describe("clone descriptor", () => { it("should write on event-store for the cloning of a descriptor", async () => { + vi.useFakeTimers(); + vi.setSystemTime(new Date()); + const descriptor: Descriptor = { ...mockDescriptor, state: descriptorState.draft, @@ -1370,14 +1381,60 @@ describe("database test", async () => { ), docs: [expectedDocument], }; + const currentDate = new Date(); const expectedEService: EService = { ...eService, id: writtenPayload.eService!.id, - name: `${eService.name} - clone`, + name: `${eService.name} - clone - ${currentDate.toLocaleDateString( + "it-IT" + )} ${currentDate.toLocaleTimeString("it-IT")}`, descriptors: [expectedDescriptor], createdAt: new Date(Number(writtenPayload.eService?.createdAt)), }; expect(writtenPayload.eService).toEqual(toEServiceV1(expectedEService)); + vi.useRealTimers(); + }); + it("should throw eServiceDuplicate if an eService with the same name already exists", async () => { + vi.useFakeTimers(); + vi.setSystemTime(new Date()); + + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + interface: mockDocument, + docs: [mockDocument], + }; + const eService1: EService = { + ...mockEService, + id: generateId(), + descriptors: [descriptor], + }; + await addOneEService(eService1, postgresDB, eservices); + + const currentDate = new Date(); + + const conflictEServiceName = `${ + eService1.name + } - clone - ${currentDate.toLocaleDateString( + "it-IT" + )} ${currentDate.toLocaleTimeString("it-IT")}`; + + const eService2: EService = { + ...mockEService, + id: generateId(), + name: conflictEServiceName, + descriptors: [descriptor], + }; + await addOneEService(eService2, postgresDB, eservices); + + expect( + catalogService.cloneDescriptor( + eService1.id, + descriptor.id, + getMockAuthData(eService1.producerId) + ) + ).rejects.toThrowError(eServiceDuplicate(conflictEServiceName)); + vi.useRealTimers(); }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( From 55fee8744972b5a615afaafa238cacc76987245f Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 24 Jan 2024 14:44:18 +0100 Subject: [PATCH 42/77] Add error in mapper --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 06bad07a1e..a7686ed84b 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -148,6 +148,7 @@ export const cloneEServiceByDescriptorErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("eServiceDuplicate", () => HTTP_STATUS_CONFLICT) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 2e84b4f9940191696b15d7e972215c6fb3bbe507 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 24 Jan 2024 18:16:15 +0100 Subject: [PATCH 43/77] Update business logic --- .../src/services/catalogService.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 97ab79f717..1f645f7db3 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -218,7 +218,14 @@ export function catalogServiceBuilder( const eService = await readModelService.getEServiceById(eServiceId); await repository.createEvent( - updateEserviceLogic({ eService, eServiceId, authData, eServiceSeed }) + await updateEserviceLogic({ + eService, + eServiceId, + authData, + eServiceSeed, + getEServiceByNameAndProducerId: + readModelService.getEServiceByNameAndProducerId, + }) ); }, @@ -491,17 +498,25 @@ export function createEserviceLogic({ return toCreateEventEServiceAdded(newEService); } -export function updateEserviceLogic({ +export async function updateEserviceLogic({ eService, eServiceId, authData, eServiceSeed, + getEServiceByNameAndProducerId, }: { eService: WithMetadata | undefined; eServiceId: string; authData: AuthData; eServiceSeed: ApiEServiceSeed; -}): CreateEvent { + getEServiceByNameAndProducerId: ({ + name, + producerId, + }: { + name: string; + producerId: string; + }) => Promise | undefined>; +}): Promise> { assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); @@ -515,6 +530,14 @@ export function updateEserviceLogic({ throw eServiceCannotBeUpdated(eServiceId); } + if ( + await getEServiceByNameAndProducerId({ + name: eServiceSeed.name, + producerId: authData.organizationId, + }) + ) { + throw eServiceDuplicate(eServiceSeed.name); + } const updatedEService: EService = { ...eService.data, description: eServiceSeed.description, From cab9a4df9816a377067bbfaa1b8ed70986f5bf41 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 24 Jan 2024 18:16:24 +0100 Subject: [PATCH 44/77] Update tests --- .../test/catalogService.test.ts | 13 +++++--- packages/catalog-process/test/db.test.ts | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index 653d35fd20..c12e656e57 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-floating-promises */ import { generateMock } from "@anatine/zod-mock"; import { describe, expect, it, vi } from "vitest"; import { @@ -125,11 +126,12 @@ describe("CatalogService", () => { it("updates the eservice", async () => { const eService = { ...mockEservice, descriptors: [] }; - const event = updateEserviceLogic({ + const event = await updateEserviceLogic({ eService: addMetadata(eService), eServiceId: mockEservice.id, eServiceSeed: mockEserviceSeed, authData, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }); expect(event.event.type).toBe("EServiceUpdated"); expect(event.event.data).toMatchObject({ @@ -155,8 +157,9 @@ describe("CatalogService", () => { eServiceId: mockEservice.id, authData, eServiceSeed: mockEserviceSeed, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(eServiceCannotBeUpdated(mockEservice.id)); + ).rejects.toThrowError(eServiceCannotBeUpdated(mockEservice.id)); }); it("returns an error if the authenticated organization is not the producer", async () => { @@ -172,8 +175,9 @@ describe("CatalogService", () => { ...authData, organizationId: "other-org-id", }, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(operationForbidden); + ).rejects.toThrowError(operationForbidden); }); it("returns an error when the service does not exist", async () => { @@ -187,8 +191,9 @@ describe("CatalogService", () => { ...authData, organizationId: "organizationId", }, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(eServiceNotFound(eServiceId)); + ).rejects.toThrowError(eServiceNotFound(eServiceId)); }); }); describe("deleteEService", () => { diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index a12705fbf9..9e0fa2d5e8 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -259,6 +259,36 @@ describe("database test", async () => { ).rejects.toThrowError(operationForbidden); }); + it("should throw eServiceDuplicate if the updated name is already in use", async () => { + const eService1: EService = { + ...mockEService, + id: generateId(), + descriptors: [], + }; + const eService2: EService = { + ...mockEService, + id: generateId(), + name: "eService name already in use", + descriptors: [], + }; + await addOneEService(eService1, postgresDB, eservices); + await addOneEService(eService2, postgresDB, eservices); + + expect( + catalogService.updateEService( + eService1.id, + { + name: "eService name already in use", + description: "eService description", + technology: "REST", + }, + getMockAuthData(eService1.producerId) + ) + ).rejects.toThrowError( + eServiceDuplicate("eService name already in use") + ); + }); + it("should throw eServiceCannotBeUpdated if the eService descriptor is in published state", async () => { const descriptor: Descriptor = { ...mockDescriptor, From 74c938d93034012a36f5b4c2a3c771951f2c80e9 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 25 Jan 2024 10:37:57 +0100 Subject: [PATCH 45/77] Add check in business logic --- packages/catalog-process/src/services/catalogService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 1f645f7db3..fe9276d82e 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -588,7 +588,11 @@ export function uploadDocumentLogic({ assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); - retrieveDescriptor(descriptorId, eService); + const descriptor = retrieveDescriptor(descriptorId, eService); + + if (descriptor.state !== descriptorState.draft) { + throw notValidDescriptor(descriptor.id, descriptor.state); + } return toCreateEventEServiceDocumentAdded( eServiceId, From 9d70bea5e2ae5ff009abc79842ca4ef93239f8a5 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 25 Jan 2024 10:38:02 +0100 Subject: [PATCH 46/77] Fix previous tests --- .../test/catalogService.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index c12e656e57..ec38520555 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -254,17 +254,25 @@ describe("CatalogService", () => { }); describe("uploadDocument", () => { it("uploads the document", async () => { + const descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + }; + const eService = { + ...mockEservice, + descriptors: [descriptor], + }; const event = uploadDocumentLogic({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: eService.descriptors[0].id, document: mockDocument, authData, - eService: addMetadata(mockEservice), + eService: addMetadata(eService), }); expect(event.event.type).toBe("EServiceDocumentAdded"); expect(event.event.data).toMatchObject({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: eService.descriptors[0].id, document: { id: mockDocument.documentId, name: mockDocument.fileName, From ac01572cca755ef709e15e6533e43556b32ace3d Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 25 Jan 2024 10:38:12 +0100 Subject: [PATCH 47/77] Add new tests --- packages/catalog-process/test/db.test.ts | 84 ++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 9e0fa2d5e8..ac08ebc256 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1696,6 +1696,90 @@ describe("database test", async () => { eServiceDescriptorNotFound(eService.id, mockDescriptor.id) ); }); + it("should throw notValidDescriptor if the descriptor is in published state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.published, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.published) + ); + }); + it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.deprecated) + ); + }); + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); + }); + it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.suspended) + ); + }); }); describe("delete Document", () => { From fdd55d28c2a2324b53b8bef436de79667ccbb30c Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Thu, 25 Jan 2024 10:41:47 +0100 Subject: [PATCH 48/77] Add error in mapper --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index a7686ed84b..7ae1d1e6aa 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -48,6 +48,7 @@ export const documentCreateErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From e044962f63eb794ee9ea9b6f2db15d74d3d51978 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 09:53:35 +0100 Subject: [PATCH 49/77] Fix business logic --- packages/catalog-process/src/services/catalogService.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index fe9276d82e..1da14e7b6c 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -634,6 +634,10 @@ export async function deleteDocumentLogic({ const descriptor = retrieveDescriptor(descriptorId, eService); + if (descriptor.state !== descriptorState.draft) { + throw notValidDescriptor(descriptor.id, descriptor.state); + } + const document = [...descriptor.docs, descriptor.interface].find( (doc) => doc != null && doc.id === documentId ); From 1d1f57b592fc379c157cbdb0dc4ee00e3e33092e Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 09:53:41 +0100 Subject: [PATCH 50/77] Fix previous tests --- .../test/catalogService.test.ts | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index ec38520555..08e9dd92c8 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -337,16 +337,25 @@ describe("CatalogService", () => { }); describe("deleteDocument", () => { it("delete the document", async () => { + const descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService = { + ...mockEservice, + descriptors: [descriptor], + }; const event = await deleteDocumentLogic({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: eService.descriptors[0].id, documentId: mockDocument.documentId, authData, eService: addMetadata({ - ...mockEservice, + ...eService, descriptors: [ { - ...mockEservice.descriptors[0], + ...eService.descriptors[0], docs: [ { path: mockDocument.filePath, @@ -365,27 +374,36 @@ describe("CatalogService", () => { }); expect(event.event.type).toBe("EServiceDocumentDeleted"); expect(event.event.data).toMatchObject({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: eService.descriptors[0].id, documentId: mockDocument.documentId, }); }); - it("returns an error if the eservice doesn't contains the document", async () => { + it("returns an error if the eservice doesn't contain the document", async () => { + const descriptor = { + ...mockDescriptor, + state: descriptorState.draft, + docs: [], + }; + const eService = { + ...mockEservice, + descriptors: [descriptor], + }; const documentId = "document-not-present-id"; await expect(() => deleteDocumentLogic({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: eService.descriptors[0].id, documentId, authData, - eService: addMetadata(mockEservice), + eService: addMetadata(eService), deleteRemoteFile: () => Promise.resolve(), }) ).rejects.toThrowError( eServiceDocumentNotFound( - mockEservice.id, - mockEservice.descriptors[0].id, + eService.id, + eService.descriptors[0].id, documentId ) ); From 16d1692e6313e8892f6e79778c65870260de8809 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 09:53:50 +0100 Subject: [PATCH 51/77] Add test coverage --- packages/catalog-process/test/db.test.ts | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index ac08ebc256..8090bb83ae 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1864,6 +1864,94 @@ describe("database test", async () => { eServiceDescriptorNotFound(eService.id, mockDescriptor.id) ); }); + it("should throw notValidDescriptor if the descriptor is in published state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.published, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.published) + ); + }); + it("should throw notValidDescriptor if the descriptor is in deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.deprecated, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.deprecated) + ); + }); + it("should throw notValidDescriptor if the descriptor is in archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.archived, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); + }); + it("should throw notValidDescriptor if the descriptor is in suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + state: descriptorState.suspended, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.deleteDocument( + eService.id, + descriptor.id, + mockDocument.id, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.suspended) + ); + }); it("should throw eServiceDocumentNotFound if the document doesn't exist", async () => { const descriptor: Descriptor = { ...mockDescriptor, From 0afbc38305ff0396d97dec57510373d375283ab8 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 10:08:28 +0100 Subject: [PATCH 52/77] Fix business logic --- packages/catalog-process/src/model/domain/errors.ts | 11 +++++++++++ .../catalog-process/src/services/catalogService.ts | 5 +++++ .../catalog-process/src/utilities/errorMappers.ts | 1 + 3 files changed, 17 insertions(+) diff --git a/packages/catalog-process/src/model/domain/errors.ts b/packages/catalog-process/src/model/domain/errors.ts index a0d5130b72..d8a254e4ea 100644 --- a/packages/catalog-process/src/model/domain/errors.ts +++ b/packages/catalog-process/src/model/domain/errors.ts @@ -13,6 +13,7 @@ export const errorCodes = { draftDescriptorAlreadyExists: "0008", eserviceCannotBeUpdatedOrDeleted: "0009", eServiceDuplicate: "0010", + interfaceAlreadyExists: "0011", }; export type ErrorCodes = keyof typeof errorCodes; @@ -126,3 +127,13 @@ export function invalidDescriptorVersion( title: "Version is not a valid descriptor version", }); } + +export function interfaceAlreadyExists( + descriptorId: DescriptorId +): ApiError { + return new ApiError({ + detail: `Descriptor ${descriptorId} already contains an interface`, + code: "interfaceAlreadyExists", + title: "Version is not a valid descriptor version", + }); +} diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 1da14e7b6c..d87df7ad25 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -59,6 +59,7 @@ import { notValidDescriptor, eServiceNotFound, eServiceDescriptorWithoutInterface, + interfaceAlreadyExists, } from "../model/domain/errors.js"; import { ReadModelService } from "./readModelService.js"; @@ -594,6 +595,10 @@ export function uploadDocumentLogic({ throw notValidDescriptor(descriptor.id, descriptor.state); } + if (document.kind === "INTERFACE" && descriptor.interface) { + throw interfaceAlreadyExists(descriptor.id); + } + return toCreateEventEServiceDocumentAdded( eServiceId, eService.metadata.version, diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 7ae1d1e6aa..5c2898b672 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -49,6 +49,7 @@ export const documentCreateErrorMapper = ( () => HTTP_STATUS_NOT_FOUND ) .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) + .with("interfaceAlreadyExists", () => HTTP_STATUS_CONFLICT) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 6dd6a9fc2238b4185d61f18d6fe6c54e28bd4340 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 10:08:33 +0100 Subject: [PATCH 53/77] Add test --- packages/catalog-process/test/db.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 8090bb83ae..c7557a320b 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -67,6 +67,7 @@ import { eServiceDocumentNotFound, eServiceDuplicate, eServiceNotFound, + interfaceAlreadyExists, notValidDescriptor, } from "../src/model/domain/errors.js"; import { @@ -1780,6 +1781,26 @@ describe("database test", async () => { notValidDescriptor(descriptor.id, descriptorState.suspended) ); }); + it("should throw interfaceAlreadyExists if the descriptor already contains an interface", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + interface: mockDocument, + state: descriptorState.draft, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.uploadDocument( + eService.id, + mockDescriptor.id, + buildInterfaceSeed(), + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError(interfaceAlreadyExists(descriptor.id)); + }); }); describe("delete Document", () => { From 6453f9d27dd50ab4197348177c26385a6137a43b Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 10:13:31 +0100 Subject: [PATCH 54/77] Fix test --- packages/catalog-process/test/catalogService.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index 08e9dd92c8..c5eeb4a6b5 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -256,6 +256,7 @@ describe("CatalogService", () => { it("uploads the document", async () => { const descriptor = { ...mockDescriptor, + interface: undefined, state: descriptorState.draft, }; const eService = { From 7e4b54b501fa578375dc9cc977453738fed2f2df Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 17:06:46 +0100 Subject: [PATCH 55/77] Refactor --- .../src/services/catalogService.ts | 25 +++++++------------ .../test/catalogService.test.ts | 8 +++--- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 1f645f7db3..4344446277 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -223,8 +223,11 @@ export function catalogServiceBuilder( eServiceId, authData, eServiceSeed, - getEServiceByNameAndProducerId: - readModelService.getEServiceByNameAndProducerId, + eServiceWithSameName: + await readModelService.getEServiceByNameAndProducerId({ + name: eServiceSeed.name, + producerId: authData.organizationId, + }), }) ); }, @@ -503,19 +506,13 @@ export async function updateEserviceLogic({ eServiceId, authData, eServiceSeed, - getEServiceByNameAndProducerId, + eServiceWithSameName, }: { eService: WithMetadata | undefined; eServiceId: string; authData: AuthData; eServiceSeed: ApiEServiceSeed; - getEServiceByNameAndProducerId: ({ - name, - producerId, - }: { - name: string; - producerId: string; - }) => Promise | undefined>; + eServiceWithSameName: WithMetadata | undefined; }): Promise> { assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); @@ -530,14 +527,10 @@ export async function updateEserviceLogic({ throw eServiceCannotBeUpdated(eServiceId); } - if ( - await getEServiceByNameAndProducerId({ - name: eServiceSeed.name, - producerId: authData.organizationId, - }) - ) { + if (eServiceWithSameName) { throw eServiceDuplicate(eServiceSeed.name); } + const updatedEService: EService = { ...eService.data, description: eServiceSeed.description, diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index c12e656e57..ad4f60fc8d 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -131,7 +131,7 @@ describe("CatalogService", () => { eServiceId: mockEservice.id, eServiceSeed: mockEserviceSeed, authData, - getEServiceByNameAndProducerId: () => Promise.resolve(undefined), + eServiceWithSameName: undefined, }); expect(event.event.type).toBe("EServiceUpdated"); expect(event.event.data).toMatchObject({ @@ -157,7 +157,7 @@ describe("CatalogService", () => { eServiceId: mockEservice.id, authData, eServiceSeed: mockEserviceSeed, - getEServiceByNameAndProducerId: () => Promise.resolve(undefined), + eServiceWithSameName: undefined, }) ).rejects.toThrowError(eServiceCannotBeUpdated(mockEservice.id)); }); @@ -175,7 +175,7 @@ describe("CatalogService", () => { ...authData, organizationId: "other-org-id", }, - getEServiceByNameAndProducerId: () => Promise.resolve(undefined), + eServiceWithSameName: undefined, }) ).rejects.toThrowError(operationForbidden); }); @@ -191,7 +191,7 @@ describe("CatalogService", () => { ...authData, organizationId: "organizationId", }, - getEServiceByNameAndProducerId: () => Promise.resolve(undefined), + eServiceWithSameName: undefined, }) ).rejects.toThrowError(eServiceNotFound(eServiceId)); }); From ec16e8f6e3eba0f0652c95793f897ef5a413167f Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 26 Jan 2024 17:32:42 +0100 Subject: [PATCH 56/77] Refactor --- packages/catalog-process/test/db.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 9864fd67a7..5e698f9708 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1062,7 +1062,7 @@ describe("database test", async () => { expect( catalogService.suspendDescriptor( - mockEService.id, + eService.id, mockDescriptor.id, getMockAuthData(mockEService.producerId) ) @@ -1196,9 +1196,9 @@ describe("database test", async () => { expect( catalogService.activateDescriptor( - mockEService.id, + eService.id, mockDescriptor.id, - getMockAuthData(mockEService.producerId) + getMockAuthData(eService.producerId) ) ).rejects.toThrowError( eServiceDescriptorNotFound(eService.id, mockDescriptor.id) @@ -1487,7 +1487,7 @@ describe("database test", async () => { expect( catalogService.archiveDescriptor( - mockEService.id, + eService.id, mockDescriptor.id, getMockAuthData(mockEService.producerId) ) From 01a3934356b9a1e7a1739a47a5975242441c8111 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 09:53:16 +0100 Subject: [PATCH 57/77] Minor fix --- packages/catalog-process/test/catalogService.test.ts | 4 ++-- packages/catalog-process/test/db.test.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index ec38520555..40890faa0f 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -264,7 +264,7 @@ describe("CatalogService", () => { }; const event = uploadDocumentLogic({ eServiceId: eService.id, - descriptorId: eService.descriptors[0].id, + descriptorId: descriptor.id, document: mockDocument, authData, eService: addMetadata(eService), @@ -272,7 +272,7 @@ describe("CatalogService", () => { expect(event.event.type).toBe("EServiceDocumentAdded"); expect(event.event.data).toMatchObject({ eServiceId: eService.id, - descriptorId: eService.descriptors[0].id, + descriptorId: descriptor.id, document: { id: mockDocument.documentId, name: mockDocument.fileName, diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index ac08ebc256..787e7fcf00 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1709,7 +1709,7 @@ describe("database test", async () => { expect( catalogService.uploadDocument( eService.id, - mockDescriptor.id, + descriptor.id, buildInterfaceSeed(), getMockAuthData(eService.producerId) ) @@ -1730,7 +1730,7 @@ describe("database test", async () => { expect( catalogService.uploadDocument( eService.id, - mockDescriptor.id, + descriptor.id, buildInterfaceSeed(), getMockAuthData(eService.producerId) ) @@ -1751,7 +1751,7 @@ describe("database test", async () => { expect( catalogService.uploadDocument( eService.id, - mockDescriptor.id, + descriptor.id, buildInterfaceSeed(), getMockAuthData(eService.producerId) ) @@ -1772,7 +1772,7 @@ describe("database test", async () => { expect( catalogService.uploadDocument( eService.id, - mockDescriptor.id, + descriptor.id, buildInterfaceSeed(), getMockAuthData(eService.producerId) ) From 34fa7c13771f3a51ca90d150af58d1e97bead34c Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 11:02:07 +0100 Subject: [PATCH 58/77] Add error in mapper --- packages/catalog-process/src/utilities/errorMappers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 7ae1d1e6aa..1c4af97b1c 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -62,6 +62,7 @@ export const documentUpdateDeleteErrorMapper = ( "eServiceDocumentNotFound", () => HTTP_STATUS_NOT_FOUND ) + .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 087d815cedad79e5940c079e0565687190dbac55 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 11:03:48 +0100 Subject: [PATCH 59/77] Minor fixes --- .../catalog-process/test/catalogService.test.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index d19e3d196b..36b9d11b45 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -348,14 +348,14 @@ describe("CatalogService", () => { }; const event = await deleteDocumentLogic({ eServiceId: eService.id, - descriptorId: eService.descriptors[0].id, + descriptorId: descriptor.id, documentId: mockDocument.documentId, authData, eService: addMetadata({ ...eService, descriptors: [ { - ...eService.descriptors[0], + ...descriptor, docs: [ { path: mockDocument.filePath, @@ -375,7 +375,7 @@ describe("CatalogService", () => { expect(event.event.type).toBe("EServiceDocumentDeleted"); expect(event.event.data).toMatchObject({ eServiceId: eService.id, - descriptorId: eService.descriptors[0].id, + descriptorId: descriptor.id, documentId: mockDocument.documentId, }); }); @@ -394,18 +394,14 @@ describe("CatalogService", () => { await expect(() => deleteDocumentLogic({ eServiceId: eService.id, - descriptorId: eService.descriptors[0].id, + descriptorId: descriptor.id, documentId, authData, eService: addMetadata(eService), deleteRemoteFile: () => Promise.resolve(), }) ).rejects.toThrowError( - eServiceDocumentNotFound( - eService.id, - eService.descriptors[0].id, - documentId - ) + eServiceDocumentNotFound(eService.id, descriptor.id, documentId) ); }); From 29858366bbd4722d05aca70399a878652401b5c6 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 12:37:33 +0100 Subject: [PATCH 60/77] Fix --- packages/catalog-process/src/services/catalogService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 4344446277..2602bbc35f 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -218,7 +218,7 @@ export function catalogServiceBuilder( const eService = await readModelService.getEServiceById(eServiceId); await repository.createEvent( - await updateEserviceLogic({ + updateEserviceLogic({ eService, eServiceId, authData, @@ -501,7 +501,7 @@ export function createEserviceLogic({ return toCreateEventEServiceAdded(newEService); } -export async function updateEserviceLogic({ +export function updateEserviceLogic({ eService, eServiceId, authData, @@ -513,7 +513,7 @@ export async function updateEserviceLogic({ authData: AuthData; eServiceSeed: ApiEServiceSeed; eServiceWithSameName: WithMetadata | undefined; -}): Promise> { +}): CreateEvent { assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); From a2071564b18d22a049f78647b54b40d640809d60 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 12:42:02 +0100 Subject: [PATCH 61/77] Fix --- packages/catalog-process/test/catalogService.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index ad4f60fc8d..a3fb72ebcd 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -126,7 +126,7 @@ describe("CatalogService", () => { it("updates the eservice", async () => { const eService = { ...mockEservice, descriptors: [] }; - const event = await updateEserviceLogic({ + const event = updateEserviceLogic({ eService: addMetadata(eService), eServiceId: mockEservice.id, eServiceSeed: mockEserviceSeed, From c5b63afeb3474aa32b02aed0f0df2b6d9203a0ed Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 29 Jan 2024 12:43:59 +0100 Subject: [PATCH 62/77] Fix --- packages/catalog-process/test/catalogService.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index a3fb72ebcd..bbc42bc16d 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -159,7 +159,7 @@ describe("CatalogService", () => { eServiceSeed: mockEserviceSeed, eServiceWithSameName: undefined, }) - ).rejects.toThrowError(eServiceCannotBeUpdated(mockEservice.id)); + ).toThrowError(eServiceCannotBeUpdated(mockEservice.id)); }); it("returns an error if the authenticated organization is not the producer", async () => { @@ -177,7 +177,7 @@ describe("CatalogService", () => { }, eServiceWithSameName: undefined, }) - ).rejects.toThrowError(operationForbidden); + ).toThrowError(operationForbidden); }); it("returns an error when the service does not exist", async () => { @@ -193,7 +193,7 @@ describe("CatalogService", () => { }, eServiceWithSameName: undefined, }) - ).rejects.toThrowError(eServiceNotFound(eServiceId)); + ).toThrowError(eServiceNotFound(eServiceId)); }); }); describe("deleteEService", () => { From d568d3f9769482c64968ac45f17c2641604e655a Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 09:15:00 +0100 Subject: [PATCH 63/77] Fix error title --- packages/catalog-process/src/model/domain/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/src/model/domain/errors.ts b/packages/catalog-process/src/model/domain/errors.ts index d8a254e4ea..c1fcb9ce4b 100644 --- a/packages/catalog-process/src/model/domain/errors.ts +++ b/packages/catalog-process/src/model/domain/errors.ts @@ -134,6 +134,6 @@ export function interfaceAlreadyExists( return new ApiError({ detail: `Descriptor ${descriptorId} already contains an interface`, code: "interfaceAlreadyExists", - title: "Version is not a valid descriptor version", + title: "Descriptor already contains an interface", }); } From c65501fa610e6e6af3f2fe4f4512d4e34eb30b97 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 09:56:56 +0100 Subject: [PATCH 64/77] Fix business logic --- packages/catalog-process/src/services/catalogService.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index a4086ebd6d..10ccf14f69 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -673,6 +673,10 @@ export async function updateDocumentLogic({ const descriptor = retrieveDescriptor(descriptorId, eService); + if (descriptor.state !== descriptorState.draft) { + throw notValidDescriptor(descriptor.id, descriptor.state); + } + const document = ( descriptor ? [...descriptor.docs, descriptor.interface] : [] ).find((doc) => doc != null && doc.id === documentId); From a7884ae2e76905c3b642f8fb6c4942be32b440e7 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 09:57:01 +0100 Subject: [PATCH 65/77] Fix tests --- .../test/catalogService.test.ts | 68 ++++++++++++------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index 831d1acdcc..dde1a9e865 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -289,7 +289,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptorId = "descriptor-not-present-id"; expect(() => uploadDocumentLogic({ @@ -445,17 +445,27 @@ describe("CatalogService", () => { describe("updateDocument", () => { it("update the document", async () => { const refDate = new Date(); + const descriptor = { + ...mockDescriptor, + interface: undefined, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService = { + ...mockEservice, + descriptors: [descriptor], + }; const event = await updateDocumentLogic({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, - documentId: mockDocument.documentId, + eServiceId: eService.id, + descriptorId: descriptor.id, + documentId: descriptor.docs[0].documentId, apiEServiceDescriptorDocumentUpdateSeed: mockUpdateDocumentSeed, authData, eService: addMetadata({ - ...mockEservice, + ...eService, descriptors: [ { - ...mockEservice.descriptors[0], + ...descriptor, docs: [ { path: mockDocument.filePath, @@ -473,8 +483,8 @@ describe("CatalogService", () => { }); expect(event.event.type).toBe("EServiceDocumentUpdated"); expect(event.event.data).toMatchObject({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: descriptor.id, documentId: mockDocument.documentId, updatedDocument: { id: mockDocument.documentId, @@ -485,11 +495,11 @@ describe("CatalogService", () => { checksum: mockDocument.checksum, uploadDate: refDate.toISOString(), }, - serverUrls: mockEservice.descriptors[0].serverUrls, + serverUrls: descriptor.serverUrls, }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptorId = "descriptor-not-present-id"; await expect(() => updateDocumentLogic({ @@ -505,23 +515,29 @@ describe("CatalogService", () => { ); }); - it("returns an error if the eservice doesn't contains the document", async () => { + it("returns an error if the eservice doesn't contain the document", async () => { const documentId = "document-not-present-id"; + const descriptor: Descriptor = { + ...mockDescriptor, + interface: undefined, + state: descriptorState.draft, + docs: [mockDocument], + }; + const eService: EService = { + ...mockEservice, + descriptors: [descriptor], + }; await expect(() => updateDocumentLogic({ - eServiceId: mockEservice.id, - descriptorId: mockEservice.descriptors[0].id, + eServiceId: eService.id, + descriptorId: descriptor.id, documentId, apiEServiceDescriptorDocumentUpdateSeed: mockUpdateDocumentSeed, authData, - eService: addMetadata(mockEservice), + eService: addMetadata(eService), }) ).rejects.toThrowError( - eServiceDocumentNotFound( - mockEservice.id, - mockEservice.descriptors[0].id, - documentId - ) + eServiceDocumentNotFound(eService.id, descriptor.id, documentId) ); }); @@ -616,7 +632,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains a draft descriptor", async () => { + it("returns an error if the eservice doesn't contain a draft descriptor", async () => { expect(() => createDescriptorLogic({ eServiceId: mockEservice.id, @@ -682,7 +698,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptorId = "descriptor-not-present-id"; await expect(() => deleteDraftDescriptorLogic({ @@ -770,7 +786,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, state: "Draft" }; const eService: EService = { ...mockEservice, @@ -912,7 +928,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptorId = "descriptor-not-present-id"; expect(() => publishDescriptorLogic({ @@ -1024,7 +1040,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, state: "Published" }; const eService: EService = { ...mockEservice, @@ -1240,7 +1256,7 @@ describe("CatalogService", () => { vi.useRealTimers(); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const eService: EService = { ...mockEservice, descriptors: [mockDescriptor], @@ -1316,7 +1332,7 @@ describe("CatalogService", () => { }); }); - it("returns an error if the eservice doesn't contains the descriptor", async () => { + it("returns an error if the eservice doesn't contain the descriptor", async () => { const eService: EService = { ...mockEservice, descriptors: [mockDescriptor], From 5b8a70b137cc19016efaab58fc12572746d227d9 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 11:13:19 +0100 Subject: [PATCH 66/77] Add test coverage --- packages/catalog-process/test/db.test.ts | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 80c22b19cf..ed462822f6 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -2094,6 +2094,98 @@ describe("database test", async () => { eServiceDescriptorNotFound(eService.id, mockDescriptor.id) ); }); + it("should throw notValidDescriptor if the descriptor is in Published state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + interface: mockDocument, + state: descriptorState.published, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + mockDescriptor.id, + uuidv4(), + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.published) + ); + }); + it("should throw notValidDescriptor if the descriptor is in Suspended state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + interface: mockDocument, + state: descriptorState.suspended, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + mockDescriptor.id, + uuidv4(), + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.suspended) + ); + }); + it("should throw notValidDescriptor if the descriptor is in Archived state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + interface: mockDocument, + state: descriptorState.archived, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + mockDescriptor.id, + uuidv4(), + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.archived) + ); + }); + it("should throw notValidDescriptor if the descriptor is in Deprecated state", async () => { + const descriptor: Descriptor = { + ...mockDescriptor, + interface: mockDocument, + state: descriptorState.deprecated, + }; + const eService: EService = { + ...mockEService, + descriptors: [descriptor], + }; + await addOneEService(eService, postgresDB, eservices); + expect( + catalogService.updateDocument( + eService.id, + mockDescriptor.id, + uuidv4(), + { prettyName: "updated prettyName" }, + getMockAuthData(eService.producerId) + ) + ).rejects.toThrowError( + notValidDescriptor(descriptor.id, descriptorState.deprecated) + ); + }); it("should throw eServiceDocumentNotFound if the document doesn't exist", async () => { const descriptor: Descriptor = { ...mockDescriptor, From e4e96061e6e0a8c27d838f5a8e6a49e3859b5551 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 11:14:31 +0100 Subject: [PATCH 67/77] Change status code --- packages/catalog-process/src/utilities/errorMappers.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/catalog-process/src/utilities/errorMappers.ts b/packages/catalog-process/src/utilities/errorMappers.ts index 121aee21c6..41b34e6b93 100644 --- a/packages/catalog-process/src/utilities/errorMappers.ts +++ b/packages/catalog-process/src/utilities/errorMappers.ts @@ -48,8 +48,11 @@ export const documentCreateErrorMapper = ( "eServiceDescriptorNotFound", () => HTTP_STATUS_NOT_FOUND ) - .with("notValidDescriptor", () => HTTP_STATUS_BAD_REQUEST) - .with("interfaceAlreadyExists", () => HTTP_STATUS_CONFLICT) + .with( + "notValidDescriptor", + "interfaceAlreadyExists", + () => HTTP_STATUS_BAD_REQUEST + ) .with("operationForbidden", () => HTTP_STATUS_FORBIDDEN) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); From 3e3ff7d9205475accaa16d3b386575716347cfa7 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 11:15:12 +0100 Subject: [PATCH 68/77] Fix --- packages/catalog-process/test/db.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 80c22b19cf..5868313ce2 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1795,7 +1795,7 @@ describe("database test", async () => { expect( catalogService.uploadDocument( eService.id, - mockDescriptor.id, + descriptor.id, buildInterfaceSeed(), getMockAuthData(eService.producerId) ) From b53c5043e5de17dd8f27c764387a8c16bfab962a Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 31 Jan 2024 14:29:13 +0100 Subject: [PATCH 69/77] Fix --- packages/catalog-process/test/db.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index ed462822f6..df981fd1bb 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -2108,7 +2108,7 @@ describe("database test", async () => { expect( catalogService.updateDocument( eService.id, - mockDescriptor.id, + descriptor.id, uuidv4(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) @@ -2131,7 +2131,7 @@ describe("database test", async () => { expect( catalogService.updateDocument( eService.id, - mockDescriptor.id, + descriptor.id, uuidv4(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) @@ -2154,7 +2154,7 @@ describe("database test", async () => { expect( catalogService.updateDocument( eService.id, - mockDescriptor.id, + descriptor.id, uuidv4(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) @@ -2177,7 +2177,7 @@ describe("database test", async () => { expect( catalogService.updateDocument( eService.id, - mockDescriptor.id, + descriptor.id, uuidv4(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) From a7016bda4effe181ee8baef96e0dae7a0de4b53e Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Fri, 2 Feb 2024 10:53:46 +0100 Subject: [PATCH 70/77] Fix case where the update doesn't change the name --- packages/catalog-process/src/services/catalogService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 2602bbc35f..964201a87e 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -527,7 +527,10 @@ export function updateEserviceLogic({ throw eServiceCannotBeUpdated(eServiceId); } - if (eServiceWithSameName) { + if ( + eServiceWithSameName && + eServiceWithSameName.data.id !== eService.data.id + ) { throw eServiceDuplicate(eServiceSeed.name); } From 306cc907875b38934f503f62f929f86cc086ec01 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 5 Feb 2024 12:47:38 +0100 Subject: [PATCH 71/77] Refactor --- .../src/services/catalogService.ts | 7 +++---- packages/catalog-process/test/db.test.ts | 15 ++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 97ab79f717..a3cda32571 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -996,10 +996,9 @@ export async function cloneDescriptorLogic({ assertRequesterAllowed(eService.data.producerId, authData.organizationId); const currentDate = new Date(); - const formattedDateAndTime = `${currentDate.toLocaleDateString( - "it-IT" - )} ${currentDate.toLocaleTimeString("it-IT")}`; - const clonedEServiceName = `${eService.data.name} - clone - ${formattedDateAndTime}`; + const currentLocalDate = currentDate.toLocaleDateString("it-IT"); + const currentLocalTime = currentDate.toLocaleTimeString("it-IT"); + const clonedEServiceName = `${eService.data.name} - clone - ${currentLocalDate} ${currentLocalTime}`; if ( await getEServiceByNameAndProducerId({ diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 0f0e858637..32c6d4b11c 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -1382,12 +1382,12 @@ describe("database test", async () => { docs: [expectedDocument], }; const currentDate = new Date(); + const currentLocalDate = currentDate.toLocaleDateString("it-IT"); + const currentLocalTime = currentDate.toLocaleTimeString("it-IT"); const expectedEService: EService = { ...eService, id: writtenPayload.eService!.id, - name: `${eService.name} - clone - ${currentDate.toLocaleDateString( - "it-IT" - )} ${currentDate.toLocaleTimeString("it-IT")}`, + name: `${eService.name} - clone - ${currentLocalDate} ${currentLocalTime}`, descriptors: [expectedDescriptor], createdAt: new Date(Number(writtenPayload.eService?.createdAt)), }; @@ -1412,12 +1412,9 @@ describe("database test", async () => { await addOneEService(eService1, postgresDB, eservices); const currentDate = new Date(); - - const conflictEServiceName = `${ - eService1.name - } - clone - ${currentDate.toLocaleDateString( - "it-IT" - )} ${currentDate.toLocaleTimeString("it-IT")}`; + const currentLocalDate = currentDate.toLocaleDateString("it-IT"); + const currentLocalTime = currentDate.toLocaleTimeString("it-IT"); + const conflictEServiceName = `${eService1.name} - clone - ${currentLocalDate} ${currentLocalTime}`; const eService2: EService = { ...mockEService, From 5c1cfb3c7d08ada59d99796259b0b0f031cce703 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 5 Feb 2024 14:10:34 +0100 Subject: [PATCH 72/77] Improve timing in tests --- packages/catalog-process/test/db.test.ts | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index 32c6d4b11c..65281c2a60 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -4,6 +4,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { + afterAll, afterEach, beforeAll, beforeEach, @@ -1322,10 +1323,15 @@ describe("database test", async () => { }); describe("clone descriptor", () => { - it("should write on event-store for the cloning of a descriptor", async () => { + beforeAll(() => { vi.useFakeTimers(); - vi.setSystemTime(new Date()); + vi.setSystemTime(new Date("2024-01-01T12:00:00")); + }); + afterAll(() => { + vi.useRealTimers(); + }); + it("should write on event-store for the cloning of a descriptor", async () => { const descriptor: Descriptor = { ...mockDescriptor, state: descriptorState.draft, @@ -1381,23 +1387,16 @@ describe("database test", async () => { ), docs: [expectedDocument], }; - const currentDate = new Date(); - const currentLocalDate = currentDate.toLocaleDateString("it-IT"); - const currentLocalTime = currentDate.toLocaleTimeString("it-IT"); const expectedEService: EService = { ...eService, id: writtenPayload.eService!.id, - name: `${eService.name} - clone - ${currentLocalDate} ${currentLocalTime}`, + name: `${eService.name} - clone - 1/1/2024 12:00:00`, descriptors: [expectedDescriptor], createdAt: new Date(Number(writtenPayload.eService?.createdAt)), }; expect(writtenPayload.eService).toEqual(toEServiceV1(expectedEService)); - vi.useRealTimers(); }); it("should throw eServiceDuplicate if an eService with the same name already exists", async () => { - vi.useFakeTimers(); - vi.setSystemTime(new Date()); - const descriptor: Descriptor = { ...mockDescriptor, state: descriptorState.draft, @@ -1411,10 +1410,7 @@ describe("database test", async () => { }; await addOneEService(eService1, postgresDB, eservices); - const currentDate = new Date(); - const currentLocalDate = currentDate.toLocaleDateString("it-IT"); - const currentLocalTime = currentDate.toLocaleTimeString("it-IT"); - const conflictEServiceName = `${eService1.name} - clone - ${currentLocalDate} ${currentLocalTime}`; + const conflictEServiceName = `${eService1.name} - clone - 1/1/2024 12:00:00`; const eService2: EService = { ...mockEService, @@ -1431,7 +1427,6 @@ describe("database test", async () => { getMockAuthData(eService1.producerId) ) ).rejects.toThrowError(eServiceDuplicate(conflictEServiceName)); - vi.useRealTimers(); }); it("should throw eServiceNotFound if the eService doesn't exist", () => { expect( From 2618c67b2825c4d00fd22e5e5bd7fcb1d22291d8 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 5 Feb 2024 15:02:43 +0100 Subject: [PATCH 73/77] Refactor --- .../src/services/catalogService.ts | 27 ++++++++++++------- .../test/catalogService.test.ts | 16 +++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 964201a87e..6e0832ecfc 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -218,16 +218,13 @@ export function catalogServiceBuilder( const eService = await readModelService.getEServiceById(eServiceId); await repository.createEvent( - updateEserviceLogic({ + await updateEserviceLogic({ eService, eServiceId, authData, eServiceSeed, - eServiceWithSameName: - await readModelService.getEServiceByNameAndProducerId({ - name: eServiceSeed.name, - producerId: authData.organizationId, - }), + getEServiceByNameAndProducerId: + readModelService.getEServiceByNameAndProducerId, }) ); }, @@ -501,19 +498,25 @@ export function createEserviceLogic({ return toCreateEventEServiceAdded(newEService); } -export function updateEserviceLogic({ +export async function updateEserviceLogic({ eService, eServiceId, authData, eServiceSeed, - eServiceWithSameName, + getEServiceByNameAndProducerId, }: { eService: WithMetadata | undefined; eServiceId: string; authData: AuthData; eServiceSeed: ApiEServiceSeed; - eServiceWithSameName: WithMetadata | undefined; -}): CreateEvent { + getEServiceByNameAndProducerId: ({ + name, + producerId, + }: { + name: string; + producerId: string; + }) => Promise | undefined>; +}): Promise> { assertEServiceExist(eServiceId, eService); assertRequesterAllowed(eService.data.producerId, authData.organizationId); @@ -527,6 +530,10 @@ export function updateEserviceLogic({ throw eServiceCannotBeUpdated(eServiceId); } + const eServiceWithSameName = await getEServiceByNameAndProducerId({ + name: eServiceSeed.name, + producerId: authData.organizationId, + }); if ( eServiceWithSameName && eServiceWithSameName.data.id !== eService.data.id diff --git a/packages/catalog-process/test/catalogService.test.ts b/packages/catalog-process/test/catalogService.test.ts index bbc42bc16d..c12e656e57 100644 --- a/packages/catalog-process/test/catalogService.test.ts +++ b/packages/catalog-process/test/catalogService.test.ts @@ -126,12 +126,12 @@ describe("CatalogService", () => { it("updates the eservice", async () => { const eService = { ...mockEservice, descriptors: [] }; - const event = updateEserviceLogic({ + const event = await updateEserviceLogic({ eService: addMetadata(eService), eServiceId: mockEservice.id, eServiceSeed: mockEserviceSeed, authData, - eServiceWithSameName: undefined, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }); expect(event.event.type).toBe("EServiceUpdated"); expect(event.event.data).toMatchObject({ @@ -157,9 +157,9 @@ describe("CatalogService", () => { eServiceId: mockEservice.id, authData, eServiceSeed: mockEserviceSeed, - eServiceWithSameName: undefined, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(eServiceCannotBeUpdated(mockEservice.id)); + ).rejects.toThrowError(eServiceCannotBeUpdated(mockEservice.id)); }); it("returns an error if the authenticated organization is not the producer", async () => { @@ -175,9 +175,9 @@ describe("CatalogService", () => { ...authData, organizationId: "other-org-id", }, - eServiceWithSameName: undefined, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(operationForbidden); + ).rejects.toThrowError(operationForbidden); }); it("returns an error when the service does not exist", async () => { @@ -191,9 +191,9 @@ describe("CatalogService", () => { ...authData, organizationId: "organizationId", }, - eServiceWithSameName: undefined, + getEServiceByNameAndProducerId: () => Promise.resolve(undefined), }) - ).toThrowError(eServiceNotFound(eServiceId)); + ).rejects.toThrowError(eServiceNotFound(eServiceId)); }); }); describe("deleteEService", () => { From 4b0e795875e35cf550deba4741f069f39903e619 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Wed, 7 Feb 2024 12:58:07 +0100 Subject: [PATCH 74/77] Fix after merge --- packages/catalog-process/src/services/catalogService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 91738f211b..3c36fd73df 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -991,7 +991,7 @@ export async function cloneDescriptorLogic({ producerId, }: { name: string; - producerId: string; + producerId: TenantId; }) => Promise | undefined>; }): Promise<{ eService: EService; event: CreateEvent }> { assertEServiceExist(eserviceId, eService); From 8c22f22c8f88e2cd5d509eba69c4baa2d6e91484 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 12 Feb 2024 09:48:59 +0100 Subject: [PATCH 75/77] Improve logic to avoid not needed queries --- .../src/services/catalogService.ts | 17 +++++---- packages/catalog-process/test/db.test.ts | 35 ++++++++++++++++++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index 2515b3927f..0cace5069b 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -534,15 +534,14 @@ export async function updateEserviceLogic({ throw eServiceCannotBeUpdated(eserviceId); } - const eServiceWithSameName = await getEServiceByNameAndProducerId({ - name: eServiceSeed.name, - producerId: authData.organizationId, - }); - if ( - eServiceWithSameName && - eServiceWithSameName.data.id !== eService.data.id - ) { - throw eServiceDuplicate(eServiceSeed.name); + if (eServiceSeed.name !== eService.data.name) { + const eServiceWithSameName = await getEServiceByNameAndProducerId({ + name: eServiceSeed.name, + producerId: authData.organizationId, + }); + if (eServiceWithSameName !== undefined) { + throw eServiceDuplicate(eServiceSeed.name); + } } const updatedEService: EService = { diff --git a/packages/catalog-process/test/db.test.ts b/packages/catalog-process/test/db.test.ts index b41dce2c0a..40f3ad33b9 100644 --- a/packages/catalog-process/test/db.test.ts +++ b/packages/catalog-process/test/db.test.ts @@ -197,7 +197,7 @@ describe("database test", async () => { }); describe("update eService", () => { - it("should write on event-store for the update of an eService", async () => { + it("should write on event-store for the update of an eService (update name only)", async () => { const updatedName = "eService new name"; await addOneEService(mockEService, postgresDB, eservices); await catalogService.updateEService( @@ -230,6 +230,39 @@ describe("database test", async () => { expect(writtenPayload.eService).toEqual(toEServiceV1(updatedEService)); }); + it("should write on event-store for the update of an eService (update description only)", async () => { + const updatedDescription = "eService new description"; + await addOneEService(mockEService, postgresDB, eservices); + await catalogService.updateEService( + mockEService.id, + { + name: mockEService.name, + description: updatedDescription, + technology: "REST", + }, + getMockAuthData(mockEService.producerId) + ); + + const updatedEService: EService = { + ...mockEService, + description: updatedDescription, + }; + + const writtenEvent = await readLastEventByStreamId( + mockEService.id, + postgresDB + ); + expect(writtenEvent.stream_id).toBe(mockEService.id); + expect(writtenEvent.version).toBe("1"); + expect(writtenEvent.type).toBe("EServiceUpdated"); + const writtenPayload = decodeProtobufPayload({ + messageType: EServiceUpdatedV1, + payload: writtenEvent.data, + }); + + expect(writtenPayload.eService).toEqual(toEServiceV1(updatedEService)); + }); + it("should throw eServiceNotFound if the eService doesn't exist", async () => { expect( catalogService.updateEService( From 44ded2510352239da0ff69a48439d4fdfa1c329e Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 13 Feb 2024 10:23:41 +0100 Subject: [PATCH 76/77] Refactor and fix id --- .../test/catalogService.integration.test.ts | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/catalog-process/test/catalogService.integration.test.ts b/packages/catalog-process/test/catalogService.integration.test.ts index 57c59c6f11..c3c29f6b11 100644 --- a/packages/catalog-process/test/catalogService.integration.test.ts +++ b/packages/catalog-process/test/catalogService.integration.test.ts @@ -27,6 +27,7 @@ import { EServiceUpdatedV1, EServiceWithDescriptorsDeletedV1, Tenant, + TenantId, descriptorState, generateId, operationForbidden, @@ -1346,7 +1347,9 @@ describe("database test", async () => { const expectedInterface: Document = { ...mockDocument, - id: writtenPayload.eService!.descriptors[0].interface!.id, + id: unsafeBrandId( + writtenPayload.eService!.descriptors[0].interface!.id + ), uploadDate: new Date( writtenPayload.eService!.descriptors[0].docs[0].uploadDate ), @@ -1354,7 +1357,7 @@ describe("database test", async () => { }; const expectedDocument: Document = { ...mockDocument, - id: writtenPayload.eService!.descriptors[0].docs[0].id, + id: unsafeBrandId(writtenPayload.eService!.descriptors[0].docs[0].id), uploadDate: new Date( writtenPayload.eService!.descriptors[0].docs[0].uploadDate ), @@ -1372,7 +1375,7 @@ describe("database test", async () => { }; const expectedEService: EService = { ...eService, - id: writtenPayload.eService!.id, + id: unsafeBrandId(writtenPayload.eService!.id), name: `${eService.name} - clone`, descriptors: [expectedDescriptor], createdAt: new Date(Number(writtenPayload.eService?.createdAt)), @@ -1554,9 +1557,9 @@ describe("database test", async () => { buildInterfaceSeed().serverUrls ); - const expectedDocument = { + const expectedDocument: Document = { ...mockDocument, - id: writtenPayload.document!.id, + id: unsafeBrandId(writtenPayload.document!.id), checksum: writtenPayload.document!.checksum, uploadDate: new Date(writtenPayload.document!.uploadDate), }; @@ -1806,7 +1809,7 @@ describe("database test", async () => { catalogService.updateDocument( eService.id, mockDescriptor.id, - uuidv4(), + generateId(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) ) @@ -1842,9 +1845,9 @@ describe("database test", async () => { describe("ReadModel Service", () => { describe("getEservices", () => { - let organizationId1: string; - let organizationId2: string; - let organizationId3: string; + let organizationId1: TenantId; + let organizationId2: TenantId; + let organizationId3: TenantId; let eService1: EService; let eService2: EService; let eService3: EService; @@ -1853,9 +1856,9 @@ describe("database test", async () => { let eService6: EService; beforeEach(async () => { - organizationId1 = uuidv4(); - organizationId2 = uuidv4(); - organizationId3 = uuidv4(); + organizationId1 = generateId(); + organizationId2 = generateId(); + organizationId3 = generateId(); const descriptor1: Descriptor = { ...mockDescriptor, @@ -1865,7 +1868,7 @@ describe("database test", async () => { }; eService1 = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 001 test", descriptors: [descriptor1], producerId: organizationId1, @@ -1879,7 +1882,7 @@ describe("database test", async () => { }; eService2 = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 002 test", descriptors: [descriptor2], producerId: organizationId1, @@ -1894,7 +1897,7 @@ describe("database test", async () => { }; eService3 = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 003 test", descriptors: [descriptor3], producerId: organizationId1, @@ -1908,7 +1911,7 @@ describe("database test", async () => { }; eService4 = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 004 test", producerId: organizationId2, descriptors: [descriptor4], @@ -1966,7 +1969,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: eservicesIds)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [eService1.id, eService2.id], producersIds: [], @@ -1981,7 +1984,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: producersIds)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [organizationId1], @@ -1996,7 +1999,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: states)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [], @@ -2011,7 +2014,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: agreementStates)", async () => { const result = await readModelService.getEServices( - getMockAuthData(organizationId3), + organizationId3, { eservicesIds: [], producersIds: [], @@ -2026,7 +2029,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: name)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [], @@ -2047,7 +2050,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: states, agreementStates, name)", async () => { const result = await readModelService.getEServices( - getMockAuthData(organizationId3), + organizationId3, { eservicesIds: [], producersIds: [], @@ -2063,7 +2066,7 @@ describe("database test", async () => { }); it("should not get the eServices if they don't exist (parameters: states, agreementStates, name)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [], @@ -2079,7 +2082,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (parameters: producersIds, states, name)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [organizationId2], @@ -2095,7 +2098,7 @@ describe("database test", async () => { }); it("should not get the eServices if they don't exist (parameters: producersIds, states, name)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [organizationId2], @@ -2111,7 +2114,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (pagination: limit)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [], @@ -2126,7 +2129,7 @@ describe("database test", async () => { }); it("should get the eServices if they exist (pagination: offset, limit)", async () => { const result = await readModelService.getEServices( - getMockAuthData(), + generateId(), { eservicesIds: [], producersIds: [], @@ -2143,8 +2146,8 @@ describe("database test", async () => { describe("getEServiceByNameAndProducerId", () => { it("should get the eService if it matches the name and the producerId", async () => { - const organizationId1 = uuidv4(); - const organizationId2 = uuidv4(); + const organizationId1: TenantId = generateId(); + const organizationId2: TenantId = generateId(); const eService1: EService = { ...mockEService, id: generateId(), @@ -2176,7 +2179,7 @@ describe("database test", async () => { expect(result?.data).toEqual(eService1); }); it("should not get the eService if it doesn't exist", async () => { - const organizationId = uuidv4(); + const organizationId: TenantId = generateId(); const eService1: EService = { ...mockEService, id: generateId(), @@ -2249,7 +2252,7 @@ describe("database test", async () => { it("should not get the eService if it doesn't exist", async () => { await addOneEService(mockEService, postgresDB, eservices); - const result = await readModelService.getEServiceById(uuidv4()); + const result = await readModelService.getEServiceById(generateId()); expect(result).toBeUndefined(); }); }); @@ -2315,7 +2318,7 @@ describe("database test", async () => { }; const eService: EService = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 001", descriptors: [descriptor], }; @@ -2331,7 +2334,7 @@ describe("database test", async () => { it("should not get document if it doesn't exist", async () => { const eService: EService = { ...mockEService, - id: uuidv4(), + id: generateId(), name: "eService 001", descriptors: [], }; @@ -2339,7 +2342,7 @@ describe("database test", async () => { const result = await readModelService.getDocumentById( eService.id, generateId(), - uuidv4() + generateId() ); expect(result).toBeUndefined(); }); From 6bf00e64a5813dcf7f49ba070dd70927c4e416a2 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 13 Feb 2024 17:51:49 +0100 Subject: [PATCH 77/77] Fix ids --- .../test/catalogService.integration.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/catalog-process/test/catalogService.integration.test.ts b/packages/catalog-process/test/catalogService.integration.test.ts index e2819ceabf..6ff7e7bf4d 100644 --- a/packages/catalog-process/test/catalogService.integration.test.ts +++ b/packages/catalog-process/test/catalogService.integration.test.ts @@ -2140,7 +2140,7 @@ describe("database test", async () => { catalogService.updateDocument( eService.id, descriptor.id, - uuidv4(), + generateId(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) ) @@ -2163,7 +2163,7 @@ describe("database test", async () => { catalogService.updateDocument( eService.id, descriptor.id, - uuidv4(), + generateId(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) ) @@ -2186,7 +2186,7 @@ describe("database test", async () => { catalogService.updateDocument( eService.id, descriptor.id, - uuidv4(), + generateId(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) ) @@ -2209,7 +2209,7 @@ describe("database test", async () => { catalogService.updateDocument( eService.id, descriptor.id, - uuidv4(), + generateId(), { prettyName: "updated prettyName" }, getMockAuthData(eService.producerId) )