@contrail/flexplm 1.7.0 → 1.7.1-alpha.e5225c7

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,12 @@ class BaseEntityProcessor {
183
183
  return undefined;
184
184
  }
185
185
  const entityReference = identityEntity.entityReference;
186
- const [entityName, id] = entityReference.split(':');
186
+ const firstColonIndex = entityReference.indexOf(':');
187
+ if (firstColonIndex === -1 || firstColonIndex === 0 || firstColonIndex === entityReference.length - 1) {
188
+ throw new Error('Invalid entityReference: ' + entityReference);
189
+ }
190
+ const entityName = entityReference.slice(0, firstColonIndex);
191
+ const id = entityReference.slice(firstColonIndex + 1);
187
192
  const entity = await this.entities.get({
188
193
  entityName,
189
194
  id
@@ -585,5 +585,64 @@ 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 entityReference: item1');
627
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
628
+ });
629
+ it('should throw error when entityReference starts with a colon (missing entityName)', async () => {
630
+ mockEntitiesGet.mockResolvedValue([{ entityReference: ':1' }]);
631
+ await expect(btep.getEntityUsingIdentityService({
632
+ poolKey: 'item',
633
+ propertyName: 'itemNumber',
634
+ propertyValue: '12345'
635
+ })).rejects.toThrow('Invalid entityReference: :1');
636
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
637
+ });
638
+ it('should throw error when entityReference ends with a colon (missing id)', async () => {
639
+ mockEntitiesGet.mockResolvedValue([{ entityReference: 'item:' }]);
640
+ await expect(btep.getEntityUsingIdentityService({
641
+ poolKey: 'item',
642
+ propertyName: 'itemNumber',
643
+ propertyValue: '12345'
644
+ })).rejects.toThrow('Invalid entityReference: item:');
645
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
646
+ });
588
647
  });
589
648
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.7.0",
3
+ "version": "1.7.1-alpha.e5225c7",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",