From d299f6680fb05473684686b7d2034646d490df24 Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 11 Jul 2023 13:00:25 -0700 Subject: [PATCH] chore: tests --- .../auth-lambda-callout-migration.test.ts | 51 ++++++------ .../auth-resource-deletion-migration.test.ts | 79 ------------------- 2 files changed, 22 insertions(+), 108 deletions(-) delete mode 100644 packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-resource-deletion-migration.test.ts diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-lambda-callout-migration.test.ts b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-lambda-callout-migration.test.ts index 510c4126f2..9334737a5e 100644 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-lambda-callout-migration.test.ts +++ b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-lambda-callout-migration.test.ts @@ -14,9 +14,9 @@ import { setupUser, signInUser, signOutUser, - updateHeadlessAuth, + getUserPool, + listSocialIdpProviders, } from '@aws-amplify/amplify-e2e-core'; -import { UpdateAuthRequest } from 'amplify-headless-interface'; import { validateVersionsForMigrationTest } from '../../migration-helpers'; import { expectLambdasInCfnTemplate, migratedLambdas, nonMigratedLambdas } from '../../migration-helpers-v12/auth-helpers/utilities'; import { initJSProjectWithProfileV12 } from '../../migration-helpers-v12/init'; @@ -58,7 +58,7 @@ describe('lambda callouts', () => { await amplifyPushForce(projRoot, true); const postMigrationTemplate = await getCloudFormationTemplate(projRoot, 'auth', resourceName); - expectLambdasInCfnTemplate(preMigrationTemplate, nonMigratedLambdas, migratedLambdas); + expectLambdasInCfnTemplate(postMigrationTemplate, nonMigratedLambdas, migratedLambdas); // revert to previous CLI version await amplifyPushForce(projRoot, false); @@ -109,38 +109,31 @@ describe('lambda callouts', () => { await signOutUser(); }); - it('should be migrated when set up using headless commands', async () => { + it('should keep identity providers and domain during migration', async () => { await initJSProjectWithProfileV12(projRoot, defaultsSettings); + const resourceName = `test${generateRandomShortId()}`; await addAuthWithMaxOptions(projRoot, { name: resourceName }); + await amplifyPushAuth(projRoot, false); - const updateAuthRequest: UpdateAuthRequest = { - version: 2, - serviceModification: { - serviceName: 'Cognito', - userPoolModification: { - userPoolGroups: [ - { - groupName: 'group1', - }, - { - groupName: 'group2', - }, - ], - }, - includeIdentityPool: true, - identityPoolModification: { - identitySocialFederation: [{ provider: 'GOOGLE', clientId: 'fakeClientId' }], - }, - }, - }; - - await updateHeadlessAuth(projRoot, updateAuthRequest, { testingWithLatestCodebase: true }); - await amplifyPushAuth(projRoot, true); + const meta = getProjectMeta(projRoot); + const region = meta.providers.awscloudformation.Region; + const { HostedUIDomain, UserPoolId } = Object.keys(meta.auth) + .map((key) => meta.auth[key]) + .find((auth) => auth.service === 'Cognito').output; + const userPoolRes1 = await getUserPool(UserPoolId, region); + const userPoolDomainV12 = userPoolRes1.UserPool.Domain; + const socialIdpProvidersV12 = await listSocialIdpProviders(UserPoolId, region); + await amplifyPushForce(projRoot, true); - const template = await getCloudFormationTemplate(projRoot, 'auth', resourceName); - expectLambdasInCfnTemplate(template, nonMigratedLambdas, migratedLambdas); + const userPoolRes2 = await getUserPool(UserPoolId, region); + const userPoolDomainLatest = userPoolRes2.UserPool.Domain; + const socialIdpProvidersLatest = await listSocialIdpProviders(UserPoolId, region); + // check same domain should exist + expect(userPoolDomainV12).toEqual(userPoolDomainLatest); + // check the Social Idp Provider exists + expect(socialIdpProvidersV12).toEqual(socialIdpProvidersLatest); }); }); diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-resource-deletion-migration.test.ts b/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-resource-deletion-migration.test.ts deleted file mode 100644 index c735680500..0000000000 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests_v12/auth-resource-deletion-migration.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { - addAuthWithMaxOptions, - amplifyPull, - amplifyPushAuth, - amplifyPushForce, - createNewProjectDir, - deleteProject, - deleteProjectDir, - deleteSocialIdpProviders, - deleteUserPoolDomain, - getAppId, - getProjectMeta, - getUserPool, - listSocialIdpProviders, -} from '@aws-amplify/amplify-e2e-core'; -import { allowedVersionsToMigrateFrom, versionCheck } from '../../migration-helpers'; -import { initJSProjectWithProfileV12 } from '../../migration-helpers-v12/init'; - -describe('amplify migration test auth', () => { - let projRoot1: string; - - beforeAll(async () => { - const migrateFromVersion = { v: 'uninitialized' }; - const migrateToVersion = { v: 'uninitialized' }; - await versionCheck(process.cwd(), false, migrateFromVersion); - await versionCheck(process.cwd(), true, migrateToVersion); - console.log(`Test migration from: ${migrateFromVersion.v} to ${migrateToVersion.v}`); - expect(migrateFromVersion.v).not.toEqual(migrateToVersion.v); - expect(allowedVersionsToMigrateFrom).toContain(migrateFromVersion.v); - }); - - beforeEach(async () => { - projRoot1 = await createNewProjectDir('authMigration1'); - }); - - afterEach(async () => { - await deleteProject(projRoot1, null, true); - deleteProjectDir(projRoot1); - }); - - it('should pass if the resources created by the Lambda callouts are deleted and trying to recreate resources with CFN code', async () => { - await initJSProjectWithProfileV12(projRoot1, { name: 'authTest', disableAmplifyAppCreation: false }); - - await addAuthWithMaxOptions(projRoot1, {}); - await amplifyPushAuth(projRoot1); - - const appId = getAppId(projRoot1); - expect(appId).toBeDefined(); - const projRoot2 = await createNewProjectDir('authMigration2'); - - try { - await amplifyPull(projRoot2, { emptyDir: true, appId }, true); - const meta = getProjectMeta(projRoot1); - const region = meta.providers.awscloudformation.Region; - const { HostedUIDomain, UserPoolId } = Object.keys(meta.auth) - .map((key) => meta.auth[key]) - .find((auth) => auth.service === 'Cognito').output; - const userPoolRes1 = await getUserPool(UserPoolId, region); - const userPoolDomainV12 = userPoolRes1.UserPool.Domain; - const socialIdpProvidersV12 = await listSocialIdpProviders(UserPoolId, region); - - // delete domain manually - await deleteUserPoolDomain(HostedUIDomain, UserPoolId, region); - // delete providers manually - const socialProviders = ['Facebook', 'Google', 'LoginWithAmazon', 'SignInWithApple']; - await deleteSocialIdpProviders(socialProviders, UserPoolId, region); - await amplifyPushForce(projRoot2, true); - const userPoolRes2 = await getUserPool(UserPoolId, region); - const userPoolDomainLatest = userPoolRes2.UserPool.Domain; - const socialIdpProvidersLatest = await listSocialIdpProviders(UserPoolId, region); - // check same domain should exist - expect(userPoolDomainV12).toEqual(userPoolDomainLatest); - // check the Social Idp Provider exists - expect(socialIdpProvidersV12).toMatchObject(socialIdpProvidersLatest); - } finally { - deleteProjectDir(projRoot2); - } - }); -});