@@ -5,11 +5,16 @@ import { exportSecrets } from "./lib";
5
5
describe ( "exportSecrets()" , ( ) => {
6
6
describe ( "success" , ( ) => {
7
7
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
+ } ) ,
13
18
exportVariable : vi . fn ( ) ,
14
19
} ;
15
20
@@ -23,7 +28,64 @@ describe("exportSecrets()", () => {
23
28
expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
24
29
} ) ;
25
30
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" , ( ) => {
27
89
expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
28
90
1 ,
29
91
"KEY_A" ,
@@ -39,12 +101,26 @@ describe("exportSecrets()", () => {
39
101
"KEY_C" ,
40
102
"VALUE_C" ,
41
103
) ;
104
+ expect ( coreMock . exportVariable ) . toHaveBeenNthCalledWith (
105
+ 4 ,
106
+ "TF_VAR_key_d" ,
107
+ "VALUE_D" ,
108
+ ) ;
42
109
} ) ;
43
110
} ) ;
44
111
45
112
describe ( "secrets is empty" , ( ) => {
46
113
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
+ } ) ,
48
124
exportVariable : vi . fn ( ) ,
49
125
} ;
50
126
@@ -58,14 +134,27 @@ describe("exportSecrets()", () => {
58
134
expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
59
135
} ) ;
60
136
137
+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
138
+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
139
+ } ) ;
140
+
61
141
it ( "does not calls exportVariable()" , ( ) => {
62
142
expect ( coreMock . exportVariable ) . not . toHaveBeenCalled ( ) ;
63
143
} ) ;
64
144
} ) ;
65
145
66
146
describe ( "secret is invalid JSON" , ( ) => {
67
147
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
+ } ) ,
69
158
exportVariable : vi . fn ( ) ,
70
159
} ;
71
160
@@ -79,6 +168,10 @@ describe("exportSecrets()", () => {
79
168
expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "secrets" ) ;
80
169
} ) ;
81
170
171
+ it ( 'calls getInput() with "downcase-tf-var"' , ( ) => {
172
+ expect ( coreMock . getInput ) . toHaveBeenCalledWith ( "downcase-tf-var" ) ;
173
+ } ) ;
174
+
82
175
it ( "does not calls exportVariable()" , ( ) => {
83
176
expect ( coreMock . exportVariable ) . not . toHaveBeenCalled ( ) ;
84
177
} ) ;
0 commit comments