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]();
+ }
}
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);
+ });
+
+
});