@@ -3,6 +3,22 @@ import { $TSContext, stateManager } from '@aws-amplify/amplify-cli-core';
33import { CloudFormationClient , DescribeChangeSetOutput } from '@aws-sdk/client-cloudformation' ;
44
55jest . mock ( '@aws-sdk/client-cloudformation' ) ;
6+ jest . mock ( 'bottleneck' , ( ) => {
7+ return jest . fn ( ) . mockImplementation ( ( ) => ( {
8+ schedule : jest . fn ( ( fn ) => fn ( ) ) ,
9+ } ) ) ;
10+ } ) ;
11+ jest . mock ( '@aws-amplify/amplify-prompts' , ( ) => ( {
12+ printer : {
13+ error : jest . fn ( ) ,
14+ info : jest . fn ( ) ,
15+ warn : jest . fn ( ) ,
16+ } ,
17+ AmplifySpinner : jest . fn ( ) . mockImplementation ( ( ) => ( {
18+ start : jest . fn ( ) ,
19+ stop : jest . fn ( ) ,
20+ } ) ) ,
21+ } ) ) ;
622jest . mock ( '@aws-amplify/amplify-cli-core' , ( ) => ( {
723 ...jest . requireActual ( '@aws-amplify/amplify-cli-core' ) ,
824 stateManager : {
@@ -20,6 +36,19 @@ describe('AmplifyGen2MigrationValidations', () => {
2036 } ) ;
2137
2238 describe ( 'validateStatefulResources' , ( ) => {
39+ let mockSend : jest . Mock ;
40+
41+ beforeEach ( ( ) => {
42+ mockSend = jest . fn ( ) ;
43+ ( CloudFormationClient as jest . Mock ) . mockImplementation ( ( ) => ( {
44+ send : mockSend ,
45+ } ) ) ;
46+ } ) ;
47+
48+ afterEach ( ( ) => {
49+ jest . clearAllMocks ( ) ;
50+ } ) ;
51+
2352 it ( 'should pass when no changes exist' , async ( ) => {
2453 const changeSet : DescribeChangeSetOutput = { } ;
2554 await expect ( validations . validateStatefulResources ( changeSet ) ) . resolves . not . toThrow ( ) ;
@@ -56,8 +85,8 @@ describe('AmplifyGen2MigrationValidations', () => {
5685 } ;
5786 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
5887 name : 'DestructiveMigrationError' ,
59- message : 'Stateful resources scheduled for deletion: MyTable (AWS::DynamoDB::Table) .' ,
60- resolution : 'Review the migration plan and ensure data is backed up before proceeding.' ,
88+ message : 'Decommission will delete stateful resources .' ,
89+ resolution : 'Review the resources above and ensure data is backed up before proceeding.' ,
6190 } ) ;
6291 } ) ;
6392
@@ -84,8 +113,8 @@ describe('AmplifyGen2MigrationValidations', () => {
84113 } ;
85114 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
86115 name : 'DestructiveMigrationError' ,
87- message : 'Stateful resources scheduled for deletion: Bucket1 (AWS::S3::Bucket), UserPool1 (AWS::Cognito::UserPool) .' ,
88- resolution : 'Review the migration plan and ensure data is backed up before proceeding.' ,
116+ message : 'Decommission will delete stateful resources .' ,
117+ resolution : 'Review the resources above and ensure data is backed up before proceeding.' ,
89118 } ) ;
90119 } ) ;
91120
@@ -176,8 +205,8 @@ describe('AmplifyGen2MigrationValidations', () => {
176205 } ;
177206 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
178207 name : 'DestructiveMigrationError' ,
179- message : 'Stateful resources scheduled for deletion: MyEBSVolume (AWS::EC2::Volume) .' ,
180- resolution : 'Review the migration plan and ensure data is backed up before proceeding.' ,
208+ message : 'Decommission will delete stateful resources .' ,
209+ resolution : 'Review the resources above and ensure data is backed up before proceeding.' ,
181210 } ) ;
182211 } ) ;
183212
@@ -212,9 +241,8 @@ describe('AmplifyGen2MigrationValidations', () => {
212241 } ;
213242 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
214243 name : 'DestructiveMigrationError' ,
215- message :
216- 'Stateful resources scheduled for deletion: Database (AWS::RDS::DBInstance), UsersTable (AWS::DynamoDB::Table), EventStream (AWS::Kinesis::Stream).' ,
217- resolution : 'Review the migration plan and ensure data is backed up before proceeding.' ,
244+ message : 'Decommission will delete stateful resources.' ,
245+ resolution : 'Review the resources above and ensure data is backed up before proceeding.' ,
218246 } ) ;
219247 } ) ;
220248
@@ -321,34 +349,20 @@ describe('AmplifyGen2MigrationValidations', () => {
321349 } ;
322350 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
323351 name : 'DestructiveMigrationError' ,
324- message : 'Stateful resources scheduled for deletion: DeletedBucket (AWS::S3::Bucket) .' ,
352+ message : 'Decommission will delete stateful resources .' ,
325353 } ) ;
326354 } ) ;
327- } ) ;
328-
329- describe ( 'validateStatefulResources - nested stacks' , ( ) => {
330- let mockSend : jest . Mock ;
331-
332- beforeEach ( ( ) => {
333- mockSend = jest . fn ( ) ;
334- ( CloudFormationClient as jest . Mock ) . mockImplementation ( ( ) => ( {
335- send : mockSend ,
336- } ) ) ;
337- } ) ;
338-
339- afterEach ( ( ) => {
340- jest . clearAllMocks ( ) ;
341- } ) ;
342355
343356 it ( 'should throw when nested stack contains stateful resources' , async ( ) => {
344357 mockSend . mockResolvedValueOnce ( {
345- StackResources : [
358+ StackResourceSummaries : [
346359 {
347360 ResourceType : 'AWS::DynamoDB::Table' ,
348361 PhysicalResourceId : 'MyTable' ,
349362 LogicalResourceId : 'Table' ,
350363 } ,
351364 ] ,
365+ NextToken : undefined ,
352366 } ) ;
353367
354368 const changeSet : DescribeChangeSetOutput = {
@@ -367,20 +381,20 @@ describe('AmplifyGen2MigrationValidations', () => {
367381
368382 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
369383 name : 'DestructiveMigrationError' ,
370- message :
371- 'Stateful resources scheduled for deletion: AuthStack (AWS::CloudFormation::Stack) containing: Table (AWS::DynamoDB::Table).' ,
384+ message : 'Decommission will delete stateful resources.' ,
372385 } ) ;
373386 } ) ;
374387
375388 it ( 'should pass when nested stack contains only stateless resources' , async ( ) => {
376389 mockSend . mockResolvedValueOnce ( {
377- StackResources : [
390+ StackResourceSummaries : [
378391 {
379392 ResourceType : 'AWS::Lambda::Function' ,
380393 PhysicalResourceId : 'MyFunction' ,
381394 LogicalResourceId : 'Function' ,
382395 } ,
383396 ] ,
397+ NextToken : undefined ,
384398 } ) ;
385399
386400 const changeSet : DescribeChangeSetOutput = {
@@ -402,23 +416,25 @@ describe('AmplifyGen2MigrationValidations', () => {
402416
403417 it ( 'should handle multiple levels of nested stacks' , async ( ) => {
404418 mockSend . mockResolvedValueOnce ( {
405- StackResources : [
419+ StackResourceSummaries : [
406420 {
407421 ResourceType : 'AWS::CloudFormation::Stack' ,
408422 PhysicalResourceId : 'storage-nested-stack' ,
409423 LogicalResourceId : 'StorageNestedStack' ,
410424 } ,
411425 ] ,
426+ NextToken : undefined ,
412427 } ) ;
413428
414429 mockSend . mockResolvedValueOnce ( {
415- StackResources : [
430+ StackResourceSummaries : [
416431 {
417432 ResourceType : 'AWS::S3::Bucket' ,
418433 PhysicalResourceId : 'my-bucket' ,
419434 LogicalResourceId : 'Bucket' ,
420435 } ,
421436 ] ,
437+ NextToken : undefined ,
422438 } ) ;
423439
424440 const changeSet : DescribeChangeSetOutput = {
@@ -460,13 +476,14 @@ describe('AmplifyGen2MigrationValidations', () => {
460476
461477 it ( 'should handle mixed direct and nested stateful resources' , async ( ) => {
462478 mockSend . mockResolvedValueOnce ( {
463- StackResources : [
479+ StackResourceSummaries : [
464480 {
465481 ResourceType : 'AWS::Cognito::UserPool' ,
466482 PhysicalResourceId : 'user-pool' ,
467483 LogicalResourceId : 'UserPool' ,
468484 } ,
469485 ] ,
486+ NextToken : undefined ,
470487 } ) ;
471488
472489 const changeSet : DescribeChangeSetOutput = {
@@ -493,7 +510,7 @@ describe('AmplifyGen2MigrationValidations', () => {
493510
494511 await expect ( validations . validateStatefulResources ( changeSet ) ) . rejects . toMatchObject ( {
495512 name : 'DestructiveMigrationError' ,
496- message : expect . stringContaining ( 'DirectTable' ) ,
513+ message : 'Decommission will delete stateful resources.' ,
497514 } ) ;
498515 } ) ;
499516 } ) ;
0 commit comments