@@ -13,6 +13,8 @@ import { removeProperties } from '.';
1313import { $TSAny } from '@aws-amplify/amplify-cli-core' ;
1414import assert from 'node:assert' ;
1515
16+ const DATA_SOURCE_PROPS_TO_REMOVE = [ 'dataSourceArn' , 'serviceRoleArn' , 'dynamodbConfig' ] ;
17+
1618export async function assertUserPool ( gen1Meta : $TSAny , gen1Region : string ) {
1719 const { UserPoolId : gen1UserPoolId } = Object . keys ( gen1Meta . auth ) . map ( ( key ) => gen1Meta . auth [ key ] ) [ 0 ] . output ;
1820 const cloudUserPool = await getUserPool ( gen1UserPoolId , gen1Region ) ;
@@ -129,17 +131,24 @@ export async function assertAuthWithMaxOptionsGen1Setup(projRoot: string) {
129131
130132export async function assertStorageWithMaxOptionsGen1Setup ( projRoot : string ) {
131133 const gen1Meta = getProjectMeta ( projRoot ) ;
134+ const gen1StackName = gen1Meta . providers . awscloudformation . StackName ;
132135 const gen1Region = gen1Meta . providers . awscloudformation . Region ;
133136 const { gen1BucketName } = await assertStorage ( gen1Meta , gen1Region ) ;
134137 const { gen1UserPoolId } = await assertUserPool ( gen1Meta , gen1Region ) ;
135138 const { gen1FunctionName } = await assertFunction ( gen1Meta , gen1Region ) ;
136139 assert . match ( gen1FunctionName , / S 3 T r i g g e r / ) ;
137140 const { gen1ClientIds } = await assertUserPoolClients ( gen1Meta , gen1Region ) ;
138141 const { gen1IdentityPoolId } = await assertIdentityPool ( gen1Meta , gen1Region ) ;
142+ const envName = gen1StackName . split ( '-' ) [ 2 ] ;
139143
140- return { gen1UserPoolId, gen1ClientIds, gen1BucketName, gen1IdentityPoolId, gen1Region, gen1FunctionName } ;
144+ return { gen1UserPoolId, gen1ClientIds, gen1BucketName, gen1IdentityPoolId, gen1Region, gen1FunctionName, envName } ;
141145}
142146
147+ const extractUserPoolNamePrefix = ( userPoolName : string ) => {
148+ const [ userPoolNamePrefix ] = userPoolName . split ( '-' ) ;
149+ return userPoolNamePrefix ;
150+ } ;
151+
143152async function assertUserPoolResource ( projRoot : string , gen1UserPoolId : string , gen1Region : string ) {
144153 const gen1Resource = await getResourceDetails ( 'AWS::Cognito::UserPool' , gen1UserPoolId , gen1Region ) ;
145154 removeProperties ( gen1Resource , [ 'ProviderURL' , 'ProviderName' , 'UserPoolId' , 'Arn' , 'LambdaConfig.PostConfirmation' ] ) ;
@@ -156,6 +165,8 @@ async function assertUserPoolResource(projRoot: string, gen1UserPoolId: string,
156165 const gen2UserPoolId = gen2Meta . auth . user_pool_id ;
157166 const gen2Region = gen2Meta . auth . aws_region ;
158167 const gen2Resource = await getResourceDetails ( 'AWS::Cognito::UserPool' , gen2UserPoolId , gen2Region ) ;
168+ gen1Resource . UserPoolName = extractUserPoolNamePrefix ( gen1Resource . UserPoolName ) ;
169+ gen2Resource . UserPoolName = extractUserPoolNamePrefix ( gen2Resource . UserPoolName ) ;
159170 if ( gen1Resource . LambdaConfig . PostConfirmation ) assert ( gen2Resource . LambdaConfig . PostConfirmation ) ;
160171 removeProperties ( gen2Resource , [ 'ProviderURL' , 'ProviderName' , 'UserPoolId' , 'Arn' , 'LambdaConfig.PostConfirmation' ] ) ;
161172 // TODO: remove below line after EmailMessage, EmailSubject, SmsMessage, SmsVerificationMessage, EmailVerificationMessage, EmailVerificationSubject, AccountRecoverySetting inconsistency is fixed
@@ -275,7 +286,7 @@ export async function assertFunctionResource(projRoot: string, gen2StackName: st
275286 const gen1Resource = await getResourceDetails ( 'AWS::Lambda::Function' , gen1FunctionName , gen1Region ) ;
276287 removeProperties ( gen1Resource , [ 'Arn' , 'FunctionName' , 'LoggingConfig.LogGroup' , 'Role' ] ) ;
277288 // TODO: remove below line after Tags inconsistency is fixed
278- removeProperties ( gen1Resource , [ 'Tags' ] ) ;
289+ removeProperties ( gen1Resource , [ 'Tags' , 'Environment' ] ) ;
279290
280291 const gen2Meta = getProjectOutputs ( projRoot ) ;
281292 const gen2Region = gen2Meta . auth . aws_region ;
@@ -285,15 +296,15 @@ export async function assertFunctionResource(projRoot: string, gen2StackName: st
285296 assert ( gen2Resource . FunctionName ) ;
286297 removeProperties ( gen2Resource , [ 'Arn' , 'FunctionName' , 'LoggingConfig.LogGroup' , 'Role' ] ) ;
287298 // TODO: remove below line after Environment.Variables.AMPLIFY_SSM_ENV_CONFIG, Tags inconsistency is fixed
288- removeProperties ( gen2Resource , [ 'Environment.Variables.AMPLIFY_SSM_ENV_CONFIG' , 'Tags' ] ) ;
299+ removeProperties ( gen2Resource , [ 'Environment.Variables.AMPLIFY_SSM_ENV_CONFIG' , 'Tags' , 'Environment' ] ) ;
289300
290301 expect ( gen2Resource ) . toEqual ( gen1Resource ) ;
291302}
292303
293304export async function assertDataResource ( projRoot : string , gen2StackName : string , gen1GraphqlApiId : string , gen1Region : string ) {
294305 const gen1Resource = await getAppSyncApi ( gen1GraphqlApiId , gen1Region ) ;
295306 const gen1DataSource = ( await getAppSyncDataSource ( gen1GraphqlApiId , 'TodoTable' , gen1Region ) ) as Record < string , unknown > ;
296- removeProperties ( gen1DataSource , [ 'dataSourceArn' , 'serviceRoleArn' ] ) ;
307+ removeProperties ( gen1DataSource , DATA_SOURCE_PROPS_TO_REMOVE ) ;
297308 removeProperties ( gen1Resource . graphqlApi as Record < string , unknown > , [ 'name' , 'apiId' , 'arn' , 'uris' , 'tags' , 'dns' ] ) ;
298309 // TODO: remove below line after authenticationType inconsistency is fixed
299310 removeProperties ( gen1Resource . graphqlApi as Record < string , unknown > , [ 'authenticationType' ] ) ;
@@ -304,7 +315,7 @@ export async function assertDataResource(projRoot: string, gen2StackName: string
304315 const gen2GraphqlApiId = outputs ?. find ( ( output ) => output . OutputKey === 'awsAppsyncApiId' ) ?. OutputValue ?? '' ;
305316 const gen2Resource = await getAppSyncApi ( gen2GraphqlApiId , gen2Region ) ;
306317 const gen2DataSource = ( await getAppSyncDataSource ( gen2GraphqlApiId , 'TodoTable' , gen1Region ) ) as Record < string , unknown > ;
307- removeProperties ( gen2DataSource , [ 'dataSourceArn' , 'serviceRoleArn' ] ) ;
318+ removeProperties ( gen2DataSource , DATA_SOURCE_PROPS_TO_REMOVE ) ;
308319 removeProperties ( gen2Resource . graphqlApi as Record < string , unknown > , [
309320 'name' ,
310321 'apiId' ,
0 commit comments