Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Niranjan Jayakar committed Jun 9, 2020
1 parent 355d4f4 commit e57a713
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
33 changes: 32 additions & 1 deletion packages/@aws-cdk/aws-cognito/test/user-pool-idps/amazon.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@aws-cdk/assert/jest';
import { Stack } from '@aws-cdk/core';
import { UserPool, UserPoolIdentityProviderAmazon } from '../../lib';
import { ProviderAttribute, UserPool, UserPoolIdentityProviderAmazon } from '../../lib';

describe('UserPoolIdentityProvider', () => {
describe('amazon', () => {
Expand Down Expand Up @@ -66,5 +66,36 @@ describe('UserPoolIdentityProvider', () => {
// THEN
expect(pool.identityProviders).toContain(provider);
});

test('attribute mapping', () => {
// GIVEN
const stack = new Stack();
const pool = new UserPool(stack, 'userpool');

// WHEN
new UserPoolIdentityProviderAmazon(stack, 'userpoolidp', {
userPool: pool,
clientId: 'amazn-client-id',
clientSecret: 'amzn-client-secret',
attributeMapping: {
givenName: ProviderAttribute.AMAZON_NAME,
address: ProviderAttribute.custom('amzn-address'),
custom: {
customAttr1: ProviderAttribute.AMAZON_EMAIL,
customAttr2: ProviderAttribute.custom('amzn-custom-attr'),
},
},
});

// THEN
expect(stack).toHaveResource('AWS::Cognito::UserPoolIdentityProvider', {
AttributeMapping: {
given_name: 'name',
address: 'amzn-address',
customAttr1: 'email',
customAttr2: 'amzn-custom-attr',
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('UserPoolIdentityProvider', () => {
const pool = new UserPool(stack, 'UserPool');

// WHEN
const idp = new MyIdp(stack, 'MyIdp1', {
const idp = new MyIdp(stack, 'MyIdp', {
userPool: pool,
attributeMapping: {
givenName: ProviderAttribute.FACEBOOK_NAME,
Expand All @@ -55,7 +55,7 @@ describe('UserPoolIdentityProvider', () => {
const pool = new UserPool(stack, 'UserPool');

// WHEN
const idp = new MyIdp(stack, 'MyIdp1', {
const idp = new MyIdp(stack, 'MyIdp', {
userPool: pool,
attributeMapping: {
custom: {
Expand All @@ -78,7 +78,7 @@ describe('UserPoolIdentityProvider', () => {
const pool = new UserPool(stack, 'UserPool');

// WHEN
const idp = new MyIdp(stack, 'MyIdp1', {
const idp = new MyIdp(stack, 'MyIdp', {
userPool: pool,
attributeMapping: {
address: ProviderAttribute.custom('custom-provider-attr'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@aws-cdk/assert/jest';
import { Stack } from '@aws-cdk/core';
import { UserPool, UserPoolIdentityProviderFacebook } from '../../lib';
import { ProviderAttribute, UserPool, UserPoolIdentityProviderFacebook } from '../../lib';

describe('UserPoolIdentityProvider', () => {
describe('facebook', () => {
Expand Down Expand Up @@ -68,5 +68,36 @@ describe('UserPoolIdentityProvider', () => {
// THEN
expect(pool.identityProviders).toContain(provider);
});

test('attribute mapping', () => {
// GIVEN
const stack = new Stack();
const pool = new UserPool(stack, 'userpool');

// WHEN
new UserPoolIdentityProviderFacebook(stack, 'userpoolidp', {
userPool: pool,
clientId: 'fb-client-id',
clientSecret: 'fb-client-secret',
attributeMapping: {
givenName: ProviderAttribute.FACEBOOK_NAME,
address: ProviderAttribute.custom('fb-address'),
custom: {
customAttr1: ProviderAttribute.FACEBOOK_EMAIL,
customAttr2: ProviderAttribute.custom('fb-custom-attr'),
},
},
});

// THEN
expect(stack).toHaveResource('AWS::Cognito::UserPoolIdentityProvider', {
AttributeMapping: {
given_name: 'name',
address: 'fb-address',
customAttr1: 'email',
customAttr2: 'fb-custom-attr',
},
});
});
});
});

0 comments on commit e57a713

Please sign in to comment.