-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vulnerability dashboard error loading for read only user (#6993)
* Refactor useDataSource hook for improved error handling * Add comment for vulnerability dashboard error handling * Refactor data source hook and remove unused TimeRange * Fix issue causing vulnerability dashboard load failure for read-only users * Fix Prettier issues * Add tests for PatternDataSource class and RecordMock types * Fix syntax error in PatternDataSource file * Fix Prettier issues * Prettier --------- Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com>
- Loading branch information
1 parent
d7ee5e8
commit 952bf49
Showing
5 changed files
with
121 additions
and
54 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
47 changes: 47 additions & 0 deletions
47
plugins/main/public/components/common/data-source/pattern/pattern-data-source.test.ts
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,47 @@ | ||
import { IndexPatternsService } from '../../../../../../../src/plugins/data/common'; | ||
import { RecordMock } from '../../../../../test/types'; | ||
import { PatternDataSource } from './pattern-data-source'; | ||
|
||
let patternService: RecordMock<IndexPatternsService>; | ||
let patternDataSource: PatternDataSource; | ||
const TEST_ID = 'test-id'; | ||
const TEST_TITLE = 'test-title'; | ||
|
||
describe('PatternDataSource', () => { | ||
beforeEach(() => { | ||
patternDataSource = new PatternDataSource(TEST_ID, TEST_TITLE); | ||
// @ts-expect-error | ||
patternService = { | ||
get: jest.fn().mockImplementation(() => ({ | ||
getScriptedFields: jest.fn().mockImplementation(() => []), | ||
fields: { | ||
replaceAll: jest.fn(), | ||
}, | ||
})), | ||
getFieldsForIndexPattern: jest.fn().mockResolvedValue([]), | ||
updateSavedObject: jest.fn(), | ||
}; | ||
// @ts-expect-error | ||
patternDataSource.patternService = patternService; | ||
}); | ||
|
||
it('should throw error when pattern not found', () => { | ||
patternService.get.mockResolvedValue(undefined); | ||
expect(async () => { | ||
await patternDataSource.select(); | ||
}).rejects.toThrow( | ||
'Error selecting index pattern: Error: Error selecting index pattern: pattern not found', | ||
); | ||
}); | ||
|
||
it('should throw error when get fields for index pattern rejects', () => { | ||
patternService.getFieldsForIndexPattern.mockRejectedValue(null); | ||
expect(async () => { | ||
await patternDataSource.select(); | ||
}).rejects.toThrow('Error selecting index pattern: null'); | ||
}); | ||
|
||
it('should not throw error when selecting from pattern data source', async () => { | ||
await expect(patternDataSource.select()).resolves.not.toThrow(); | ||
}); | ||
}); |
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,14 @@ | ||
export type RecordMock<T> = { | ||
[K in keyof T]: T[K] extends Function | ||
? jest.Mock | ||
: T[K] extends {} | ||
? RecordMock<T[K]> | ||
: T[K]; | ||
}; | ||
export type PartialRecordMock<T> = Partial<{ | ||
[K in keyof T]: T[K] extends Function | ||
? jest.Mock | ||
: T[K] extends {} | ||
? PartialRecordMock<T[K]> | ||
: T[K]; | ||
}>; |