domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
108 lines • 4.37 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const test_fns_1 = require("test-fns");
const DomainEntity_1 = require("../instantiation/DomainEntity");
describe('DomainReference', () => {
(0, test_fns_1.given)('a domain entity', () => {
class SeaTurtle extends DomainEntity_1.DomainEntity {
}
SeaTurtle.primary = ['uuid'];
SeaTurtle.unique = ['saltwaterSecurityNumber'];
class EarthWorm extends DomainEntity_1.DomainEntity {
}
EarthWorm.primary = ['uuid'];
EarthWorm.unique = [
'soilSecurityNumber',
'wormSegmentNumber',
];
it('should be able to define a unique key reference', () => {
const ref = {
saltwaterSecurityNumber: '821',
};
expect(ref.saltwaterSecurityNumber).toEqual('821');
// @ts-expect-error; uuid does not exist
expect(ref.uuid).toEqual(undefined);
});
it('should be able to define a primary key ref', () => {
const ref = {
uuid: '__uuid__',
};
expect(ref.uuid).toEqual('__uuid__');
// @ts-expect-error; saltwaterSecurityNumber does not exist
expect(ref.saltwaterSecurityNumber).toEqual(undefined);
});
it('should raise a type error if the unique key was not declared correctly', () => {
const ref = {
// @ts-expect-error - seawater != saltwater
seawaterSecurityNumber: '821',
};
});
it('should raise a type error if the primary key was not declared correctly', () => {
const ref = {
// @ts-expect-error - guid != uuid
guid: '821',
};
});
it('should raise a type error if unique key wasnt fully defined', () => {
// @ts-expect-error; Property 'wormSegmentNumber' is missing in type
const ref = {
soilSecurityNumber: '29131',
};
});
it('should raise a type error neither key was defined', () => {
// @ts-expect-error - must not be empty
const ref = {};
});
test_fns_1.then.todo('should raise an error if both are declared (since users could define them out of sync)', () => {
const ref = {
uuid: '821',
saltwaterSecurityNumber: '821',
};
});
});
(0, test_fns_1.given)('a domain event', () => {
class SeaTurtleReport extends DomainEntity_1.DomainEntity {
}
SeaTurtleReport.primary = ['uuid'];
SeaTurtleReport.unique = ['forRegion', 'onDate'];
it('should be able to define a unique key reference', () => {
const ref = {
forRegion: 'Great Barrier Reef',
onDate: 'yesterday',
};
expect(ref.forRegion).toEqual('Great Barrier Reef');
expect(ref.onDate).toEqual('yesterday');
// @ts-expect-error; uuid does not exist on unique
expect(ref.uuid).toEqual(undefined);
});
it('should be able to define a primary key ref', () => {
const ref = {
uuid: '__uuid__',
};
expect(ref.uuid).toEqual('__uuid__');
// @ts-expect-error; forRegion does not exist on primary
expect(ref.forRegion).toEqual(undefined);
});
it('should raise a type error if the unique key was not declared correctly', () => {
const ref = {
// @ts-expect-error - region != forRegion
region: 'Great Barrier Reef',
onDate: 'yesterday',
};
});
it('should raise a type error if the primary key was not declared correctly', () => {
const ref = {
// @ts-expect-error - guid != uuid
guid: '821',
};
});
test_fns_1.then.todo('should raise an error if both are declared (since users could define them out of sync)', () => {
const ref = {
uuid: '821',
forRegion: 'Great Barrier Reef',
onDate: 'yesterday',
};
});
});
});
//# sourceMappingURL=DomainReference.test.js.map
;