11import { CalmNode , CalmNodeDetails } from './node.js' ;
2- import { CalmNodeSchema } from '../types/core-types.js' ;
2+ import { CalmNodeSchema , CalmNodeDetailsSchema } from '../types/core-types.js' ;
33
44const nodeData : CalmNodeSchema = {
55 'unique-id' : 'node-001' ,
@@ -32,6 +32,28 @@ describe('CalmNodeDetails', () => {
3232 expect ( nodeDetails . detailedArchitecture ) . toBe ( 'https://example.com/architecture' ) ;
3333 expect ( nodeDetails . requiredPattern ) . toBe ( 'https://example.com/pattern' ) ;
3434 } ) ;
35+
36+ it ( 'should create a CalmNodeDetails instance from JSON data with no pattern' , ( ) => {
37+ const nodeDetailsSchema : CalmNodeDetailsSchema = {
38+ 'detailed-architecture' : 'https://example.com/architecture' ,
39+ } ;
40+ const nodeDetails = CalmNodeDetails . fromJson ( nodeDetailsSchema ) ;
41+
42+ expect ( nodeDetails ) . toBeInstanceOf ( CalmNodeDetails ) ;
43+ expect ( nodeDetails . detailedArchitecture ) . toBe ( 'https://example.com/architecture' ) ;
44+ expect ( nodeDetails . requiredPattern ) . toBeUndefined ( ) ;
45+ } ) ;
46+
47+ it ( 'should create a CalmNodeDetails instance from JSON data with no architecture' , ( ) => {
48+ const nodeDetailsSchema : CalmNodeDetailsSchema = {
49+ 'required-pattern' : 'https://example.com/pattern' ,
50+ } ;
51+ const nodeDetails = CalmNodeDetails . fromJson ( nodeDetailsSchema ) ;
52+
53+ expect ( nodeDetails ) . toBeInstanceOf ( CalmNodeDetails ) ;
54+ expect ( nodeDetails . detailedArchitecture ) . toBeUndefined ( ) ;
55+ expect ( nodeDetails . requiredPattern ) . toBe ( 'https://example.com/pattern' ) ;
56+ } ) ;
3557} ) ;
3658
3759describe ( 'CalmNode' , ( ) => {
@@ -57,21 +79,34 @@ describe('CalmNode', () => {
5779 'unique-id' : 'node-002' ,
5880 'node-type' : 'service' ,
5981 name : 'Another Test Node' ,
60- description : 'Another test node description' ,
61- details : {
62- 'detailed-architecture' : 'https://example.com/architecture-2' ,
63- 'required-pattern' : 'https://example.com/pattern-2'
64- } ,
65- interfaces : [ { 'unique-id' : 'interface-002' , port : 8080 } ] ,
66- controls : { 'control-002' : { description : 'Another test control' , requirements : [ { 'requirement-url' : 'https://example.com/requirement2' , 'config-url' : 'https://example.com/config2' } ] } } ,
67- metadata : [ { key : 'value' } ]
82+ description : 'Another test node description'
6883 } ;
6984
7085 const nodeWithoutOptionalFields = CalmNode . fromJson ( nodeDataWithoutOptionalFields ) ;
7186
7287 expect ( nodeWithoutOptionalFields ) . toBeInstanceOf ( CalmNode ) ;
7388 expect ( nodeWithoutOptionalFields . uniqueId ) . toBe ( 'node-002' ) ;
74- expect ( nodeWithoutOptionalFields [ 'run-as' ] ) . toBeUndefined ( ) ;
89+ expect ( nodeWithoutOptionalFields . details . detailedArchitecture ) . toEqual ( '' ) ;
90+ expect ( nodeWithoutOptionalFields . details . requiredPattern ) . toEqual ( '' ) ;
91+ expect ( nodeWithoutOptionalFields . interfaces ) . toEqual ( [ ] ) ;
92+ expect ( nodeWithoutOptionalFields . controls ) . toEqual ( [ ] ) ;
93+ expect ( nodeWithoutOptionalFields . metadata . data ) . toEqual ( { } ) ;
94+ } ) ;
95+
96+ it ( 'should handle adduitional properties' , ( ) => {
97+ const nodeDataWithAdditionalFields : CalmNodeSchema = {
98+ 'unique-id' : 'node-002' ,
99+ 'node-type' : 'service' ,
100+ name : 'Another Test Node' ,
101+ description : 'Another test node description' ,
102+ 'another-property' : 'some value'
103+ } ;
104+
105+ const nodeWithAdditionalFields = CalmNode . fromJson ( nodeDataWithAdditionalFields ) ;
106+
107+ expect ( nodeWithAdditionalFields ) . toBeInstanceOf ( CalmNode ) ;
108+ expect ( nodeWithAdditionalFields . uniqueId ) . toBe ( 'node-002' ) ;
109+ expect ( nodeWithAdditionalFields . additionalProperties [ 'another-property' ] ) . toBe ( 'some value' ) ;
75110 } ) ;
76111
77112 it ( 'should handle empty interfaces, controls, and metadata' , ( ) => {
@@ -94,6 +129,6 @@ describe('CalmNode', () => {
94129 expect ( nodeWithEmptyFields ) . toBeInstanceOf ( CalmNode ) ;
95130 expect ( nodeWithEmptyFields . interfaces ) . toHaveLength ( 0 ) ;
96131 expect ( nodeWithEmptyFields . controls ) . toHaveLength ( 0 ) ;
97- expect ( nodeWithEmptyFields . metadata ) . toEqual ( { data : { } } ) ;
132+ expect ( nodeWithEmptyFields . metadata ) . toEqual ( { data : { } } ) ;
98133 } ) ;
99134} ) ;
0 commit comments