forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Fix debug param issue (elastic#19676)
* [APM] Fix debug param issue * [APM] Fix _debug issue and add test
- Loading branch information
Showing
3 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/apm/public/services/__test__/SessionStorageMock.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export class SessionStorageMock { | ||
store = {}; | ||
|
||
clear() { | ||
this.store = {}; | ||
} | ||
|
||
getItem(key) { | ||
return this.store[key] || null; | ||
} | ||
|
||
setItem(key, value) { | ||
this.store[key] = value.toString(); | ||
} | ||
|
||
removeItem(key) { | ||
delete this.store[key]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as kfetchModule from 'ui/kfetch'; | ||
import { SessionStorageMock } from './SessionStorageMock'; | ||
import { callApi } from '../rest'; | ||
|
||
describe('rest', () => { | ||
let kfetchSpy; | ||
|
||
beforeEach(() => { | ||
kfetchSpy = jest.spyOn(kfetchModule, 'kfetch').mockResolvedValue({ | ||
my_key: 'hello world' | ||
}); | ||
global.sessionStorage = new SessionStorageMock(); | ||
}); | ||
|
||
afterEach(() => { | ||
kfetchSpy.mockClear(); | ||
}); | ||
|
||
describe('callApi', () => { | ||
describe('debug param', () => { | ||
describe('when apm_debug is true', () => { | ||
beforeEach(() => { | ||
sessionStorage.setItem('apm_debug', 'true'); | ||
}); | ||
|
||
it('should add debug param for APM endpoints', async () => { | ||
await callApi({ pathname: `/api/apm/status/server` }); | ||
|
||
expect(kfetchSpy).toHaveBeenCalledWith( | ||
{ pathname: '/api/apm/status/server', query: { _debug: true } }, | ||
{ camelcase: true } | ||
); | ||
}); | ||
|
||
it('should not add debug param for non-APM endpoints', async () => { | ||
await callApi({ pathname: `/api/kibana` }); | ||
|
||
expect(kfetchSpy).toHaveBeenCalledWith( | ||
{ pathname: '/api/kibana' }, | ||
{ camelcase: true } | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('camelcase', () => { | ||
it('camelcase param should be true by default', async () => { | ||
const res = await callApi({ pathname: `/api/kibana` }); | ||
|
||
expect(kfetchSpy).toHaveBeenCalledWith( | ||
{ pathname: '/api/kibana' }, | ||
{ camelcase: true } | ||
); | ||
|
||
expect(res).toEqual({ myKey: 'hello world' }); | ||
}); | ||
|
||
it('should respect settings', async () => { | ||
const res = await callApi( | ||
{ pathname: `/api/kibana` }, | ||
{ camelcase: false } | ||
); | ||
|
||
expect(kfetchSpy).toHaveBeenCalledWith( | ||
{ pathname: '/api/kibana' }, | ||
{ camelcase: false } | ||
); | ||
|
||
expect(res).toEqual({ my_key: 'hello world' }); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters