Skip to content

Commit

Permalink
fix(tests): add more test coverage on domain object refs
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Dec 1, 2024
1 parent 057b132 commit fb3e3e7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,93 @@ exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from f
]
`;

exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from files which reference a Reference<> type from domain-objects 1`] = `
[
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": [
"uuid",
],
"unique": [
"seawaterSecurityNumber",
],
"updatable": [
"name",
],
},
"extends": "DomainEntity",
"name": "SeaTurtle",
"properties": {
"name": DomainObjectPropertyMetadata {
"name": "name",
"nullable": false,
"required": true,
"type": "STRING",
},
"seawaterSecurityNumber": DomainObjectPropertyMetadata {
"name": "seawaterSecurityNumber",
"nullable": false,
"required": true,
"type": "STRING",
},
"uuid": DomainObjectPropertyMetadata {
"name": "uuid",
"nullable": false,
"required": false,
"type": "STRING",
},
},
},
DomainObjectMetadata {
"decorations": {
"alias": null,
"primary": [
"uuid",
],
"unique": [
"turtle",
],
"updatable": [
"name",
],
},
"extends": "DomainEntity",
"name": "SeaGuide",
"properties": {
"rank": DomainObjectPropertyMetadata {
"name": "rank",
"nullable": false,
"of": [
"SAND_SCOUT",
"KELP_KEEPER",
"WAVE_WHISPERER",
"OCEAN_ORACLE",
],
"required": true,
"type": "ENUM",
},
"turtle": DomainObjectPropertyMetadata {
"name": "turtle",
"nullable": false,
"of": DomainObjectReferenceMetadata {
"extends": "DomainEntity",
"name": "SeaTurtle",
},
"required": true,
"type": "REFERENCE",
},
"uuid": DomainObjectPropertyMetadata {
"name": "uuid",
"nullable": false,
"required": false,
"type": "STRING",
},
},
},
]
`;

exports[`getHydratedDomainObjectMetadatasFromFiles should return metadata from files which reference a generic type modifier from a package plugin, Literalize 1`] = `
[
DomainObjectMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from 'typescript';

import { DomainObjectPropertyType } from '../../domain';
import { DomainObjectPropertyType, DomainObjectVariant } from '../../domain';
import { extractRelevantProgramSourceFiles } from '../extractRelevantProgramSourceFiles';
import { getHydratedDomainObjectMetadatasFromFiles } from './getHydratedDomainObjectMetadatasFromFiles';

Expand Down Expand Up @@ -164,4 +164,22 @@ describe('getHydratedDomainObjectMetadatasFromFiles', () => {
);
expect(metadatas).toMatchSnapshot();
});
it('should return metadata from files which reference a Reference<> type from domain-objects', () => {
const program = ts.createProgram(
[`${__dirname}/../__test_assets__/SeaGuide.ts`],
{},
);
const files = extractRelevantProgramSourceFiles(program.getSourceFiles());
const metadatas = getHydratedDomainObjectMetadatasFromFiles(files);
console.log(JSON.stringify(metadatas, null, 2));

expect(metadatas[1]?.properties.turtle?.type).toEqual(
DomainObjectPropertyType.REFERENCE,
);
expect(metadatas[1]?.properties.turtle?.of).toEqual({
name: 'SeaTurtle',
extends: DomainObjectVariant.DOMAIN_ENTITY,
});
expect(metadatas).toMatchSnapshot();
});
});

0 comments on commit fb3e3e7

Please sign in to comment.