From 301000c985c8e6f3c2a942cdcbd08a3aac49c0c0 Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Wed, 19 Jul 2023 14:37:48 -0700 Subject: [PATCH] chore: snapshots --- .../auth-add-all.migration.test.ts.snap | 53 +++++---- .../auth-oauth-lambda-migration.test.ts.snap | 106 +++++++++--------- 2 files changed, 78 insertions(+), 81 deletions(-) diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests_v10/__snapshots__/auth-add-all.migration.test.ts.snap b/packages/amplify-migration-tests/src/__tests__/migration_tests_v10/__snapshots__/auth-add-all.migration.test.ts.snap index e6a08fcc6a..4209eefbf7 100644 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests_v10/__snapshots__/auth-add-all.migration.test.ts.snap +++ b/packages/amplify-migration-tests/src/__tests__/migration_tests_v10/__snapshots__/auth-add-all.migration.test.ts.snap @@ -204,38 +204,37 @@ async function createUserPoolDomain(domainName, userPoolId) { await identity.createUserPoolDomain(params).promise(); } +async function createOrUpdateDomain(inputDomainName, userPoolId) { + const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); + if (result.UserPool.Domain === inputDomainName) { + // if existing domain is same as input domain do nothing. + return; + } + if (inputDomainName) { + // create new or replace existing domain. + const isDomainAvailable = await checkDomainAvailability(inputDomainName); + if (isDomainAvailable) { + if (result.UserPool.Domain) { + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } + await createUserPoolDomain(inputDomainName, userPoolId); + } else { + throw new Error('Domain not available'); + } + } else if (result.UserPool.Domain) { + // if input domain is undefined delete existing domain if exists. + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } +} + async function handleEvent(event, context) { - const userPoolId = event.ResourceProperties.userPoolId; - const inputDomainName = event.ResourceProperties.hostedUIDomainName; try { + const userPoolId = event.ResourceProperties.userPoolId; + const inputDomainName = event.ResourceProperties.hostedUIDomainName; if (event.RequestType === 'Delete') { await deleteUserPoolDomain(inputDomainName, userPoolId); } else if (event.RequestType === 'Update' || event.RequestType === 'Create') { - const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); - if (inputDomainName) { - if (result.UserPool.Domain !== inputDomainName) { - if (!result.UserPool.Domain) { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } else { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } - } - } else { - if (result.UserPool.Domain) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - } - } + await createOrUpdateDomain(inputDomainName, userPoolId); } response.send(event, context, response.SUCCESS, {}); } catch (err) { diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/__snapshots__/auth-oauth-lambda-migration.test.ts.snap b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/__snapshots__/auth-oauth-lambda-migration.test.ts.snap index e8d44474b6..22e430b238 100644 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/__snapshots__/auth-oauth-lambda-migration.test.ts.snap +++ b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/__snapshots__/auth-oauth-lambda-migration.test.ts.snap @@ -191,38 +191,37 @@ async function createUserPoolDomain(domainName, userPoolId) { await identity.createUserPoolDomain(params).promise(); } +async function createOrUpdateDomain(inputDomainName, userPoolId) { + const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); + if (result.UserPool.Domain === inputDomainName) { + // if existing domain is same as input domain do nothing. + return; + } + if (inputDomainName) { + // create new or replace existing domain. + const isDomainAvailable = await checkDomainAvailability(inputDomainName); + if (isDomainAvailable) { + if (result.UserPool.Domain) { + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } + await createUserPoolDomain(inputDomainName, userPoolId); + } else { + throw new Error('Domain not available'); + } + } else if (result.UserPool.Domain) { + // if input domain is undefined delete existing domain if exists. + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } +} + async function handleEvent(event, context) { - const userPoolId = event.ResourceProperties.userPoolId; - const inputDomainName = event.ResourceProperties.hostedUIDomainName; try { + const userPoolId = event.ResourceProperties.userPoolId; + const inputDomainName = event.ResourceProperties.hostedUIDomainName; if (event.RequestType === 'Delete') { await deleteUserPoolDomain(inputDomainName, userPoolId); } else if (event.RequestType === 'Update' || event.RequestType === 'Create') { - const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); - if (inputDomainName) { - if (result.UserPool.Domain !== inputDomainName) { - if (!result.UserPool.Domain) { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } else { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } - } - } else { - if (result.UserPool.Domain) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - } - } + await createOrUpdateDomain(inputDomainName, userPoolId); } response.send(event, context, response.SUCCESS, {}); } catch (err) { @@ -429,38 +428,37 @@ async function createUserPoolDomain(domainName, userPoolId) { await identity.createUserPoolDomain(params).promise(); } +async function createOrUpdateDomain(inputDomainName, userPoolId) { + const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); + if (result.UserPool.Domain === inputDomainName) { + // if existing domain is same as input domain do nothing. + return; + } + if (inputDomainName) { + // create new or replace existing domain. + const isDomainAvailable = await checkDomainAvailability(inputDomainName); + if (isDomainAvailable) { + if (result.UserPool.Domain) { + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } + await createUserPoolDomain(inputDomainName, userPoolId); + } else { + throw new Error('Domain not available'); + } + } else if (result.UserPool.Domain) { + // if input domain is undefined delete existing domain if exists. + await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); + } +} + async function handleEvent(event, context) { - const userPoolId = event.ResourceProperties.userPoolId; - const inputDomainName = event.ResourceProperties.hostedUIDomainName; try { + const userPoolId = event.ResourceProperties.userPoolId; + const inputDomainName = event.ResourceProperties.hostedUIDomainName; if (event.RequestType === 'Delete') { await deleteUserPoolDomain(inputDomainName, userPoolId); } else if (event.RequestType === 'Update' || event.RequestType === 'Create') { - const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise(); - if (inputDomainName) { - if (result.UserPool.Domain !== inputDomainName) { - if (!result.UserPool.Domain) { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } else { - const isDomainAvailable = await checkDomainAvailability(inputDomainName); - if (isDomainAvailable) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - await createUserPoolDomain(inputDomainName, userPoolId); - } else { - throw new Error('Domain not available'); - } - } - } - } else { - if (result.UserPool.Domain) { - await deleteUserPoolDomain(result.UserPool.Domain, userPoolId); - } - } + await createOrUpdateDomain(inputDomainName, userPoolId); } response.send(event, context, response.SUCCESS, {}); } catch (err) {