From 7216f417348b503abff9f5951bf9a61e2193cafb Mon Sep 17 00:00:00 2001 From: Francisco de la Vega Date: Wed, 6 May 2026 17:50:33 +0200 Subject: [PATCH] Fix bug with lost self attestation --- .../create-product-spec.component.spec.ts | 30 ++++++++++++++++ .../create-product-spec.component.ts | 36 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.spec.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.spec.ts index 67206d12..9b8d111f 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.spec.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.spec.ts @@ -1104,6 +1104,36 @@ describe('CreateProductSpecComponent', () => { expect(component.productSpecToCreate?.productSpecCharacteristic?.some((c: any) => c.name === 'B')).toBeTrue(); }); + it('showFinish should include self attestation even when it is not in prodChars', () => { + component.partyId = 'party-1'; + component.generalForm.patchValue({ + name: 'My Product', + description: 'Desc', + version: '1.0', + brand: 'Brand', + number: 'PN-1' + }); + component.selectedISOS = []; + component.additionalISOS = []; + component.prodRelationships = []; + component.prodAttachments = []; + component.selectedResourceSpecs = []; + component.selectedServiceSpecs = []; + component.prodChars = [{ id: 'char-1', name: 'Feature', productSpecCharacteristicValue: [{ value: 'x' }] } as any]; + component.selfAtt = { + id: 'self-att-1', + name: 'Compliance:SelfAtt', + productSpecCharacteristicValue: [{ isDefault: true, value: 'https://self-att' }] + }; + + component.showFinish(); + + const selfAtt = component.productSpecToCreate?.productSpecCharacteristic?.find((c: any) => c.name === 'Compliance:SelfAtt'); + const selfAttValue = (selfAtt as any)?.productSpecCharacteristicValue?.[0]?.value; + expect(selfAtt).toBeDefined(); + expect(selfAttValue).toBe('https://self-att'); + }); + it('createProduct should call API and go back on success', () => { const backSpy = spyOn(component, 'goBack'); component.productSpecToCreate = { name: 'Prod' } as any; diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts index 6359cad6..74b83125 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts @@ -459,6 +459,14 @@ export class CreateProductSpecComponent implements OnInit, OnDestroy { } + private hasSelfAttestation(): boolean { + const selfAttestationValue = this.selfAtt?.productSpecCharacteristicValue?.[0]?.value; + if (typeof selfAttestationValue === 'string') { + return selfAttestationValue.trim() !== ''; + } + return !!selfAttestationValue; + } + public dropped(files: NgxFileDropEntry[],sel:any) { this.files = files; for (const droppedFile of files) { @@ -1497,6 +1505,34 @@ export class CreateProductSpecComponent implements OnInit, OnDestroy { } console.log(this.finishChars) } + + // Keep self attestation from compliance step in final payload. + if (this.hasSelfAttestation()) { + const selfAttName = 'Compliance:SelfAtt'; + const selfAttValue = this.selfAtt?.productSpecCharacteristicValue?.[0]?.value; + const selfAttIndex = this.finishChars.findIndex(item => item.name === selfAttName); + const selfAttId = this.selfAtt?.id + ? this.selfAtt.id + : (selfAttIndex !== -1 && this.finishChars[selfAttIndex]?.id + ? this.finishChars[selfAttIndex].id + : `urn:ngsi-ld:characteristic:${uuidv4()}`); + + const selfAttestationCharacteristic = { + id: selfAttId, + name: selfAttName, + productSpecCharacteristicValue: [{ + isDefault: true, + value: selfAttValue + }] + } as ProductSpecificationCharacteristic; + + if (selfAttIndex === -1) { + this.finishChars.push(selfAttestationCharacteristic); + } else { + this.finishChars[selfAttIndex] = selfAttestationCharacteristic; + } + } + let rels = []; for(let i=0; i