diff --git a/packages/catalog-process/src/services/catalogService.ts b/packages/catalog-process/src/services/catalogService.ts index e9f245aa8c..372c2ec56d 100644 --- a/packages/catalog-process/src/services/catalogService.ts +++ b/packages/catalog-process/src/services/catalogService.ts @@ -760,6 +760,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); diff --git a/packages/catalog-process/test/catalogService.integration.test.ts b/packages/catalog-process/test/catalogService.integration.test.ts index 550c51e7e4..6ff7e7bf4d 100644 --- a/packages/catalog-process/test/catalogService.integration.test.ts +++ b/packages/catalog-process/test/catalogService.integration.test.ts @@ -2125,6 +2125,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, + descriptor.id, + generateId(), + { 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, + descriptor.id, + generateId(), + { 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, + descriptor.id, + generateId(), + { 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, + descriptor.id, + generateId(), + { 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,