@@ -4,11 +4,19 @@ import { AmplifyStack } from './amplify_stack.js';
44import { Template } from 'aws-cdk-lib/assertions' ;
55import assert from 'node:assert' ;
66import { FederatedPrincipal , Role } from 'aws-cdk-lib/aws-iam' ;
7+ import { BackendIdentifier } from '@aws-amplify/plugin-types' ;
8+ import { Bucket } from 'aws-cdk-lib/aws-s3' ;
9+
10+ const branchBackendId : BackendIdentifier = {
11+ namespace : 'testId' ,
12+ name : 'testBranch' ,
13+ type : 'branch' ,
14+ } ;
715
816void describe ( 'AmplifyStack' , ( ) => {
917 void it ( 'renames nested stack logical IDs to non-redundant value' , ( ) => {
1018 const app = new App ( ) ;
11- const rootStack = new AmplifyStack ( app , 'test-id' ) ;
19+ const rootStack = new AmplifyStack ( app , branchBackendId ) ;
1220 new NestedStack ( rootStack , 'testName' ) ;
1321
1422 const rootStackTemplate = Template . fromStack ( rootStack ) ;
@@ -23,7 +31,7 @@ void describe('AmplifyStack', () => {
2331
2432 void it ( 'allows roles with properly configured cognito trust policies' , ( ) => {
2533 const app = new App ( ) ;
26- const rootStack = new AmplifyStack ( app , 'test-id' ) ;
34+ const rootStack = new AmplifyStack ( app , branchBackendId ) ;
2735 new Role ( rootStack , 'correctRole' , {
2836 assumedBy : new FederatedPrincipal (
2937 'cognito-identity.amazonaws.com' ,
@@ -43,7 +51,7 @@ void describe('AmplifyStack', () => {
4351
4452 void it ( 'throws on roles with cognito trust policy missing amr condition' , ( ) => {
4553 const app = new App ( ) ;
46- const rootStack = new AmplifyStack ( app , 'test-id' ) ;
54+ const rootStack = new AmplifyStack ( app , branchBackendId ) ;
4755 new Role ( rootStack , 'missingAmrCondition' , {
4856 assumedBy : new FederatedPrincipal (
4957 'cognito-identity.amazonaws.com' ,
@@ -64,7 +72,7 @@ void describe('AmplifyStack', () => {
6472
6573 void it ( 'throws on roles with cognito trust policy missing aud condition' , ( ) => {
6674 const app = new App ( ) ;
67- const rootStack = new AmplifyStack ( app , 'test-id' ) ;
75+ const rootStack = new AmplifyStack ( app , branchBackendId ) ;
6876 new Role ( rootStack , 'missingAudCondition' , {
6977 assumedBy : new FederatedPrincipal (
7078 'cognito-identity.amazonaws.com' ,
@@ -82,4 +90,32 @@ void describe('AmplifyStack', () => {
8290 'Cannot create a Role trust policy with Cognito that does not have a StringEquals condition for cognito-identity.amazonaws.com:aud' ,
8391 } ) ;
8492 } ) ;
93+
94+ void it ( 'keeps default removal policy of retain for resources in branch deployments' , ( ) => {
95+ const app = new App ( ) ;
96+ const rootStack = new AmplifyStack ( app , branchBackendId ) ;
97+ // bucket has default removal policy to retain
98+ new Bucket ( rootStack , 'testBucket' , { enforceSSL : true } ) ;
99+ const template = Template . fromStack ( rootStack ) ;
100+
101+ template . hasResource ( 'AWS::S3::Bucket' , {
102+ DeletionPolicy : 'Retain' ,
103+ } ) ;
104+ } ) ;
105+
106+ void it ( 'sets removal policy to destroy for resources in sandbox deployments' , ( ) => {
107+ const app = new App ( ) ;
108+ const rootStack = new AmplifyStack ( app , {
109+ namespace : 'testId' ,
110+ name : 'testSandbox' ,
111+ type : 'sandbox' ,
112+ } ) ;
113+ // bucket has default removal policy to retain
114+ new Bucket ( rootStack , 'testBucket' , { enforceSSL : true } ) ;
115+ const template = Template . fromStack ( rootStack ) ;
116+
117+ template . hasResource ( 'AWS::S3::Bucket' , {
118+ DeletionPolicy : 'Delete' ,
119+ } ) ;
120+ } ) ;
85121} ) ;
0 commit comments