11import { ChangeSet } from './change-set.js' ;
22import { ParameterOperation , ResourceOperation } from 'codify-schemas' ;
33import { describe , expect , it } from 'vitest' ;
4+ import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js' ;
45
56describe ( 'Change set tests' , ( ) => {
67 it ( 'Correctly diffs two resource configs (modify)' , ( ) => {
@@ -31,7 +32,7 @@ describe('Change set tests', () => {
3132 propA : 'after' ,
3233 }
3334
34- const cs = ChangeSet . calculateModification ( after , before , ) ;
35+ const cs = ChangeSet . calculateModification ( after , before ) ;
3536 expect ( cs . parameterChanges . length ) . to . eq ( 2 ) ;
3637 expect ( cs . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
3738 expect ( cs . parameterChanges [ 1 ] . operation ) . to . eq ( ParameterOperation . ADD ) ;
@@ -104,7 +105,14 @@ describe('Change set tests', () => {
104105 propA : [ 'b' , 'a' , 'c' ] ,
105106 }
106107
107- const cs = ChangeSet . calculateModification ( after , before , { propA : { type : 'array' } } ) ;
108+ const parameterSettings = new ParsedResourceSettings ( {
109+ id : 'type' ,
110+ parameterSettings : {
111+ propA : { type : 'array' }
112+ }
113+ } ) . parameterSettings
114+
115+ const cs = ChangeSet . calculateModification ( after , before , parameterSettings ) ;
108116 expect ( cs . parameterChanges . length ) . to . eq ( 1 ) ;
109117 expect ( cs . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . NOOP ) ;
110118 expect ( cs . operation ) . to . eq ( ResourceOperation . NOOP )
@@ -119,7 +127,14 @@ describe('Change set tests', () => {
119127 propA : [ 'b' , 'a' ] ,
120128 }
121129
122- const cs = ChangeSet . calculateModification ( after , before , { propA : { type : 'array' } } ) ;
130+ const parameterSettings = new ParsedResourceSettings ( {
131+ id : 'type' ,
132+ parameterSettings : {
133+ propA : { type : 'array' }
134+ }
135+ } ) . parameterSettings
136+
137+ const cs = ChangeSet . calculateModification ( after , before , parameterSettings ) ;
123138 expect ( cs . parameterChanges . length ) . to . eq ( 1 ) ;
124139 expect ( cs . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
125140 expect ( cs . operation ) . to . eq ( ResourceOperation . RECREATE )
@@ -135,7 +150,14 @@ describe('Change set tests', () => {
135150 propB : 'before'
136151 }
137152
138- const cs = ChangeSet . calculateModification ( after , before , { propA : { canModify : true } } ) ;
153+ const parameterSettings = new ParsedResourceSettings ( {
154+ id : 'type' ,
155+ parameterSettings : {
156+ propA : { canModify : true }
157+ }
158+ } ) . parameterSettings
159+
160+ const cs = ChangeSet . calculateModification ( after , before , parameterSettings ) ;
139161 expect ( cs . parameterChanges . length ) . to . eq ( 2 ) ;
140162 expect ( cs . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
141163 expect ( cs . parameterChanges [ 1 ] . operation ) . to . eq ( ParameterOperation . REMOVE ) ;
@@ -152,10 +174,15 @@ describe('Change set tests', () => {
152174 propB : 'before'
153175 }
154176
155- const cs = ChangeSet . calculateModification < any > ( after , before , {
156- propA : { canModify : true } ,
157- propB : { canModify : true }
158- } ) ;
177+ const parameterSettings = new ParsedResourceSettings ( {
178+ id : 'type' ,
179+ parameterSettings : {
180+ propA : { canModify : true } ,
181+ propB : { canModify : true }
182+ } ,
183+ } ) . parameterSettings
184+
185+ const cs = ChangeSet . calculateModification < any > ( after , before , parameterSettings ) ;
159186 expect ( cs . parameterChanges . length ) . to . eq ( 2 ) ;
160187 expect ( cs . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
161188 expect ( cs . parameterChanges [ 1 ] . operation ) . to . eq ( ParameterOperation . REMOVE ) ;
@@ -167,7 +194,15 @@ describe('Change set tests', () => {
167194 const arrA = [ 'a' , 'b' , 'd' ] ;
168195 const arrB = [ 'a' , 'b' , 'd' ] ;
169196
170- const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , { propA : { type : 'array' } } )
197+ const parameterSettings = new ParsedResourceSettings ( {
198+ id : 'type' ,
199+ parameterSettings : {
200+ propA : { type : 'array' }
201+ } ,
202+ } ) . parameterSettings
203+
204+
205+ const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , parameterSettings )
171206
172207 expect ( result . operation ) . to . eq ( ResourceOperation . NOOP ) ;
173208 } )
@@ -176,7 +211,14 @@ describe('Change set tests', () => {
176211 const arrA = [ 'a' , 'b' ] ;
177212 const arrB = [ 'a' , 'b' , 'd' ] ;
178213
179- const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , { propA : { type : 'array' } } )
214+ const parameterSettings = new ParsedResourceSettings ( {
215+ id : 'type' ,
216+ parameterSettings : {
217+ propA : { type : 'array' }
218+ } ,
219+ } ) . parameterSettings
220+
221+ const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , parameterSettings )
180222
181223 expect ( result . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
182224 } )
@@ -185,7 +227,14 @@ describe('Change set tests', () => {
185227 const arrA = [ 'b' , 'a' , 'd' ] ;
186228 const arrB = [ 'a' , 'b' , 'd' ] ;
187229
188- const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , { propA : { type : 'array' } } )
230+ const parameterSettings = new ParsedResourceSettings ( {
231+ id : 'type' ,
232+ parameterSettings : {
233+ propA : { type : 'array' }
234+ } ,
235+ } ) . parameterSettings
236+
237+ const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , parameterSettings )
189238
190239 expect ( result . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . NOOP ) ;
191240 } )
@@ -194,12 +243,18 @@ describe('Change set tests', () => {
194243 const arrA = [ { key1 : 'a' } , { key1 : 'a' } , { key1 : 'a' } ] ;
195244 const arrB = [ { key1 : 'a' } , { key1 : 'a' } , { key1 : 'b' } ] ;
196245
197- const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , {
198- propA : {
199- type : 'array' ,
200- isElementEqual : ( a , b ) => a . key1 === b . key1
201- }
202- } )
246+ const parameterSettings = new ParsedResourceSettings ( {
247+ id : 'type' ,
248+ parameterSettings : {
249+ propA : {
250+ type : 'array' ,
251+ isElementEqual : ( a , b ) => a . key1 === b . key1
252+ }
253+ } ,
254+ } ) . parameterSettings
255+
256+
257+ const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , parameterSettings )
203258
204259 expect ( result . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . MODIFY ) ;
205260 } )
@@ -208,12 +263,17 @@ describe('Change set tests', () => {
208263 const arrA = [ { key1 : 'b' } , { key1 : 'a' } , { key1 : 'a' } ] ;
209264 const arrB = [ { key1 : 'a' } , { key1 : 'a' } , { key1 : 'b' } ] ;
210265
211- const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , {
212- propA : {
213- type : 'array' ,
214- isElementEqual : ( a , b ) => a . key1 === b . key1
215- }
216- } )
266+ const parameterSettings = new ParsedResourceSettings ( {
267+ id : 'type' ,
268+ parameterSettings : {
269+ propA : {
270+ type : 'array' ,
271+ isElementEqual : ( a , b ) => a . key1 === b . key1
272+ }
273+ } ,
274+ } ) . parameterSettings
275+
276+ const result = ChangeSet . calculateModification ( { propA : arrA } , { propA : arrB } , parameterSettings )
217277
218278 expect ( result . parameterChanges [ 0 ] . operation ) . to . eq ( ParameterOperation . NOOP ) ;
219279 } )
0 commit comments