@@ -44,7 +44,7 @@ class TestResource extends Resource<TestConfig> {
4444
4545describe ( 'Plugin tests' , ( ) => {
4646 it ( 'Validates that applies were successfully applied' , async ( ) => {
47- const resource = new class extends TestResource {
47+ const resource = new class extends TestResource {
4848 async applyCreate ( plan : Plan < TestConfig > ) : Promise < void > {
4949 }
5050
@@ -56,9 +56,9 @@ describe('Plugin tests', () => {
5656 }
5757 }
5858
59- const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
59+ const plugin = Plugin . create ( 'testPlugin' , [ resource ] )
6060
61- const desiredPlan = {
61+ const plan = {
6262 operation : ResourceOperation . CREATE ,
6363 resourceType : 'testResource' ,
6464 parameters : [
@@ -67,7 +67,7 @@ describe('Plugin tests', () => {
6767 } ;
6868
6969 // If this doesn't throw then it passes the test
70- await testPlugin . apply ( { plan : desiredPlan } ) ;
70+ await plugin . apply ( { plan } ) ;
7171 } ) ;
7272
7373 it ( 'Validates that applies were successfully applied (error)' , async ( ) => {
@@ -80,17 +80,114 @@ describe('Plugin tests', () => {
8080 return null ;
8181 }
8282 }
83+ const plugin = Plugin . create ( 'testPlugin' , [ resource ] )
8384
84- const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
85-
86- const desiredPlan = {
85+ const plan = {
8786 operation : ResourceOperation . CREATE ,
8887 resourceType : 'testResource' ,
8988 parameters : [
9089 { name : 'propA' , operation : ParameterOperation . ADD , newValue : 'abc' , previousValue : null } ,
9190 ]
9291 } ;
9392
94- await expect ( async ( ) => testPlugin . apply ( { plan : desiredPlan } ) ) . rejects . toThrowError ( expect . any ( ApplyValidationError ) ) ;
93+ await expect ( async ( ) => plugin . apply ( { plan } ) ) . rejects . toThrowError ( expect . any ( ApplyValidationError ) ) ;
94+ } ) ;
95+
96+ it ( 'Validates that deletes were successfully applied' , async ( ) => {
97+ const resource = new class extends TestResource {
98+ async applyCreate ( plan : Plan < TestConfig > ) : Promise < void > {
99+ }
100+
101+ // Return null to indicate that the resource was deleted
102+ async refresh ( keys : Map < string , unknown > ) : Promise < Partial < TestConfig > | null > {
103+ return null ;
104+ }
105+ }
106+
107+ const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
108+
109+ const plan = {
110+ operation : ResourceOperation . DESTROY ,
111+ resourceType : 'testResource' ,
112+ parameters : [
113+ { name : 'propA' , operation : ParameterOperation . REMOVE , newValue : null , previousValue : 'abc' } ,
114+ ]
115+ } ;
116+
117+ // If this doesn't throw then it passes the test
118+ await testPlugin . apply ( { plan } )
119+ } ) ;
120+
121+ it ( 'Validates that deletes were successfully applied (error)' , async ( ) => {
122+ const resource = new class extends TestResource {
123+ async applyCreate ( plan : Plan < TestConfig > ) : Promise < void > {
124+ }
125+
126+ // Return a value to indicate that the resource still exists
127+ async refresh ( keys : Map < string , unknown > ) : Promise < Partial < TestConfig > | null > {
128+ return { propA : 'abc' } ;
129+ }
130+ }
131+
132+ const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
133+
134+ const plan = {
135+ operation : ResourceOperation . DESTROY ,
136+ resourceType : 'testResource' ,
137+ parameters : [
138+ { name : 'propA' , operation : ParameterOperation . REMOVE , newValue : null , previousValue : 'abc' } ,
139+ ]
140+ } ;
141+
142+ // If this doesn't throw then it passes the test
143+ expect ( async ( ) => await testPlugin . apply ( { plan } ) ) . rejects . toThrowError ( expect . any ( ApplyValidationError ) ) ;
144+ } ) ;
145+
146+ it ( 'Validates that re-create was successfully applied' , async ( ) => {
147+ const resource = new class extends TestResource {
148+ async applyCreate ( plan : Plan < TestConfig > ) : Promise < void > {
149+ }
150+
151+ async refresh ( keys : Map < string , unknown > ) : Promise < Partial < TestConfig > | null > {
152+ return { propA : 'def' } ;
153+ }
154+ }
155+
156+ const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
157+
158+ const plan = {
159+ operation : ResourceOperation . RECREATE ,
160+ resourceType : 'testResource' ,
161+ parameters : [
162+ { name : 'propA' , operation : ParameterOperation . MODIFY , newValue : 'def' , previousValue : 'abc' } ,
163+ ]
164+ } ;
165+
166+ // If this doesn't throw then it passes the test
167+ await testPlugin . apply ( { plan } )
168+ } ) ;
169+
170+ it ( 'Validates that modify was successfully applied (error)' , async ( ) => {
171+ const resource = new class extends TestResource {
172+ async applyCreate ( plan : Plan < TestConfig > ) : Promise < void > {
173+ }
174+
175+ async refresh ( keys : Map < string , unknown > ) : Promise < Partial < TestConfig > | null > {
176+ return { propA : 'abc' } ;
177+ }
178+ }
179+
180+ const testPlugin = Plugin . create ( 'testPlugin' , [ resource ] )
181+
182+ const plan = {
183+ operation : ResourceOperation . DESTROY ,
184+ resourceType : 'testResource' ,
185+ parameters : [
186+ { name : 'propA' , operation : ParameterOperation . REMOVE , newValue : 'def' , previousValue : 'abc' } ,
187+ ]
188+ } ;
189+
190+ // If this doesn't throw then it passes the test
191+ expect ( async ( ) => await testPlugin . apply ( { plan } ) ) . rejects . toThrowError ( expect . any ( ApplyValidationError ) ) ;
95192 } ) ;
96193} ) ;
0 commit comments