Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<this.prodRelationships.length;i++){
rels.push({
Expand Down
Loading