UNPKG

domain-objects

Version:

A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.

38 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const test_fns_1 = require("test-fns"); const DomainEntity_1 = require("../instantiation/DomainEntity"); const getReferenceTo_1 = require("./getReferenceTo"); const isUniqueKeyRef_1 = require("./isUniqueKeyRef"); describe('getReferenceTo', () => { (0, test_fns_1.given)('a domain entity', () => { class SeaTurtle extends DomainEntity_1.DomainEntity { } SeaTurtle.primary = ['uuid']; SeaTurtle.unique = ['saltwaterSecurityNumber']; it('should be able to get a reference to it, without primary key', () => { const dobj = new SeaTurtle({ saltwaterSecurityNumber: '821', name: 'shellbert', age: 7, }); const ref = (0, getReferenceTo_1.getRef)(dobj); expect(ref._dobj).toEqual(SeaTurtle.name); if ((0, isUniqueKeyRef_1.isUniqueKeyRef)({ of: SeaTurtle })(ref)) expect(ref.saltwaterSecurityNumber).toEqual('821'); }); it('should be able to get a reference to it, with primary key', () => { const dobj = new SeaTurtle({ uuid: '__uuid__', saltwaterSecurityNumber: '821', name: 'shellbert', age: 7, }); const ref = (0, getReferenceTo_1.getRef)(dobj); expect(ref._dobj).toEqual(SeaTurtle.name); if ((0, isUniqueKeyRef_1.isUniqueKeyRef)({ of: SeaTurtle })(ref)) expect(ref.saltwaterSecurityNumber).toEqual('821'); }); }); }); //# sourceMappingURL=getReferenceTo.test.js.map