Skip to content

Commit efef5e6

Browse files
committed
begin rework
1 parent 7753063 commit efef5e6

File tree

6 files changed

+82
-31
lines changed

6 files changed

+82
-31
lines changed

packages/run-it/src/RunIt.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('RunIt', () => {
6868
jest.clearAllMocks()
6969
})
7070

71-
test('it renders endpoint, request and response tabs, and form inputs', () => {
71+
it('it renders endpoint, request and response tabs, and form inputs', () => {
7272
renderRunIt()
7373
// TODO fix this
7474
// expect(screen.getByRole('heading')).toHaveTextContent(
@@ -93,7 +93,7 @@ describe('RunIt', () => {
9393
).not.toBeInTheDocument()
9494
})
9595

96-
test('the form submit handler invokes the request callback on submit', async () => {
96+
it('the form submit handler invokes the request callback on submit', async () => {
9797
renderRunIt(api, api.methods.me)
9898
const defaultRequestCallback = jest
9999
.spyOn(sdk.authSession.transport, 'rawRequest')
@@ -108,13 +108,13 @@ describe('RunIt', () => {
108108
).toBeInTheDocument()
109109
expect(
110110
screen.getByRole('heading', {
111-
name: 'GET https://self-signed.looker.com:19999/user',
111+
name: 'GET https://self-signed.looker.com:19999/api/4.0/user',
112112
})
113113
).toBeInTheDocument()
114114
})
115115
})
116116

117-
test('run_inline_query has required body parameters', async () => {
117+
it('run_inline_query has required body parameters', async () => {
118118
renderRunIt()
119119
const defaultRequestCallback = jest
120120
.spyOn(sdk.authSession.transport, 'rawRequest')
@@ -140,7 +140,7 @@ describe('RunIt', () => {
140140
})
141141
})
142142

143-
test('it has Configure button', () => {
143+
it('it has Configure button', () => {
144144
renderRunIt()
145145
expect(
146146
screen.getByRole('button', { name: 'Configure' })
@@ -163,7 +163,7 @@ describe('RunIt', () => {
163163
})
164164
})
165165

166-
test('it has Login button', () => {
166+
it('it has Login button', () => {
167167
renderRunIt()
168168
expect(screen.getByRole('button', { name: 'Login' })).toBeInTheDocument()
169169
expect(

packages/run-it/src/RunIt.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ interface RunItProps {
108108
sdkLanguage?: string
109109
}
110110

111+
// interface SpecParams {
112+
// specKey: string
113+
// }
114+
111115
/**
112116
* Given an array of inputs, a method, and an api model it renders a REST request form
113117
* which on submit performs a REST request and renders the response with the appropriate MIME type handler
@@ -118,6 +122,7 @@ export const RunIt: FC<RunItProps> = ({
118122
setVersionsUrl = runItNoSet,
119123
sdkLanguage = 'All',
120124
}) => {
125+
// const { specKey } = useParams<SpecParams>()
121126
const httpMethod = method.httpMethod as RunItHttpMethod
122127
const endpoint = method.endpoint
123128
const { sdk, configurator } = useContext(RunItContext)
@@ -206,6 +211,9 @@ export const RunIt: FC<RunItProps> = ({
206211

207212
// No SDK, no RunIt for you!
208213
if (!sdk) return <></>
214+
const baseUrl = isExtension
215+
? 'need extension callback' // `${getExtensionSDK().lookerHostData?.hostUrl}/api/${specKey}`
216+
: sdk.authSession.transport.options.base_url
209217

210218
return (
211219
<Box bg="background" py="large" height="100%">
@@ -240,7 +248,7 @@ export const RunIt: FC<RunItProps> = ({
240248
<Loading
241249
loading={loading}
242250
message={`${httpMethod} ${fullRequestUrl(
243-
sdk.authSession.transport,
251+
baseUrl,
244252
endpoint,
245253
activeParams.path,
246254
activeParams.query
@@ -250,7 +258,7 @@ export const RunIt: FC<RunItProps> = ({
250258
response={responseContent}
251259
verb={httpMethod}
252260
path={fullRequestUrl(
253-
sdk.authSession.transport,
261+
baseUrl,
254262
endpoint,
255263
activeParams.path,
256264
activeParams.query

packages/run-it/src/utils/RunItSDK.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { RunItConfigKey } from '../components'
3838
// https://docs.looker.com/reference/api-and-integration/api-cors
3939
const settings = {
4040
...DefaultSettings(),
41-
base_url: 'https://self-signed.looker.com:19999',
41+
base_url: 'https://self-signed.looker.com:19999/api/4.0',
4242
agentTag: 'RunIt 0.8',
4343
} as IApiSettings
4444

packages/run-it/src/utils/requestUtils.spec.ts

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
SOFTWARE.
2424
2525
*/
26+
2627
import type { RunItInput } from '../RunIt'
2728
import { testJsonResponse, api } from '../test-data'
2829
import { defaultConfigurator, StandaloneConfigurator } from '../components'
@@ -32,6 +33,7 @@ import {
3233
runRequest,
3334
createInputs,
3435
initRequestContent,
36+
fullRequestUrl,
3537
} from './requestUtils'
3638
import { initRunItSdk } from './RunItSDK'
3739

@@ -43,12 +45,12 @@ describe('requestUtils', () => {
4345
})
4446

4547
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', () => {
4749
const actual = pathify('/logout')
4850
expect(actual).toEqual('/logout')
4951
})
5052

51-
test('it works path params', () => {
53+
it('works path params', () => {
5254
const pathParams = {
5355
query_id: 1,
5456
result_format: 'json',
@@ -61,6 +63,45 @@ describe('requestUtils', () => {
6163
})
6264
})
6365

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+
})
64105
describe('createRequestParams', () => {
65106
const inputs: RunItInput[] = [
66107
{
@@ -107,7 +148,7 @@ describe('requestUtils', () => {
107148
body: '{}',
108149
}
109150

110-
test('empty json body is not removed', () => {
151+
it('does not remove empty json body', () => {
111152
const [pathParams, queryParams, body] = createRequestParams(
112153
inputs,
113154
noBody
@@ -121,7 +162,7 @@ describe('requestUtils', () => {
121162
expect(body).toEqual({})
122163
})
123164

124-
test('it correctly identifies requestContent params location', () => {
165+
it('correctly identifies requestContent params location', () => {
125166
const [pathParams, queryParams, body] = createRequestParams(
126167
inputs,
127168
requestContent
@@ -135,7 +176,7 @@ describe('requestUtils', () => {
135176
expect(body).toEqual(JSON.parse(requestContent.body))
136177
})
137178

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', () => {
139180
const urlParams = 'key1=value1&key2=value2'
140181
const [, , body] = createRequestParams(
141182
[
@@ -156,15 +197,14 @@ describe('requestUtils', () => {
156197
})
157198

158199
describe('defaultRunItCallback', () => {
159-
test('it makes a request', async () => {
200+
it('makes a request', async () => {
160201
const spy = jest
161202
.spyOn(sdk.authSession.transport, 'rawRequest')
162203
.mockResolvedValueOnce(testJsonResponse)
163204
jest.spyOn(sdk.authSession, 'isAuthenticated').mockReturnValue(true)
164205

165206
const resp = await runRequest(
166207
sdk,
167-
'/api/3.1',
168208
'POST',
169209
'/queries/run/{result_format}',
170210
{ result_format: 'json' },
@@ -174,7 +214,7 @@ describe('requestUtils', () => {
174214

175215
expect(spy).toHaveBeenCalledWith(
176216
'POST',
177-
'/api/3.1/queries/run/json',
217+
'https://self-signed.looker.com:19999/api/4.0/queries/run/json',
178218
{
179219
fields: 'first_name, last_name',
180220
},
@@ -190,7 +230,7 @@ describe('requestUtils', () => {
190230
})
191231

192232
describe('createInputs', () => {
193-
test('converts delimarray to string', () => {
233+
it('converts delimarray to string', () => {
194234
const method = api.methods.all_users
195235
const actual = createInputs(api, method)
196236
expect(actual).toHaveLength(method.allParams.length)
@@ -203,7 +243,7 @@ describe('requestUtils', () => {
203243
})
204244
})
205245

206-
test('converts enums in body to string', () => {
246+
it('converts enums in body to string', () => {
207247
const method = api.methods.create_query_task
208248
const actual = createInputs(api, method)
209249
expect(actual).toHaveLength(method.allParams.length)
@@ -223,7 +263,7 @@ describe('requestUtils', () => {
223263
})
224264
})
225265

226-
test('works with various param types', () => {
266+
it('works with various param types', () => {
227267
const method = api.methods.run_inline_query
228268
const actual = createInputs(api, method)
229269
expect(actual).toHaveLength(method.allParams.length)
@@ -288,7 +328,7 @@ describe('requestUtils', () => {
288328
})
289329

290330
describe('request content initialization', () => {
291-
test('it initialzies body params with default values', () => {
331+
it('it initialzies body params with default values', () => {
292332
const inputs = createInputs(api, api.methods.run_inline_query)
293333
const actual = initRequestContent(defaultConfigurator, inputs, {})
294334
expect(actual).toEqual({
@@ -317,7 +357,7 @@ describe('requestUtils', () => {
317357
})
318358
})
319359

320-
test('it contains default-empty body params', () => {
360+
it('it contains default-empty body params', () => {
321361
const inputs = createInputs(api, api.methods.fetch_integration_form)
322362
const bodyInput = inputs.find((i) => i.location === 'body')!
323363
expect(bodyInput.name).toEqual('body')
@@ -332,7 +372,7 @@ describe('requestUtils', () => {
332372
describe('createRequestParams', () => {
333373
const inputs = createInputs(api, api.methods.run_inline_query)
334374

335-
test('removes empties for path, query and body params', () => {
375+
it('removes empties for path, query and body params', () => {
336376
const requestContent = initRequestContent(defaultConfigurator, inputs)
337377
const [pathParams, queryParams, body] = createRequestParams(
338378
inputs,
@@ -346,7 +386,7 @@ describe('requestUtils', () => {
346386
})
347387
})
348388

349-
test('does mot remove empty bodies', () => {
389+
it('does mot remove empty bodies', () => {
350390
const requestContent = { body: {} }
351391
const [pathParams, queryParams, body] = createRequestParams(
352392
inputs,

packages/run-it/src/utils/requestUtils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
*/
2626

27-
import type { ITransport, IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
27+
import type { IAPIMethods, IRawResponse } from '@looker/sdk-rtl'
2828
import cloneDeep from 'lodash/cloneDeep'
2929
import { isEmpty } from 'lodash'
3030
import type { IApiModel, IMethod, IType } from '@looker/sdk-codegen'
@@ -174,21 +174,20 @@ export const createRequestParams = (
174174

175175
/**
176176
* Construct the full request URL
177-
* @param transport to get server's host url
177+
* @param baseUrl full path to the API server version
178178
* @param path to REST server
179179
* @param pathParams path parameters
180180
* @param queryParams collection
181181
*/
182182
export const fullRequestUrl = (
183-
transport: ITransport,
183+
baseUrl: string,
184184
path: string,
185185
pathParams: RunItValues,
186186
queryParams?: RunItValues
187187
) => {
188-
const base = transport.options.base_url
189188
path = pathify(path, pathParams)
190189
if (!path.match(/^(http:\/\/|https:\/\/)/gi)) {
191-
path = `${base}${path}` // path was relative
190+
path = `${baseUrl}${path}` // path was relative
192191
}
193192
path = addQueryParams(path, queryParams)
194193
return path
@@ -214,7 +213,11 @@ export const runRequest = async (
214213
if (!sdk.authSession.isAuthenticated()) {
215214
await sdk.ok(sdk.authSession.login())
216215
}
217-
const url = fullRequestUrl(sdk.authSession.transport, endpoint, pathParams)
216+
const url = fullRequestUrl(
217+
sdk.authSession.transport.options.base_url,
218+
endpoint,
219+
pathParams
220+
)
218221
const raw = await sdk.authSession.transport.rawRequest(
219222
httpMethod,
220223
url,

packages/sdk-rtl/src/extensionTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export class ExtensionTransport implements ITransport {
7171
readonly options: ITransportSettings,
7272
private hostConnection: IHostConnection
7373
) {
74-
this.options = options
7574
this.hostConnection = hostConnection
75+
this.options = options
7676
}
7777

7878
observer: RawObserver | undefined

0 commit comments

Comments
 (0)