@@ -5,11 +5,16 @@ import { exportSecrets } from "./lib";
55describe ( "exportSecrets()" , ( ) => {
66 describe ( "success" , ( ) => {
77 const coreMock = {
8- getInput : vi
9- . fn ( )
10- . mockReturnValue (
11- '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C"}' ,
12- ) ,
8+ getInput : vi . fn ( ) . mockImplementation ( ( s : string ) => {
9+ switch ( s ) {
10+ case "secrets" :
11+ return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D"}' ;
12+ case "downcase-tf-var" :
13+ return "" ;
14+ default :
15+ return "" ;
16+ }
17+ } ) ,
1318 exportVariable : vi . fn ( ) ,
1419 } ;
1520
@@ -23,7 +28,64 @@ describe("exportSecrets()", () => {
2328 expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
2429 } ) ;
2530
26- it ( "calls exportVariable() 3 times" , ( ) => {
31+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
32+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
33+ } ) ;
34+
35+ it ( "calls exportVariable() 4 times" , ( ) => {
36+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
37+ 1 ,
38+ "KEY_A" ,
39+ "VALUE_A" ,
40+ ) ;
41+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
42+ 2 ,
43+ "KEY_B" ,
44+ "VALUE_B" ,
45+ ) ;
46+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
47+ 3 ,
48+ "KEY_C" ,
49+ "VALUE_C" ,
50+ ) ;
51+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
52+ 4 ,
53+ "TF_VAR_KEY_D" ,
54+ "VALUE_D" ,
55+ ) ;
56+ } ) ;
57+ } ) ;
58+
59+ describe ( "success_downcase-tf-var" , ( ) => {
60+ const coreMock = {
61+ getInput : vi . fn ( ) . mockImplementation ( ( s : string ) => {
62+ switch ( s ) {
63+ case "secrets" :
64+ return '{"KEY_A":"VALUE_A","KEY_B":"VALUE_B","KEY_C":"VALUE_C","TF_VAR_KEY_D":"VALUE_D"}' ;
65+ case "downcase-tf-var" :
66+ return "true" ;
67+ default :
68+ return "" ;
69+ }
70+ } ) ,
71+ exportVariable : vi . fn ( ) ,
72+ } ;
73+
74+ it ( "does not throws an error" , ( ) => {
75+ expect ( ( ) => {
76+ exportSecrets ( coreMock as unknown as typeof core ) ;
77+ } ) . not . toThrow ( ) ;
78+ } ) ;
79+
80+ it ( 'calls getInput() with "secrets"' , ( ) => {
81+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
82+ } ) ;
83+
84+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
85+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
86+ } ) ;
87+
88+ it ( "calls exportVariable() 4 times" , ( ) => {
2789 expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
2890 1 ,
2991 "KEY_A" ,
@@ -39,12 +101,26 @@ describe("exportSecrets()", () => {
39101 "KEY_C" ,
40102 "VALUE_C" ,
41103 ) ;
104+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
105+ 4 ,
106+ "TF_VAR_key_d" ,
107+ "VALUE_D" ,
108+ ) ;
42109 } ) ;
43110 } ) ;
44111
45112 describe ( "secrets is empty" , ( ) => {
46113 const coreMock = {
47- getInput : vi . fn ( ) . mockReturnValue ( "" ) ,
114+ getInput : vi . fn ( ) . mockImplementation ( ( s : string ) => {
115+ switch ( s ) {
116+ case "secrets" :
117+ return "{" ;
118+ case "downcase-tf-var" :
119+ return "" ;
120+ default :
121+ return "" ;
122+ }
123+ } ) ,
48124 exportVariable : vi . fn ( ) ,
49125 } ;
50126
@@ -58,14 +134,27 @@ describe("exportSecrets()", () => {
58134 expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
59135 } ) ;
60136
137+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
138+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
139+ } ) ;
140+
61141 it ( "does not calls exportVariable()" , ( ) => {
62142 expect ( coreMock . exportVariable ) . not . toHaveBeenCalled ( ) ;
63143 } ) ;
64144 } ) ;
65145
66146 describe ( "secret is invalid JSON" , ( ) => {
67147 const coreMock = {
68- getInput : vi . fn ( ) . mockReturnValue ( "{" ) ,
148+ getInput : vi . fn ( ) . mockImplementation ( ( s : string ) => {
149+ switch ( s ) {
150+ case "secrets" :
151+ return "{" ;
152+ case "downcase-tf-var" :
153+ return "" ;
154+ default :
155+ return "" ;
156+ }
157+ } ) ,
69158 exportVariable : vi . fn ( ) ,
70159 } ;
71160
@@ -79,6 +168,10 @@ describe("exportSecrets()", () => {
79168 expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
80169 } ) ;
81170
171+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
172+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
173+ } ) ;
174+
82175 it ( "does not calls exportVariable()" , ( ) => {
83176 expect ( coreMock . exportVariable ) . not . toHaveBeenCalled ( ) ;
84177 } ) ;
0 commit comments