1
- import { beforeAll , describe , expect , it , vi } from 'vitest' ;
1
+ import { describe , expect , it , vi } from 'vitest' ;
2
2
import { customUserAgentMiddleware } from '../../src/awsSdkUtils.js' ;
3
3
import {
4
4
addUserAgentMiddleware ,
@@ -8,14 +8,11 @@ import {
8
8
9
9
vi . hoisted ( ( ) => {
10
10
process . env . AWS_EXECUTION_ENV = '' ;
11
+ process . env . AWS_SDK_UA_APP_ID = 'test' ;
11
12
} ) ;
12
13
13
14
describe ( 'Helpers: awsSdk' , ( ) => {
14
15
describe ( 'Function: userAgentMiddleware' , ( ) => {
15
- beforeAll ( ( ) => {
16
- vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => ( { } ) ) ;
17
- } ) ;
18
-
19
16
it ( 'handles gracefully failures in adding a middleware and only log a warning' , ( ) => {
20
17
// Prepare
21
18
const client = {
@@ -25,13 +22,10 @@ describe('Helpers: awsSdk', () => {
25
22
} ,
26
23
} ,
27
24
} ;
28
- const warningSpy = vi
29
- . spyOn ( console , 'warn' )
30
- . mockImplementation ( ( ) => ( { } ) ) ;
31
25
32
26
// Act & Assess
33
27
expect ( ( ) => addUserAgentMiddleware ( client , 'my-feature' ) ) . not . toThrow ( ) ;
34
- expect ( warningSpy ) . toHaveBeenCalledTimes ( 1 ) ;
28
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 1 ) ;
35
29
} ) ;
36
30
37
31
it ( 'should return and do nothing if the client already has a Powertools UA middleware' , async ( ) => {
@@ -88,6 +82,11 @@ describe('Helpers: awsSdk', () => {
88
82
} ) ;
89
83
} ) ;
90
84
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
+
91
90
describe ( 'Function: customUserAgentMiddleware' , ( ) => {
92
91
it ( 'returns a middleware function' , ( ) => {
93
92
// Prepare
0 commit comments