Skip to content

Commit

Permalink
Merge branch 'main' into jk/runit_2D_data_logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaster authored Oct 4, 2021
2 parents 6ccb3d8 + eb1731f commit dbbf919
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/run-it/src/utils/RunItSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { RunItConfigKey } from '../components'
const settings = {
...DefaultSettings(),
base_url: 'https://self-signed.looker.com:19999',
agentTag: 'RunIt 0.5',
agentTag: 'RunIt 0.8',
} as IApiSettings

/**
Expand Down
20 changes: 20 additions & 0 deletions packages/run-it/src/utils/requestUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ describe('requestUtils', () => {
}),
}

const noBody = {
result_format: 'json',
cache: true,
body: '{}',
}

test('empty json body is removed', () => {
const [pathParams, queryParams, body] = createRequestParams(
inputs,
noBody
)
expect(pathParams).toEqual({
result_format: noBody.result_format,
})
expect(queryParams).toEqual({
cache: noBody.cache,
})
expect(body).not.toBeDefined()
})

test('it correctly identifies requestContent params location', () => {
const [pathParams, queryParams, body] = createRequestParams(
inputs,
Expand Down
10 changes: 9 additions & 1 deletion packages/run-it/src/utils/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ export const prepareInputs = (
const name = input.name
if (input.location === 'body') {
try {
result[name] = JSON.parse(result[name])
const parsed = JSON.parse(result[name])
// Keys call works for both objects and arrays if there are any values
const keys = Object.keys(parsed)
if (keys.length > 0) {
result[name] = parsed
} else {
// Remove body arg
delete result[name]
}
} catch (e) {
/** Treat as x-www-form-urlencoded */
result[name] = requestContent[name]
Expand Down

0 comments on commit dbbf919

Please sign in to comment.