Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validateBody for API Explorer #846

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ describe('Complex Item', () => {
describe('validateBody', () => {
test.each`
value | error
${{
model: 'thelook',
view: 'users',
fields: ['users.id', 'users.first_name'],
}} | ${''}
${'na.-_me=Vapor&age=3&luckyNumbers[]=5&luckyNumbers[]=7'} | ${''}
${'name=Vapor&age=3&luckyNumbers[]=5&luckyNumbers[]7'} | ${'luckyNumbers[]7'}
${'{'} | ${'Unexpected end of JSON input'}
Expand Down
4 changes: 2 additions & 2 deletions packages/run-it/src/components/RequestForm/formUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ export const validateEncodedValues = (body: string) => {
*
* @param body string to validate
*/
export const validateBody = (body: string) => {
export const validateBody = (body: string | Record<string, any>) => {
let result = ''
if (body) {
if (body && typeof body === 'string') {
if (/^[[{}"]/.test(body)) {
// most likely JSON
try {
Expand Down
40 changes: 40 additions & 0 deletions packages/sdk-node/test/methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,46 @@ describe('LookerNodeSDK', () => {
},
testTimeout
)

it(
'parses a query with no results',
async () => {
const sdk = new LookerSDK(session)
const query = await sdk.ok(
sdk.create_query({
model: 'system__activity',
view: 'dashboard',
limit: '2',
fields: ['dashboard.id', 'dashboard.title'],
filters: { 'dashboard.id': '-1' },
})
)
expect(query).toBeDefined()
expect(query.id).toBeDefined()
for (const format of ['csv', 'json', 'json_detail', 'txt', 'md']) {
let failed = ''
try {
const live = await sdk.ok(
sdk.run_query({ query_id: query.id!, result_format: format })
)
const cached = await sdk.ok(
sdk.run_query({
query_id: query.id!,
result_format: format,
cache: true,
})
)
expect(live).not.toEqual('{}')
expect(cached).not.toEqual('{}')
} catch (e: any) {
failed = e.message
}
expect(failed).toEqual('')
}
await sdk.authSession.logout()
},
testTimeout
)
})

describe('Dashboard endpoints', () => {
Expand Down