@@ -88,6 +88,7 @@ describe(`${action.constructor.name} unit tests`, () => {
8888 state_url : "https://looker.state.url.com/action_hub_state/asdfasdfasdfasdf" ,
8989 state_json : JSON . stringify ( { tokens : "code" , redirect : "url" } ) ,
9090 }
91+ request . webhookId = "webhookId"
9192 const stubClient = sinon . stub ( action as any , "driveClientFromRequest" )
9293 . resolves ( {
9394 files : {
@@ -98,11 +99,79 @@ describe(`${action.constructor.name} unit tests`, () => {
9899 chai . expect ( resp ) . to . eventually . deep . equal ( {
99100 success : false ,
100101 message : undefined ,
101- // state: {data: "reset"},
102102 refreshQuery : false ,
103103 validationErrors : [ ] ,
104+ error : {
105+ documentation_url : "TODO" ,
106+ http_code : 500 ,
107+ location : "ActionContainer" ,
108+ message : "Internal server error. Error while sending data undefined" ,
109+ status_code : "INTERNAL" ,
110+ } ,
111+ webhookId : "webhookId" ,
112+ } ) . and . notify ( stubClient . restore ) . and . notify ( done )
113+ } )
114+
115+ it ( "sets state to reset if error in create contains code and reason" , ( done ) => {
116+ const request = new Hub . ActionRequest ( )
117+ const dataBuffer = Buffer . from ( "Hello" )
118+ request . type = Hub . ActionType . Query
119+ request . attachment = { dataBuffer, fileExtension : "csv" }
120+ request . formParams = { filename : stubFileName , folder : stubFolder }
121+ request . params = {
122+ state_url : "https://looker.state.url.com/action_hub_state/asdfasdfasdfasdf" ,
123+ state_json : JSON . stringify ( { tokens : "code" , redirect : "url" } ) ,
124+ }
125+ request . webhookId = "webhookId"
126+ const stubClient = sinon . stub ( action as any , "driveClientFromRequest" )
127+ . resolves ( {
128+ files : {
129+ create : async ( ) => Promise . reject ( {
130+ code : 1234 ,
131+ errors : [
132+ {
133+ message : "testReason" ,
134+ } ,
135+ ] ,
136+ } ) ,
137+ } ,
138+ } )
139+ const resp = action . validateAndExecute ( request )
140+ chai . expect ( resp ) . to . eventually . deep . equal ( {
141+ success : false ,
142+ message : undefined ,
143+ refreshQuery : false ,
144+ validationErrors : [ ] ,
145+ error : {
146+ documentation_url : "TODO" ,
147+ http_code : 1234 ,
148+ location : "ActionContainer" ,
149+ message : "Internal server error. testReason" ,
150+ status_code : "INTERNAL" ,
151+ } ,
152+ webhookId : "webhookId" ,
104153 } ) . and . notify ( stubClient . restore ) . and . notify ( done )
105154 } )
155+
156+ it ( "filename missing in request" , ( ) => {
157+ const request = new TestActionRequest ( )
158+ request . webhookId = "webhookId"
159+ const resp = action . validateAndExecute ( request )
160+ chai . expect ( resp ) . to . eventually
161+ . deep . equal ( {
162+ message : "Server cannot process request due to client request error. Error creating filename from request" ,
163+ refreshQuery : false ,
164+ success : false ,
165+ error : {
166+ http_code : 400 ,
167+ status_code : "BAD_REQUEST" ,
168+ message : "Server cannot process request due to client request error. Error creating filename from request" ,
169+ location : "ActionContainer" ,
170+ documentation_url : "TODO" ,
171+ } ,
172+ webhookId : "webhookId" ,
173+ } )
174+ } )
106175 } )
107176
108177 describe ( "form" , ( ) => {
@@ -371,3 +440,9 @@ describe(`${action.constructor.name} unit tests`, () => {
371440 } )
372441 } )
373442} )
443+
444+ class TestActionRequest extends Hub . ActionRequest {
445+ suggestedFileName ( ) {
446+ return null
447+ }
448+ }
0 commit comments