@@ -14,59 +14,74 @@ import { InvocationResponse } from '@aws-sdk/client-lambda'
1414
1515describe ( 'RemoteInvokeWebview' , function ( ) {
1616 let client : SinonStubbedInstance < LambdaClient >
17- let remoteInvokeWebview : RemoteInvokeWebview
1817 let outputChannel : vscode . OutputChannel
19- let mockData : any
20- before ( async ( ) => {
21- client = createStubInstance ( DefaultLambdaClient )
18+ const mockData = {
19+ FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:my-function' ,
20+ } as any
21+ const mockDataLMI = {
22+ FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:my-function' ,
23+ LambdaFunctionNode : {
24+ configuration : {
25+ CapacityProviderConfig : {
26+ blah : 'blah' ,
27+ } ,
28+ } ,
29+ } ,
30+ } as any
31+ const input = '{"key": "value"}'
32+ const mockResponse = {
33+ LogResult : Buffer . from ( 'Test log' ) . toString ( 'base64' ) ,
34+ Payload : new TextEncoder ( ) . encode ( '{"result": "success"}' ) ,
35+ } satisfies InvocationResponse
36+
37+ before ( ( ) => {
2238 outputChannel = {
2339 appendLine : ( line : string ) => { } ,
2440 show : ( ) => { } ,
2541 } as vscode . OutputChannel
26- mockData = {
27- FunctionArn : 'arn:aws:lambda:us-west-2:123456789012:function:my-function' ,
28- }
29- remoteInvokeWebview = new RemoteInvokeWebview ( outputChannel , client , client , mockData )
3042 } )
31- describe ( 'Invoke Remote Lambda Function with Payload' , ( ) => {
32- it ( 'should invoke with a simple payload' , async function ( ) {
33- const input = '{"key": "value"}'
34- const mockResponse = {
35- LogResult : Buffer . from ( 'Test log' ) . toString ( 'base64' ) ,
36- Payload : new TextEncoder ( ) . encode ( '{"result": "success"}' ) ,
37- } satisfies InvocationResponse
38- client . invoke . resolves ( mockResponse )
39- await remoteInvokeWebview . invokeLambda ( input )
40- sinon . assert . calledOnce ( client . invoke )
41- sinon . assert . calledWith ( client . invoke , mockData . FunctionArn , input )
42- } )
43+ beforeEach ( ( ) => {
44+ client = createStubInstance ( DefaultLambdaClient )
45+ } )
46+ afterEach ( ( ) => {
47+ sinon . restore ( )
48+ } )
49+ it ( 'should invoke with a simple payload' , async function ( ) {
50+ const remoteInvokeWebview = new RemoteInvokeWebview ( outputChannel , client , client , mockData )
51+ client . invoke . resolves ( mockResponse )
52+ await remoteInvokeWebview . invokeLambda ( input )
53+ sinon . assert . calledOnce ( client . invoke )
54+ sinon . assert . calledWith ( client . invoke , mockData . FunctionArn , input , undefined , 'Tail' )
4355 } )
44- describe ( 'Invoke Remote Lambda Function with Saved Events Payload' , ( ) => {
45- const mockEvent = {
46- name : 'TestEvent' ,
47- arn : 'arn:aws:lambda:us-west-2:123456789012:function:myFunction' ,
48- region : 'us-west-2' ,
49- }
50- const expectedParams = {
51- name : mockEvent . name ,
52- operation : TestEventsOperation . Get ,
53- functionArn : mockEvent . arn ,
54- region : mockEvent . region ,
55- }
56- const mockResponse = 'true'
57- let runSamCliRemoteTestEventsStub : sinon . SinonStub
58- beforeEach ( ( ) => {
59- runSamCliRemoteTestEventsStub = sinon . stub ( samCliRemoteTestEvent , 'runSamCliRemoteTestEvents' )
60- } )
61- afterEach ( ( ) => {
62- sinon . restore ( )
63- } )
64- it ( 'should get saved event and invoke with it' , async function ( ) {
65- runSamCliRemoteTestEventsStub . resolves ( mockResponse )
66- await remoteInvokeWebview . getRemoteTestEvents ( mockEvent )
6756
68- sinon . assert . calledOnce ( runSamCliRemoteTestEventsStub )
69- sinon . assert . calledWith ( runSamCliRemoteTestEventsStub , expectedParams )
70- } )
57+ it ( 'should invoke with no tail in LMI' , async function ( ) {
58+ const remoteInvokeWebview = new RemoteInvokeWebview ( outputChannel , client , client , mockDataLMI )
59+ client . invoke . resolves ( mockResponse )
60+ await remoteInvokeWebview . invokeLambda ( input )
61+ sinon . assert . calledOnce ( client . invoke )
62+ sinon . assert . calledWith ( client . invoke , mockData . FunctionArn , input , undefined , 'None' )
63+ } )
64+
65+ const mockEvent = {
66+ name : 'TestEvent' ,
67+ arn : 'arn:aws:lambda:us-west-2:123456789012:function:myFunction' ,
68+ region : 'us-west-2' ,
69+ }
70+ const expectedParams = {
71+ name : mockEvent . name ,
72+ operation : TestEventsOperation . Get ,
73+ functionArn : mockEvent . arn ,
74+ region : mockEvent . region ,
75+ }
76+ const mockEventResponse = 'true'
77+
78+ it ( 'should get saved event and invoke with it' , async function ( ) {
79+ const remoteInvokeWebview = new RemoteInvokeWebview ( outputChannel , client , client , mockData )
80+ const runSamCliRemoteTestEventsStub = sinon . stub ( samCliRemoteTestEvent , 'runSamCliRemoteTestEvents' )
81+ runSamCliRemoteTestEventsStub . resolves ( mockEventResponse )
82+ await remoteInvokeWebview . getRemoteTestEvents ( mockEvent )
83+
84+ sinon . assert . calledOnce ( runSamCliRemoteTestEventsStub )
85+ sinon . assert . calledWith ( runSamCliRemoteTestEventsStub , expectedParams )
7186 } )
7287} )
0 commit comments