1
1
import AWS from 'aws-sdk/global' ;
2
2
import { main , Props , Credentials , ExtraOptions } from '../src' ;
3
- import { setFailed , getInput , setOutput } from '../__mocks__/@actions/core' ;
3
+ import { setFailed , getInput , setOutput , setSecret } from '../__mocks__/@actions/core' ;
4
4
import Lambda , { constructorMock } from '../__mocks__/aws-sdk/clients/lambda' ;
5
5
6
6
describe ( 'invoke-aws-lambda' , ( ) => {
@@ -29,6 +29,7 @@ describe('invoke-aws-lambda', () => {
29
29
getInput . mockClear ( ) ;
30
30
setFailed . mockClear ( ) ;
31
31
setOutput . mockClear ( ) ;
32
+ setSecret . mockClear ( ) ;
32
33
} ) ;
33
34
34
35
it ( 'runs when provided the correct input' , async ( ) => {
@@ -39,6 +40,7 @@ describe('invoke-aws-lambda', () => {
39
40
await main ( ) ;
40
41
expect ( getInput ) . toHaveBeenCalledTimes ( 13 ) ;
41
42
expect ( setFailed ) . not . toHaveBeenCalled ( ) ;
43
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 2 ) ;
42
44
expect ( AWS . config . httpOptions ) . toMatchInlineSnapshot ( `
43
45
Object {
44
46
"timeout": 220000,
@@ -95,6 +97,7 @@ describe('invoke-aws-lambda', () => {
95
97
` ) ;
96
98
expect ( setFailed ) . toHaveBeenCalled ( ) ;
97
99
expect ( setOutput ) . not . toHaveBeenCalled ( ) ;
100
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 2 ) ;
98
101
} ) ;
99
102
100
103
describe ( 'when the function returns an error' , ( ) => {
@@ -122,6 +125,7 @@ describe('invoke-aws-lambda', () => {
122
125
123
126
expect ( setOutput ) . toHaveBeenCalled ( ) ;
124
127
expect ( setFailed ) . toHaveBeenCalled ( ) ;
128
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 2 ) ;
125
129
} ) ;
126
130
127
131
it ( 'should fail the action when SUCCEED_ON_FUNCTION_FAILURE is false' , async ( ) => {
@@ -140,6 +144,7 @@ describe('invoke-aws-lambda', () => {
140
144
141
145
expect ( setOutput ) . toHaveBeenCalled ( ) ;
142
146
expect ( setFailed ) . toHaveBeenCalled ( ) ;
147
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 2 ) ;
143
148
} ) ;
144
149
145
150
it ( 'should succeed the action when SUCCEED_ON_FUNCTION_FAILURE is true' , async ( ) => {
@@ -158,6 +163,30 @@ describe('invoke-aws-lambda', () => {
158
163
159
164
expect ( setOutput ) . toHaveBeenCalled ( ) ;
160
165
expect ( setFailed ) . not . toHaveBeenCalled ( ) ;
166
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 2 ) ;
167
+ } ) ;
168
+
169
+ it ( "should call setSecret on AWS_SESSION_TOKEN when it's provided" , async ( ) => {
170
+ const overriddenMockedInput = {
171
+ ...mockedInput ,
172
+ [ Credentials . AWS_SESSION_TOKEN ] : 'someSessionToken' ,
173
+ } ;
174
+
175
+ getInput . mockImplementation (
176
+ ( key : Partial < Props & Credentials & 'REGION' > ) => {
177
+ return overriddenMockedInput [ key ] ;
178
+ }
179
+ ) ;
180
+
181
+ const handler = jest . fn ( ( ) => ( { response : 'ok' } ) ) ;
182
+
183
+ Lambda . __setResponseForMethods ( { invoke : handler } ) ;
184
+
185
+ await main ( ) ;
186
+
187
+ expect ( getInput ) . toHaveBeenCalledTimes ( 13 ) ;
188
+ expect ( setFailed ) . not . toHaveBeenCalled ( ) ;
189
+ expect ( setSecret ) . toHaveBeenCalledTimes ( 3 ) ;
161
190
} ) ;
162
191
} ) ;
163
192
} ) ;
0 commit comments