@@ -64,21 +64,23 @@ describe('when getting metrics', () => {
6464 ] ) ;
6565 } ) ;
6666
67- test ( 'put metric catches error' , ( ) => {
67+ test ( 'put metric catches error' , async ( ) => {
6868 const spyConsoleError : jest . SpyInstance = jest
6969 . spyOn ( global . console , 'error' ) . mockImplementation ( ( ) => { } ) ;
70- putMetricData . mockImplementationOnce ( ( ) => {
71- throw awsUtil . error ( new Error ( ) , {
72- code : 'InternalServiceError' ,
73- message : 'An error occurred (InternalServiceError) when '
74- + 'calling the PutMetricData operation: ' ,
75- } ) ;
70+ putMetricData . mockReturnValueOnce ( {
71+ promise : jest . fn ( ) . mockRejectedValueOnce (
72+ awsUtil . error ( new Error ( ) , {
73+ code : 'InternalServiceError' ,
74+ message : 'An error occurred (InternalServiceError) when '
75+ + 'calling the PutMetricData operation: ' ,
76+ } )
77+ )
7678 } ) ;
7779 const publisher = new MetricPublisher ( session , NAMESPACE ) ;
7880 const dimensions = new Map < string , string > ( ) ;
7981 dimensions . set ( 'DimensionKeyActionType' , Action . Create ) ;
8082 dimensions . set ( 'DimensionKeyResourceType' , RESOURCE_TYPE ) ;
81- publisher . publishMetric (
83+ await publisher . publishMetric (
8284 MetricTypes . HandlerInvocationCount ,
8385 dimensions ,
8486 StandardUnit . Count ,
@@ -115,7 +117,7 @@ describe('when getting metrics', () => {
115117 test ( 'publish exception metric' , ( ) => {
116118 const proxy = new MetricsPublisherProxy ( ACCOUNT_ID , RESOURCE_TYPE ) ;
117119 proxy . addMetricsPublisher ( session ) ;
118- proxy . publishExceptionMetric ( MOCK_DATE , Action . Create , new Error ( 'fake-err' ) ) ;
120+ proxy . publishExceptionMetric ( MOCK_DATE , Action . Create , new Error ( 'fake-err' ) ) ;
119121 expect ( putMetricData ) . toHaveBeenCalledTimes ( 1 ) ;
120122 expect ( putMetricData ) . toHaveBeenCalledWith ( {
121123 MetricData : [ {
@@ -145,7 +147,7 @@ describe('when getting metrics', () => {
145147 test ( 'publish invocation metric' , ( ) => {
146148 const proxy = new MetricsPublisherProxy ( ACCOUNT_ID , RESOURCE_TYPE ) ;
147149 proxy . addMetricsPublisher ( session ) ;
148- proxy . publishInvocationMetric ( MOCK_DATE , Action . Create ) ;
150+ proxy . publishInvocationMetric ( MOCK_DATE , Action . Create ) ;
149151 expect ( putMetricData ) . toHaveBeenCalledTimes ( 1 ) ;
150152 expect ( putMetricData ) . toHaveBeenCalledWith ( {
151153 MetricData : [ {
@@ -194,7 +196,6 @@ describe('when getting metrics', () => {
194196 } ) ;
195197 } ) ;
196198
197-
198199 test ( 'publish log delivery exception metric' , ( ) => {
199200 const proxy = new MetricsPublisherProxy ( ACCOUNT_ID , RESOURCE_TYPE ) ;
200201 proxy . addMetricsPublisher ( session ) ;
0 commit comments