11import { afterEach , describe , expect , test as it , vi } from "vitest" ;
22
33import { getArrayForCommaSeparatedString } from "../utils/getArrayForCommaSeparatedString" ;
4+ import { getBearerTokenEnvKey } from "../utils/getBearerTokenEnvKey" ;
45import { NODE_AUTH_SCHEME_PREFERENCE_OPTIONS } from "./NODE_AUTH_SCHEME_PREFERENCE_OPTIONS" ;
56
67vi . mock ( "../utils/getArrayForCommaSeparatedString" ) ;
8+ vi . mock ( "../utils/getBearerTokenEnvKey" ) ;
79
810describe ( "NODE_AUTH_SCHEME_PREFERENCE_OPTIONS" , ( ) => {
911 const mockInput = "a,b,c" ;
1012 const mockOutput = [ "a" , "b" , "c" ] ;
13+ const mockBearerTokenEnvKey = "AWS_BEARER_TOKEN_SERVICE_NAME" ;
1114
1215 vi . mocked ( getArrayForCommaSeparatedString ) . mockReturnValue ( mockOutput ) ;
16+ vi . mocked ( getBearerTokenEnvKey ) . mockReturnValue ( mockBearerTokenEnvKey ) ;
1317
1418 afterEach ( ( ) => {
1519 vi . clearAllMocks ( ) ;
@@ -19,18 +23,42 @@ describe("NODE_AUTH_SCHEME_PREFERENCE_OPTIONS", () => {
1923 it ( "returns undefined if no value is provided" , ( ) => {
2024 expect ( func ( { } ) ) . toEqual ( undefined ) ;
2125 expect ( getArrayForCommaSeparatedString ) . not . toBeCalled ( ) ;
26+ expect ( getBearerTokenEnvKey ) . not . toBeCalled ( ) ;
2227 } ) ;
2328
2429 it ( "returns list if value is defined" , ( ) => {
2530 expect ( func ( { [ key ] : mockInput } ) ) . toEqual ( mockOutput ) ;
2631 expect ( getArrayForCommaSeparatedString ) . toHaveBeenCalledTimes ( 1 ) ;
2732 expect ( getArrayForCommaSeparatedString ) . toBeCalledWith ( mockInput ) ;
33+ expect ( getBearerTokenEnvKey ) . not . toBeCalled ( ) ;
2834 } ) ;
2935 } ;
3036
3137 describe ( "environmentVariableSelector" , ( ) => {
3238 const { environmentVariableSelector } = NODE_AUTH_SCHEME_PREFERENCE_OPTIONS ;
3339 test ( environmentVariableSelector , "AWS_AUTH_SCHEME_PREFERENCE" ) ;
40+
41+ describe ( "if signingName is defined" , ( ) => {
42+ const env = { AWS_AUTH_SCHEME_PREFERENCE : mockInput } ;
43+ const options = { signingName : "Signing Name" } ;
44+
45+ afterEach ( ( ) => {
46+ expect ( getBearerTokenEnvKey ) . toHaveBeenCalledTimes ( 1 ) ;
47+ expect ( getBearerTokenEnvKey ) . toBeCalledWith ( options . signingName ) ;
48+ } ) ;
49+
50+ it ( `ignores if mockBearerTokenEnvKey is not set` , ( ) => {
51+ expect ( environmentVariableSelector ( env , options ) ) . toEqual ( mockOutput ) ;
52+ expect ( getArrayForCommaSeparatedString ) . toHaveBeenCalledTimes ( 1 ) ;
53+ expect ( getArrayForCommaSeparatedString ) . toBeCalledWith ( mockInput ) ;
54+ } ) ;
55+
56+ it ( "returns ['httpBearerAuth'] if mockBearerTokenEnvKey is set" , ( ) => {
57+ const envWithToken = { ...env , [ mockBearerTokenEnvKey ] : "token" } ;
58+ expect ( environmentVariableSelector ( envWithToken , options ) ) . toEqual ( [ "httpBearerAuth" ] ) ;
59+ expect ( getArrayForCommaSeparatedString ) . not . toHaveBeenCalled ( ) ;
60+ } ) ;
61+ } ) ;
3462 } ) ;
3563
3664 describe ( "configFileSelector" , ( ) => {
0 commit comments