1- import { beforeAll , describe , expect , it , vi } from 'vitest' ;
1+ import { describe , expect , it , vi } from 'vitest' ;
22import { customUserAgentMiddleware } from '../../src/awsSdkUtils.js' ;
33import {
44 addUserAgentMiddleware ,
@@ -8,14 +8,11 @@ import {
88
99vi . hoisted ( ( ) => {
1010 process . env . AWS_EXECUTION_ENV = '' ;
11+ process . env . AWS_SDK_UA_APP_ID = 'test' ;
1112} ) ;
1213
1314describe ( 'Helpers: awsSdk' , ( ) => {
1415 describe ( 'Function: userAgentMiddleware' , ( ) => {
15- beforeAll ( ( ) => {
16- vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => ( { } ) ) ;
17- } ) ;
18-
1916 it ( 'handles gracefully failures in adding a middleware and only log a warning' , ( ) => {
2017 // Prepare
2118 const client = {
@@ -25,13 +22,10 @@ describe('Helpers: awsSdk', () => {
2522 } ,
2623 } ,
2724 } ;
28- const warningSpy = vi
29- . spyOn ( console , 'warn' )
30- . mockImplementation ( ( ) => ( { } ) ) ;
3125
3226 // Act & Assess
3327 expect ( ( ) => addUserAgentMiddleware ( client , 'my-feature' ) ) . not . toThrow ( ) ;
34- expect ( warningSpy ) . toHaveBeenCalledTimes ( 1 ) ;
28+ expect ( console . warn ) . toHaveBeenCalledTimes ( 1 ) ;
3529 } ) ;
3630
3731 it ( 'should return and do nothing if the client already has a Powertools UA middleware' , async ( ) => {
@@ -88,6 +82,11 @@ describe('Helpers: awsSdk', () => {
8882 } ) ;
8983 } ) ;
9084
85+ it ( 'concatenates the PT AWS_SDK_UA_APP_ID when one is already set' , ( ) => {
86+ // Assess
87+ expect ( process . env . AWS_SDK_UA_APP_ID ) . toEqual ( `test/PT/TEST/${ version } ` ) ;
88+ } ) ;
89+
9190 describe ( 'Function: customUserAgentMiddleware' , ( ) => {
9291 it ( 'returns a middleware function' , ( ) => {
9392 // Prepare
0 commit comments