From 5a6a7a9e593a8d19792ba07d10dbc49e9a6a2c84 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 16 Aug 2019 16:48:51 -0400 Subject: [PATCH] LP1840050 IDL pkeyMatches function/tests Function to compare whether two IdlObjects are of the same class and have matching pkey values. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- Open-ILS/src/eg2/src/app/core/idl.service.ts | 9 +++++++++ Open-ILS/src/eg2/src/app/core/idl.spec.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Open-ILS/src/eg2/src/app/core/idl.service.ts b/Open-ILS/src/eg2/src/app/core/idl.service.ts index 21ec24a274..b5abf61d78 100644 --- a/Open-ILS/src/eg2/src/app/core/idl.service.ts +++ b/Open-ILS/src/eg2/src/app/core/idl.service.ts @@ -196,5 +196,14 @@ export class IdlService { return hash; } + + // Returns true if both objects have the same IDL class and pkey value. + pkeyMatches(obj1: IdlObject, obj2: IdlObject) { + if (!obj1 || !obj2) { return false; } + const idlClass = obj1.classname; + if (idlClass !== obj2.classname) { return false; } + const pkeyField = this.classes[idlClass].pkey || 'id'; + return obj1[pkeyField]() === obj2[pkeyField](); + } } diff --git a/Open-ILS/src/eg2/src/app/core/idl.spec.ts b/Open-ILS/src/eg2/src/app/core/idl.spec.ts index 8138bf453c..49439fdb10 100644 --- a/Open-ILS/src/eg2/src/app/core/idl.spec.ts +++ b/Open-ILS/src/eg2/src/app/core/idl.spec.ts @@ -24,5 +24,33 @@ describe('IdlService', () => { expect(org.name()).toBe('AN ORG'); }); + it('should correctly compare IDL pkey values', () => { + service.parseIdl(); + const org1 = service.create('aou'); + const org2 = service.create('aou'); + org1.id(123); + org2.id(123); + expect(service.pkeyMatches(org1, org2)).toBe(true); + }); + + it('should correctly compare IDL pkey values', () => { + service.parseIdl(); + const org1 = service.create('aou'); + const org2 = service.create('aou'); + org1.id(123); + org2.id(456); + expect(service.pkeyMatches(org1, org2)).toBe(false); + }); + + it('should correctly compare IDL classes in pkey match', () => { + service.parseIdl(); + const org = service.create('aou'); + const user = service.create('au'); + org.id(123); + user.id(123); + expect(service.pkeyMatches(org, user)).toBe(false); + }); + + }); -- 2.11.0