Skip to content

Commit 4eb83f4

Browse files
authored
Fix bug with lost self attestation (#246)
1 parent 5e7261b commit 4eb83f4

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,36 @@ describe('CreateProductSpecComponent', () => {
11041104
expect(component.productSpecToCreate?.productSpecCharacteristic?.some((c: any) => c.name === 'B')).toBeTrue();
11051105
});
11061106

1107+
it('showFinish should include self attestation even when it is not in prodChars', () => {
1108+
component.partyId = 'party-1';
1109+
component.generalForm.patchValue({
1110+
name: 'My Product',
1111+
description: 'Desc',
1112+
version: '1.0',
1113+
brand: 'Brand',
1114+
number: 'PN-1'
1115+
});
1116+
component.selectedISOS = [];
1117+
component.additionalISOS = [];
1118+
component.prodRelationships = [];
1119+
component.prodAttachments = [];
1120+
component.selectedResourceSpecs = [];
1121+
component.selectedServiceSpecs = [];
1122+
component.prodChars = [{ id: 'char-1', name: 'Feature', productSpecCharacteristicValue: [{ value: 'x' }] } as any];
1123+
component.selfAtt = {
1124+
id: 'self-att-1',
1125+
name: 'Compliance:SelfAtt',
1126+
productSpecCharacteristicValue: [{ isDefault: true, value: 'https://self-att' }]
1127+
};
1128+
1129+
component.showFinish();
1130+
1131+
const selfAtt = component.productSpecToCreate?.productSpecCharacteristic?.find((c: any) => c.name === 'Compliance:SelfAtt');
1132+
const selfAttValue = (selfAtt as any)?.productSpecCharacteristicValue?.[0]?.value;
1133+
expect(selfAtt).toBeDefined();
1134+
expect(selfAttValue).toBe('https://self-att');
1135+
});
1136+
11071137
it('createProduct should call API and go back on success', () => {
11081138
const backSpy = spyOn(component, 'goBack');
11091139
component.productSpecToCreate = { name: 'Prod' } as any;

src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,14 @@ export class CreateProductSpecComponent implements OnInit, OnDestroy {
459459

460460
}
461461

462+
private hasSelfAttestation(): boolean {
463+
const selfAttestationValue = this.selfAtt?.productSpecCharacteristicValue?.[0]?.value;
464+
if (typeof selfAttestationValue === 'string') {
465+
return selfAttestationValue.trim() !== '';
466+
}
467+
return !!selfAttestationValue;
468+
}
469+
462470
public dropped(files: NgxFileDropEntry[],sel:any) {
463471
this.files = files;
464472
for (const droppedFile of files) {
@@ -1497,6 +1505,34 @@ export class CreateProductSpecComponent implements OnInit, OnDestroy {
14971505
}
14981506
console.log(this.finishChars)
14991507
}
1508+
1509+
// Keep self attestation from compliance step in final payload.
1510+
if (this.hasSelfAttestation()) {
1511+
const selfAttName = 'Compliance:SelfAtt';
1512+
const selfAttValue = this.selfAtt?.productSpecCharacteristicValue?.[0]?.value;
1513+
const selfAttIndex = this.finishChars.findIndex(item => item.name === selfAttName);
1514+
const selfAttId = this.selfAtt?.id
1515+
? this.selfAtt.id
1516+
: (selfAttIndex !== -1 && this.finishChars[selfAttIndex]?.id
1517+
? this.finishChars[selfAttIndex].id
1518+
: `urn:ngsi-ld:characteristic:${uuidv4()}`);
1519+
1520+
const selfAttestationCharacteristic = {
1521+
id: selfAttId,
1522+
name: selfAttName,
1523+
productSpecCharacteristicValue: [{
1524+
isDefault: true,
1525+
value: selfAttValue
1526+
}]
1527+
} as ProductSpecificationCharacteristic;
1528+
1529+
if (selfAttIndex === -1) {
1530+
this.finishChars.push(selfAttestationCharacteristic);
1531+
} else {
1532+
this.finishChars[selfAttIndex] = selfAttestationCharacteristic;
1533+
}
1534+
}
1535+
15001536
let rels = [];
15011537
for(let i=0; i<this.prodRelationships.length;i++){
15021538
rels.push({

0 commit comments

Comments
 (0)