@@ -4,7 +4,6 @@ import { App, SecretValue, Stack } from 'aws-cdk-lib';
44import { Match , Template } from 'aws-cdk-lib/assertions' ;
55import assert from 'node:assert' ;
66import {
7- AmplifyFunction ,
87 BackendOutputEntry ,
98 BackendOutputStorageStrategy ,
109} from '@aws-amplify/plugin-types' ;
@@ -16,7 +15,6 @@ import {
1615 UserPoolClient ,
1716} from 'aws-cdk-lib/aws-cognito' ;
1817import { authOutputKey } from '@aws-amplify/backend-output-schemas' ;
19- import { Code , Function , Runtime } from 'aws-cdk-lib/aws-lambda' ;
2018import { DEFAULTS } from './defaults.js' ;
2119
2220const googleClientId = 'googleClientId' ;
@@ -2423,83 +2421,4 @@ void describe('Auth construct', () => {
24232421 assert . equal ( name . startsWith ( expectedPrefix ) , true ) ;
24242422 } ) ;
24252423 } ) ;
2426-
2427- void describe ( 'addTrigger' , ( ) => {
2428- void it ( 'attaches lambda function to UserPool Lambda config' , ( ) => {
2429- const app = new App ( ) ;
2430- const stack = new Stack ( app ) ;
2431- const testFunc = new Function ( stack , 'testFunc' , {
2432- code : Code . fromInline ( 'test code' ) ,
2433- handler : 'index.handler' ,
2434- runtime : Runtime . NODEJS_18_X ,
2435- } ) ;
2436- const authConstruct = new AmplifyAuth ( stack , 'testAuth' , {
2437- loginWith : { email : true } ,
2438- } ) ;
2439- authConstruct . addTrigger ( 'createAuthChallenge' , testFunc ) ;
2440- const template = Template . fromStack ( stack ) ;
2441- const lambdas = template . findResources ( 'AWS::Lambda::Function' ) ;
2442- if ( Object . keys ( lambdas ) . length !== 1 ) {
2443- assert . fail (
2444- 'Expected one and only one lambda function in the template'
2445- ) ;
2446- }
2447- const handlerLogicalId = Object . keys ( lambdas ) [ 0 ] ;
2448- template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
2449- LambdaConfig : {
2450- CreateAuthChallenge : {
2451- [ 'Fn::GetAtt' ] : [ handlerLogicalId , 'Arn' ] ,
2452- } ,
2453- } ,
2454- } ) ;
2455- } ) ;
2456-
2457- void it ( 'attaches AmplifyFunction to UserPool Lambda config' , ( ) => {
2458- const app = new App ( ) ;
2459- const stack = new Stack ( app ) ;
2460- const testFunc = new Function ( stack , 'testFunc' , {
2461- code : Code . fromInline ( 'test code' ) ,
2462- handler : 'index.handler' ,
2463- runtime : Runtime . NODEJS_18_X ,
2464- } ) ;
2465- const amplifyFuncStub : AmplifyFunction = {
2466- resources : {
2467- lambda : testFunc ,
2468- } ,
2469- } ;
2470- const authConstruct = new AmplifyAuth ( stack , 'testAuth' , {
2471- loginWith : { email : true } ,
2472- } ) ;
2473- authConstruct . addTrigger ( 'createAuthChallenge' , amplifyFuncStub ) ;
2474- const template = Template . fromStack ( stack ) ;
2475- const lambdas = template . findResources ( 'AWS::Lambda::Function' ) ;
2476- if ( Object . keys ( lambdas ) . length !== 1 ) {
2477- assert . fail (
2478- 'Expected one and only one lambda function in the template'
2479- ) ;
2480- }
2481- const handlerLogicalId = Object . keys ( lambdas ) [ 0 ] ;
2482- template . hasResourceProperties ( 'AWS::Cognito::UserPool' , {
2483- LambdaConfig : {
2484- CreateAuthChallenge : {
2485- [ 'Fn::GetAtt' ] : [ handlerLogicalId , 'Arn' ] ,
2486- } ,
2487- } ,
2488- } ) ;
2489- } ) ;
2490-
2491- void it ( 'stores attribution data in stack' , ( ) => {
2492- const app = new App ( ) ;
2493- const stack = new Stack ( app ) ;
2494- new AmplifyAuth ( stack , 'testAuth' , {
2495- loginWith : { email : true } ,
2496- } ) ;
2497-
2498- const template = Template . fromStack ( stack ) ;
2499- assert . equal (
2500- JSON . parse ( template . toJSON ( ) . Description ) . stackType ,
2501- 'auth-Cognito'
2502- ) ;
2503- } ) ;
2504- } ) ;
25052424} ) ;
0 commit comments