From c784d98def7f4e3487d6fe2ebd5ed9387935660f Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Fri, 7 Aug 2020 16:20:10 +0100 Subject: [PATCH] chore(cognito): move some tests into the correct describe block. Some tests added later were not placed in the correct top-level describe block. No tests have been added, removed or modified in this change. --- .../aws-cognito/test/user-pool.test.ts | 311 +++++++++--------- 1 file changed, 156 insertions(+), 155 deletions(-) diff --git a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts index 801879f6ea55a..cf24bed751e34 100644 --- a/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts +++ b/packages/@aws-cdk/aws-cognito/test/user-pool.test.ts @@ -896,202 +896,203 @@ describe('User Pool', () => { }, }); }); -}); - -test('addClient', () => { - // GIVEN - const stack = new Stack(); - - // WHEN - const userpool = new UserPool(stack, 'Pool'); - userpool.addClient('UserPoolClient', { - userPoolClientName: 'userpoolclient', - }); - const imported = UserPool.fromUserPoolId(stack, 'imported', 'imported-userpool-id'); - imported.addClient('UserPoolImportedClient', { - userPoolClientName: 'userpoolimportedclient', - }); - - // THEN - expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolClient', { - ClientName: 'userpoolclient', - UserPoolId: stack.resolve(userpool.userPoolId), - }); - expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolClient', { - ClientName: 'userpoolimportedclient', - UserPoolId: stack.resolve(imported.userPoolId), - }); -}); - -test('addDomain', () => { - // GIVEN - const stack = new Stack(); - - // WHEN - const userpool = new UserPool(stack, 'Pool'); - userpool.addDomain('UserPoolDomain', { - cognitoDomain: { - domainPrefix: 'userpooldomain', - }, - }); - const imported = UserPool.fromUserPoolId(stack, 'imported', 'imported-userpool-id'); - imported.addDomain('UserPoolImportedDomain', { - cognitoDomain: { - domainPrefix: 'userpoolimporteddomain', - }, - }); - - // THEN - expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolDomain', { - Domain: 'userpooldomain', - UserPoolId: stack.resolve(userpool.userPoolId), - }); - expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolDomain', { - Domain: 'userpoolimporteddomain', - UserPoolId: stack.resolve(imported.userPoolId), - }); -}); - -test('registered identity providers', () => { - // GIVEN - const stack = new Stack(); - const userPool = new UserPool(stack, 'pool'); - const provider1 = UserPoolIdentityProvider.fromProviderName(stack, 'provider1', 'provider1'); - const provider2 = UserPoolIdentityProvider.fromProviderName(stack, 'provider2', 'provider2'); - - // WHEN - userPool.registerIdentityProvider(provider1); - userPool.registerIdentityProvider(provider2); - - // THEN - expect(userPool.identityProviders).toEqual([provider1, provider2]); -}); -function fooFunction(scope: Construct, name: string): lambda.IFunction { - return new lambda.Function(scope, name, { - functionName: name, - code: lambda.Code.inline('foo'), - runtime: lambda.Runtime.NODEJS_12_X, - handler: 'index.handler', - }); -} - -describe('AccountRecoverySetting should be configured correctly', () => { - test('EMAIL_AND_PHONE_WITHOUT_MFA', () => { + test('addClient', () => { // GIVEN const stack = new Stack(); // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.EMAIL_AND_PHONE_WITHOUT_MFA }); + const userpool = new UserPool(stack, 'Pool'); + userpool.addClient('UserPoolClient', { + userPoolClientName: 'userpoolclient', + }); + const imported = UserPool.fromUserPoolId(stack, 'imported', 'imported-userpool-id'); + imported.addClient('UserPoolImportedClient', { + userPoolClientName: 'userpoolimportedclient', + }); // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'verified_email', Priority: 1 }, - { Name: 'verified_phone_number', Priority: 2 }, - ], - }, + expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolClient', { + ClientName: 'userpoolclient', + UserPoolId: stack.resolve(userpool.userPoolId), + }); + expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolClient', { + ClientName: 'userpoolimportedclient', + UserPoolId: stack.resolve(imported.userPoolId), }); }); - test('PHONE_WITHOUT_MFA_AND_EMAIL', () => { + test('addDomain', () => { // GIVEN const stack = new Stack(); // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_WITHOUT_MFA_AND_EMAIL }); + const userpool = new UserPool(stack, 'Pool'); + userpool.addDomain('UserPoolDomain', { + cognitoDomain: { + domainPrefix: 'userpooldomain', + }, + }); + const imported = UserPool.fromUserPoolId(stack, 'imported', 'imported-userpool-id'); + imported.addDomain('UserPoolImportedDomain', { + cognitoDomain: { + domainPrefix: 'userpoolimporteddomain', + }, + }); // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'verified_phone_number', Priority: 1 }, - { Name: 'verified_email', Priority: 2 }, - ], - }, + expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolDomain', { + Domain: 'userpooldomain', + UserPoolId: stack.resolve(userpool.userPoolId), + }); + expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolDomain', { + Domain: 'userpoolimporteddomain', + UserPoolId: stack.resolve(imported.userPoolId), }); }); - test('EMAIL_ONLY', () => { + test('registered identity providers', () => { // GIVEN const stack = new Stack(); + const userPool = new UserPool(stack, 'pool'); + const provider1 = UserPoolIdentityProvider.fromProviderName(stack, 'provider1', 'provider1'); + const provider2 = UserPoolIdentityProvider.fromProviderName(stack, 'provider2', 'provider2'); // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.EMAIL_ONLY }); + userPool.registerIdentityProvider(provider1); + userPool.registerIdentityProvider(provider2); // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'verified_email', Priority: 1 }, - ], - }, - }); + expect(userPool.identityProviders).toEqual([provider1, provider2]); }); - test('PHONE_ONLY_WITHOUT_MFA', () => { - // GIVEN - const stack = new Stack(); + describe('AccountRecoverySetting should be configured correctly', () => { + test('EMAIL_AND_PHONE_WITHOUT_MFA', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.EMAIL_AND_PHONE_WITHOUT_MFA }); + + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'verified_email', Priority: 1 }, + { Name: 'verified_phone_number', Priority: 2 }, + ], + }, + }); + }); - // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_ONLY_WITHOUT_MFA }); + test('PHONE_WITHOUT_MFA_AND_EMAIL', () => { + // GIVEN + const stack = new Stack(); - // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'verified_phone_number', Priority: 1 }, - ], - }, + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_WITHOUT_MFA_AND_EMAIL }); + + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'verified_phone_number', Priority: 1 }, + { Name: 'verified_email', Priority: 2 }, + ], + }, + }); }); - }); - test('NONE', () => { - // GIVEN - const stack = new Stack(); + test('EMAIL_ONLY', () => { + // GIVEN + const stack = new Stack(); - // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.NONE }); + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.EMAIL_ONLY }); - // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'admin_only', Priority: 1 }, - ], - }, + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'verified_email', Priority: 1 }, + ], + }, + }); }); - }); - test('PHONE_AND_EMAIL', () => { - // GIVEN - const stack = new Stack(); + test('PHONE_ONLY_WITHOUT_MFA', () => { + // GIVEN + const stack = new Stack(); - // WHEN - new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_AND_EMAIL }); + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_ONLY_WITHOUT_MFA }); - // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: ABSENT, + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'verified_phone_number', Priority: 1 }, + ], + }, + }); }); - }); - test('default', () => { - // GIVEN - const stack = new Stack(); + test('NONE', () => { + // GIVEN + const stack = new Stack(); - // WHEN - new UserPool(stack, 'pool'); + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.NONE }); - // THEN - expect(stack).toHaveResource('AWS::Cognito::UserPool', { - AccountRecoverySetting: { - RecoveryMechanisms: [ - { Name: 'verified_phone_number', Priority: 1 }, - { Name: 'verified_email', Priority: 2 }, - ], - }, + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'admin_only', Priority: 1 }, + ], + }, + }); + }); + + test('PHONE_AND_EMAIL', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new UserPool(stack, 'pool', { accountRecovery: AccountRecovery.PHONE_AND_EMAIL }); + + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: ABSENT, + }); + }); + + test('default', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new UserPool(stack, 'pool'); + + // THEN + expect(stack).toHaveResource('AWS::Cognito::UserPool', { + AccountRecoverySetting: { + RecoveryMechanisms: [ + { Name: 'verified_phone_number', Priority: 1 }, + { Name: 'verified_email', Priority: 2 }, + ], + }, + }); }); }); }); + + +function fooFunction(scope: Construct, name: string): lambda.IFunction { + return new lambda.Function(scope, name, { + functionName: name, + code: lambda.Code.inline('foo'), + runtime: lambda.Runtime.NODEJS_12_X, + handler: 'index.handler', + }); +} \ No newline at end of file