@contrail/flexplm 1.7.0 → 1.7.1-alpha.a1f78e7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -183,7 +183,15 @@ class BaseEntityProcessor {
|
|
|
183
183
|
return undefined;
|
|
184
184
|
}
|
|
185
185
|
const entityReference = identityEntity.entityReference;
|
|
186
|
-
|
|
186
|
+
if (typeof entityReference !== 'string' || !entityReference.includes(':')) {
|
|
187
|
+
throw new Error(`Invalid identity entityReference: ${String(entityReference)}`);
|
|
188
|
+
}
|
|
189
|
+
const firstColonIndex = entityReference.indexOf(':');
|
|
190
|
+
if (firstColonIndex === 0 || firstColonIndex === entityReference.length - 1) {
|
|
191
|
+
throw new Error('Invalid identity entityReference: ' + entityReference);
|
|
192
|
+
}
|
|
193
|
+
const entityName = entityReference.slice(0, firstColonIndex);
|
|
194
|
+
const id = entityReference.slice(firstColonIndex + 1);
|
|
187
195
|
const entity = await this.entities.get({
|
|
188
196
|
entityName,
|
|
189
197
|
id
|
|
@@ -585,5 +585,82 @@ describe('BaseEntityProcessor', () => {
|
|
|
585
585
|
id: '5'
|
|
586
586
|
});
|
|
587
587
|
});
|
|
588
|
+
it('should split entityReference on the first colon only when the id itself contains colons (project-item)', async () => {
|
|
589
|
+
const mockEntity = { id: 'e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf', name: 'Test Project Item' };
|
|
590
|
+
mockEntitiesGet
|
|
591
|
+
.mockResolvedValueOnce([{ entityReference: 'project-item:e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf' }])
|
|
592
|
+
.mockResolvedValueOnce(mockEntity);
|
|
593
|
+
const result = await btep.getEntityUsingIdentityService({
|
|
594
|
+
poolKey: 'project-item',
|
|
595
|
+
propertyName: 'itemNumber',
|
|
596
|
+
propertyValue: '12345'
|
|
597
|
+
});
|
|
598
|
+
expect(result).toEqual(mockEntity);
|
|
599
|
+
expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
|
|
600
|
+
entityName: 'project-item',
|
|
601
|
+
id: 'e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf'
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
it('should split entityReference on the first colon only when identity result is a single object with a composite id', async () => {
|
|
605
|
+
const mockEntity = { id: 'e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf' };
|
|
606
|
+
mockEntitiesGet
|
|
607
|
+
.mockResolvedValueOnce({ entityReference: 'project-item:e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf' })
|
|
608
|
+
.mockResolvedValueOnce(mockEntity);
|
|
609
|
+
const result = await btep.getEntityUsingIdentityService({
|
|
610
|
+
poolKey: 'project-item',
|
|
611
|
+
propertyName: 'itemNumber',
|
|
612
|
+
propertyValue: '12345'
|
|
613
|
+
});
|
|
614
|
+
expect(result).toEqual(mockEntity);
|
|
615
|
+
expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
|
|
616
|
+
entityName: 'project-item',
|
|
617
|
+
id: 'e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf'
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
it('should throw error when entityReference has no colon', async () => {
|
|
621
|
+
mockEntitiesGet.mockResolvedValue([{ entityReference: 'item1' }]);
|
|
622
|
+
await expect(btep.getEntityUsingIdentityService({
|
|
623
|
+
poolKey: 'item',
|
|
624
|
+
propertyName: 'itemNumber',
|
|
625
|
+
propertyValue: '12345'
|
|
626
|
+
})).rejects.toThrow('Invalid identity entityReference: item1');
|
|
627
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
628
|
+
});
|
|
629
|
+
it('should throw error when entityReference is not a string', async () => {
|
|
630
|
+
mockEntitiesGet.mockResolvedValue([{ entityReference: 12345 }]);
|
|
631
|
+
await expect(btep.getEntityUsingIdentityService({
|
|
632
|
+
poolKey: 'item',
|
|
633
|
+
propertyName: 'itemNumber',
|
|
634
|
+
propertyValue: '12345'
|
|
635
|
+
})).rejects.toThrow('Invalid identity entityReference: 12345');
|
|
636
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
637
|
+
});
|
|
638
|
+
it('should throw error when entityReference is undefined', async () => {
|
|
639
|
+
mockEntitiesGet.mockResolvedValue([{}]);
|
|
640
|
+
await expect(btep.getEntityUsingIdentityService({
|
|
641
|
+
poolKey: 'item',
|
|
642
|
+
propertyName: 'itemNumber',
|
|
643
|
+
propertyValue: '12345'
|
|
644
|
+
})).rejects.toThrow('Invalid identity entityReference: undefined');
|
|
645
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
646
|
+
});
|
|
647
|
+
it('should throw error when entityReference starts with a colon (missing entityName)', async () => {
|
|
648
|
+
mockEntitiesGet.mockResolvedValue([{ entityReference: ':1' }]);
|
|
649
|
+
await expect(btep.getEntityUsingIdentityService({
|
|
650
|
+
poolKey: 'item',
|
|
651
|
+
propertyName: 'itemNumber',
|
|
652
|
+
propertyValue: '12345'
|
|
653
|
+
})).rejects.toThrow('Invalid identity entityReference: :1');
|
|
654
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
655
|
+
});
|
|
656
|
+
it('should throw error when entityReference ends with a colon (missing id)', async () => {
|
|
657
|
+
mockEntitiesGet.mockResolvedValue([{ entityReference: 'item:' }]);
|
|
658
|
+
await expect(btep.getEntityUsingIdentityService({
|
|
659
|
+
poolKey: 'item',
|
|
660
|
+
propertyName: 'itemNumber',
|
|
661
|
+
propertyValue: '12345'
|
|
662
|
+
})).rejects.toThrow('Invalid identity entityReference: item:');
|
|
663
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
664
|
+
});
|
|
588
665
|
});
|
|
589
666
|
});
|