11import { describe , it , expect , vi , beforeEach } from 'vitest' ;
2- import { handler } from '../index ' ;
2+ import { handler } from '../lambda ' ;
33import { AMIManager } from '../ami' ;
44import { getConfig } from '../config' ;
55
66vi . mock ( '../ami' ) ;
77vi . mock ( '../config' ) ;
8- vi . mock ( '../../shared /aws-powertools-util' , ( ) => ( {
8+ vi . mock ( '@aws-github-runner /aws-powertools-util' , ( ) => ( {
99 logger : {
1010 addContext : vi . fn ( ) ,
1111 info : vi . fn ( ) ,
1212 error : vi . fn ( ) ,
1313 } ,
14- metrics : {
15- addMetric : vi . fn ( ) ,
16- } ,
1714} ) ) ;
1815
1916describe ( 'Lambda Handler' , ( ) => {
@@ -43,13 +40,13 @@ describe('Lambda Handler', () => {
4340 message : 'Updated successfully' ,
4441 } ) ;
4542
46- await handler ( { } , mockContext as any ) ;
43+ await handler ( { } , mockContext ) ;
4744
4845 expect ( AMIManager . prototype . getLatestAmi ) . toHaveBeenCalledWith ( mockConfig . amiFilter ) ;
4946 expect ( AMIManager . prototype . updateLaunchTemplate ) . toHaveBeenCalledWith (
5047 mockConfig . launchTemplateName ,
5148 'ami-new' ,
52- mockConfig . dryRun
49+ mockConfig . dryRun ,
5350 ) ;
5451 } ) ;
5552
@@ -60,21 +57,21 @@ describe('Lambda Handler', () => {
6057 message : 'Update failed' ,
6158 } ) ;
6259
63- await expect ( handler ( { } , mockContext as any ) ) . rejects . toThrow ( 'Update failed' ) ;
60+ await expect ( handler ( { } , mockContext ) ) . rejects . toThrow ( 'Update failed' ) ;
6461 } ) ;
6562
6663 it ( 'should handle errors in getLatestAmi' , async ( ) => {
6764 const error = new Error ( 'Failed to get AMI' ) ;
6865 vi . mocked ( AMIManager . prototype . getLatestAmi ) . mockRejectedValue ( error ) ;
6966
70- await expect ( handler ( { } , mockContext as any ) ) . rejects . toThrow ( 'Failed to get AMI' ) ;
67+ await expect ( handler ( { } , mockContext ) ) . rejects . toThrow ( 'Failed to get AMI' ) ;
7168 } ) ;
7269
7370 it ( 'should handle errors in updateLaunchTemplate' , async ( ) => {
7471 vi . mocked ( AMIManager . prototype . getLatestAmi ) . mockResolvedValue ( 'ami-new' ) ;
7572 const error = new Error ( 'Failed to update template' ) ;
7673 vi . mocked ( AMIManager . prototype . updateLaunchTemplate ) . mockRejectedValue ( error ) ;
7774
78- await expect ( handler ( { } , mockContext as any ) ) . rejects . toThrow ( 'Failed to update template' ) ;
75+ await expect ( handler ( { } , mockContext ) ) . rejects . toThrow ( 'Failed to update template' ) ;
7976 } ) ;
80- } ) ;
77+ } ) ;
0 commit comments