-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed parsedError string handling (#4266)
* fixed parsedError string handling * Added changelog * Add unit test to devtools Co-authored-by: Álex <[email protected]>
- Loading branch information
1 parent
2f83a43
commit 5979464
Showing
3 changed files
with
99 additions
and
14 deletions.
There are no files selected for viewing
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
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,82 @@ | ||
import { ErrorHandler } from '../../react-services'; | ||
import { DevToolsController } from './dev-tools'; | ||
|
||
// mocked some required kibana-services | ||
jest.mock('../../kibana-services', () => ({ | ||
...(jest.requireActual('../../kibana-services') as object), | ||
getUiSettings: jest.fn().mockReturnValue({ | ||
get: (name) => { | ||
return true; | ||
}, | ||
}), | ||
})); | ||
|
||
// mocked window object | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
hash: { | ||
endsWith: jest.fn(), | ||
includes: jest.fn(), | ||
}, | ||
href: jest.fn(), | ||
assign: jest.fn(), | ||
search: jest.fn().mockResolvedValue({ | ||
tab: 'api', | ||
}), | ||
path: jest.fn(), | ||
}, | ||
writable: true, | ||
}); | ||
// mocked scope dependency | ||
const $scope = { | ||
$applyAsync: jest.fn(), | ||
}; | ||
// mocked getErrorOrchestrator | ||
const mockedGetErrorOrchestrator = { | ||
handleError: jest.fn(), | ||
}; | ||
|
||
jest.mock('../../react-services/common-services', () => { | ||
return { | ||
getErrorOrchestrator: () => mockedGetErrorOrchestrator, | ||
}; | ||
}); | ||
|
||
describe('Devtools Controller', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('Devtools.Send()', () => { | ||
it('Should return string type errors to print in the codemirror textarea output', async () => { | ||
|
||
// Create new instance of the devtools controller | ||
const controller = new DevToolsController($scope, window, ErrorHandler, [window.document]); | ||
|
||
// Define possible error structures to parse | ||
const errorTypes = { | ||
dataObject: { | ||
data: { message: 'Data Object Error' } | ||
}, | ||
invalidObject: { | ||
error: 'Invalid Object Error' | ||
}, | ||
object: { | ||
data: 'Object Error', | ||
status: -1 | ||
}, | ||
string: "String Error", | ||
null: null, | ||
undefined: undefined, | ||
number: 1, | ||
} | ||
|
||
expect(controller.parseError(errorTypes.object)).toEqual('Wazuh API is not reachable. Reason: timeout.'); | ||
expect(controller.parseError(errorTypes.string)).toEqual('String Error'); | ||
expect(controller.parseError(errorTypes.dataObject)).toEqual(errorTypes.dataObject.data.message); | ||
expect(controller.parseError(errorTypes.invalidObject)).toEqual(JSON.stringify(errorTypes.invalidObject)); | ||
|
||
}) | ||
}) | ||
|
||
}); |
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