23
23
SOFTWARE.
24
24
25
25
*/
26
+
26
27
import type { RunItInput } from '../RunIt'
27
28
import { testJsonResponse , api } from '../test-data'
28
29
import { defaultConfigurator , StandaloneConfigurator } from '../components'
@@ -32,6 +33,7 @@ import {
32
33
runRequest ,
33
34
createInputs ,
34
35
initRequestContent ,
36
+ fullRequestUrl ,
35
37
} from './requestUtils'
36
38
import { initRunItSdk } from './RunItSDK'
37
39
@@ -43,12 +45,12 @@ describe('requestUtils', () => {
43
45
} )
44
46
45
47
describe ( 'pathify' , ( ) => {
46
- test ( 'it returns unchanged path if no path params are specified', ( ) => {
48
+ it ( ' returns unchanged path if no path params are specified', ( ) => {
47
49
const actual = pathify ( '/logout' )
48
50
expect ( actual ) . toEqual ( '/logout' )
49
51
} )
50
52
51
- test ( 'it works path params', ( ) => {
53
+ it ( ' works path params', ( ) => {
52
54
const pathParams = {
53
55
query_id : 1 ,
54
56
result_format : 'json' ,
@@ -61,6 +63,45 @@ describe('requestUtils', () => {
61
63
} )
62
64
} )
63
65
66
+ describe ( 'fullRequestUrl' , ( ) => {
67
+ it ( 'has full path' , ( ) => {
68
+ const path = '/queries/{query_id}/run/{result_format}'
69
+ const pathParams = {
70
+ query_id : 1 ,
71
+ result_format : 'json' ,
72
+ }
73
+ const actual = fullRequestUrl (
74
+ sdk . authSession . transport . options . base_url ,
75
+ path ,
76
+ pathParams
77
+ )
78
+ expect ( actual ) . toEqual (
79
+ 'https://self-signed.looker.com:19999/api/4.0/queries/1/run/json'
80
+ )
81
+ } )
82
+
83
+ it ( 'has escaped query params' , ( ) => {
84
+ const path = '/dashboards/{dashboard_id}/search'
85
+ const pathParams = {
86
+ dashboard_id : 1 ,
87
+ }
88
+ const queryParams = {
89
+ title : 'SDK%' ,
90
+ description : '%dashboard&' ,
91
+ limit : 4 ,
92
+ offset : 10 ,
93
+ }
94
+ const actual = fullRequestUrl (
95
+ sdk . authSession . transport . options . base_url ,
96
+ path ,
97
+ pathParams ,
98
+ queryParams
99
+ )
100
+ expect ( actual ) . toEqual (
101
+ 'https://self-signed.looker.com:19999/api/4.0/dashboards/1/search?title=SDK%25&description=%25dashboard%26&limit=4&offset=10'
102
+ )
103
+ } )
104
+ } )
64
105
describe ( 'createRequestParams' , ( ) => {
65
106
const inputs : RunItInput [ ] = [
66
107
{
@@ -107,7 +148,7 @@ describe('requestUtils', () => {
107
148
body : '{}' ,
108
149
}
109
150
110
- test ( 'empty json body is not removed ', ( ) => {
151
+ it ( 'does not remove empty json body ', ( ) => {
111
152
const [ pathParams , queryParams , body ] = createRequestParams (
112
153
inputs ,
113
154
noBody
@@ -121,7 +162,7 @@ describe('requestUtils', () => {
121
162
expect ( body ) . toEqual ( { } )
122
163
} )
123
164
124
- test ( 'it correctly identifies requestContent params location', ( ) => {
165
+ it ( ' correctly identifies requestContent params location', ( ) => {
125
166
const [ pathParams , queryParams , body ] = createRequestParams (
126
167
inputs ,
127
168
requestContent
@@ -135,7 +176,7 @@ describe('requestUtils', () => {
135
176
expect ( body ) . toEqual ( JSON . parse ( requestContent . body ) )
136
177
} )
137
178
138
- test ( ' non JSON parsable strings are treated as x-www-form-urlencoded strings', ( ) => {
179
+ it ( 'treats non JSON parsable strings as x-www-form-urlencoded strings', ( ) => {
139
180
const urlParams = 'key1=value1&key2=value2'
140
181
const [ , , body ] = createRequestParams (
141
182
[
@@ -156,15 +197,14 @@ describe('requestUtils', () => {
156
197
} )
157
198
158
199
describe ( 'defaultRunItCallback' , ( ) => {
159
- test ( 'it makes a request', async ( ) => {
200
+ it ( ' makes a request', async ( ) => {
160
201
const spy = jest
161
202
. spyOn ( sdk . authSession . transport , 'rawRequest' )
162
203
. mockResolvedValueOnce ( testJsonResponse )
163
204
jest . spyOn ( sdk . authSession , 'isAuthenticated' ) . mockReturnValue ( true )
164
205
165
206
const resp = await runRequest (
166
207
sdk ,
167
- '/api/3.1' ,
168
208
'POST' ,
169
209
'/queries/run/{result_format}' ,
170
210
{ result_format : 'json' } ,
@@ -174,7 +214,7 @@ describe('requestUtils', () => {
174
214
175
215
expect ( spy ) . toHaveBeenCalledWith (
176
216
'POST' ,
177
- '/ api/3.1 /queries/run/json' ,
217
+ 'https://self-signed.looker.com:19999/ api/4.0 /queries/run/json' ,
178
218
{
179
219
fields : 'first_name, last_name' ,
180
220
} ,
@@ -190,7 +230,7 @@ describe('requestUtils', () => {
190
230
} )
191
231
192
232
describe ( 'createInputs' , ( ) => {
193
- test ( 'converts delimarray to string' , ( ) => {
233
+ it ( 'converts delimarray to string' , ( ) => {
194
234
const method = api . methods . all_users
195
235
const actual = createInputs ( api , method )
196
236
expect ( actual ) . toHaveLength ( method . allParams . length )
@@ -203,7 +243,7 @@ describe('requestUtils', () => {
203
243
} )
204
244
} )
205
245
206
- test ( 'converts enums in body to string' , ( ) => {
246
+ it ( 'converts enums in body to string' , ( ) => {
207
247
const method = api . methods . create_query_task
208
248
const actual = createInputs ( api , method )
209
249
expect ( actual ) . toHaveLength ( method . allParams . length )
@@ -223,7 +263,7 @@ describe('requestUtils', () => {
223
263
} )
224
264
} )
225
265
226
- test ( 'works with various param types' , ( ) => {
266
+ it ( 'works with various param types' , ( ) => {
227
267
const method = api . methods . run_inline_query
228
268
const actual = createInputs ( api , method )
229
269
expect ( actual ) . toHaveLength ( method . allParams . length )
@@ -288,7 +328,7 @@ describe('requestUtils', () => {
288
328
} )
289
329
290
330
describe ( 'request content initialization' , ( ) => {
291
- test ( 'it initialzies body params with default values' , ( ) => {
331
+ it ( 'it initialzies body params with default values' , ( ) => {
292
332
const inputs = createInputs ( api , api . methods . run_inline_query )
293
333
const actual = initRequestContent ( defaultConfigurator , inputs , { } )
294
334
expect ( actual ) . toEqual ( {
@@ -317,7 +357,7 @@ describe('requestUtils', () => {
317
357
} )
318
358
} )
319
359
320
- test ( 'it contains default-empty body params' , ( ) => {
360
+ it ( 'it contains default-empty body params' , ( ) => {
321
361
const inputs = createInputs ( api , api . methods . fetch_integration_form )
322
362
const bodyInput = inputs . find ( ( i ) => i . location === 'body' ) !
323
363
expect ( bodyInput . name ) . toEqual ( 'body' )
@@ -332,7 +372,7 @@ describe('requestUtils', () => {
332
372
describe ( 'createRequestParams' , ( ) => {
333
373
const inputs = createInputs ( api , api . methods . run_inline_query )
334
374
335
- test ( 'removes empties for path, query and body params' , ( ) => {
375
+ it ( 'removes empties for path, query and body params' , ( ) => {
336
376
const requestContent = initRequestContent ( defaultConfigurator , inputs )
337
377
const [ pathParams , queryParams , body ] = createRequestParams (
338
378
inputs ,
@@ -346,7 +386,7 @@ describe('requestUtils', () => {
346
386
} )
347
387
} )
348
388
349
- test ( 'does mot remove empty bodies' , ( ) => {
389
+ it ( 'does mot remove empty bodies' , ( ) => {
350
390
const requestContent = { body : { } }
351
391
const [ pathParams , queryParams , body ] = createRequestParams (
352
392
inputs ,
0 commit comments