-
Notifications
You must be signed in to change notification settings - Fork 91
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: error toast message while configuring trigger while creating a monitor #1178
Merged
+245
−24
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02d94ee
fix: error toast message while configuring trigger while creating a m…
vikhy-aws 3f98a83
fix: gracefully handle exceptions related to config index not created
vikhy-aws bed0821
fix: gracefully handle exceptions related to config index not created
vikhy-aws a5b64f1
fix: fix unit test to conform to code changes
vikhy-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,188 @@ | ||
import DestinationsService from "./DestinationsService"; | ||
|
||
describe("Test DestinationsService -- getDestinations", () => { | ||
let destinationsService; | ||
let mockContext; | ||
let mockReq; | ||
let mockRes; | ||
let mockClient; | ||
|
||
beforeEach(() => { | ||
mockClient = jest.fn(); | ||
|
||
amsiglan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mockContext = {}; | ||
|
||
mockRes = { | ||
ok: jest.fn().mockReturnValue({ body: {} }), | ||
}; | ||
|
||
destinationsService = new DestinationsService(); | ||
destinationsService.getClientBasedOnDataSource = jest.fn().mockReturnValue(mockClient); | ||
|
||
}); | ||
|
||
describe("Test getDestinations", () => { | ||
|
||
test("should successfully get destinations list -- name as sort string", async () => { | ||
const mockReq = { | ||
query: { | ||
from: 0, | ||
size: 20, | ||
search: "", | ||
sortDirection: "desc", | ||
sortField: "name", | ||
type: "ALL", | ||
}, | ||
}; | ||
|
||
const mockResponse = { | ||
destinations: [{ | ||
id: "1", | ||
name: "Sample Destination", | ||
schema_version: 1, | ||
seq_no: 1, | ||
primary_term: 1, | ||
}], | ||
totalDestinations: 1, | ||
}; | ||
mockClient.mockResolvedValueOnce(mockResponse); | ||
|
||
await destinationsService.getDestinations(mockContext, mockReq, mockRes); | ||
|
||
expect(mockClient).toHaveBeenCalledWith("alerting.searchDestinations", { | ||
sortString: "destination.name.keyword", | ||
sortOrder: "desc", | ||
startIndex: 0, | ||
size: 20, | ||
searchString: "", | ||
destinationType: "ALL", | ||
}); | ||
expect(mockRes.ok).toHaveBeenCalledWith({ | ||
body: { | ||
ok: true, | ||
destinations: [{ | ||
id: "1", | ||
name: "Sample Destination", | ||
schema_version: 1, | ||
seq_no: 1, | ||
primary_term: 1, | ||
version: 1, | ||
ifSeqNo: 1, | ||
ifPrimaryTerm: 1, | ||
}], | ||
totalDestinations: 1, | ||
}, | ||
}); | ||
}); | ||
|
||
test("should successfully get destinations list -- type as sort string", async () => { | ||
const mockReq = { | ||
query: { | ||
from: 0, | ||
size: 20, | ||
search: "", | ||
sortDirection: "desc", | ||
sortField: "type", | ||
type: "ALL", | ||
}, | ||
}; | ||
|
||
const mockResponse = { | ||
destinations: [{ | ||
id: "1", | ||
name: "Sample Destination", | ||
schema_version: 1, | ||
seq_no: 1, | ||
primary_term: 1, | ||
}], | ||
totalDestinations: 1, | ||
}; | ||
mockClient.mockResolvedValueOnce(mockResponse); | ||
|
||
await destinationsService.getDestinations(mockContext, mockReq, mockRes); | ||
|
||
expect(mockClient).toHaveBeenCalledWith("alerting.searchDestinations", { | ||
sortString: "destination.type", | ||
sortOrder: "desc", | ||
startIndex: 0, | ||
size: 20, | ||
searchString: "", | ||
destinationType: "ALL", | ||
}); | ||
expect(mockRes.ok).toHaveBeenCalledWith({ | ||
body: { | ||
ok: true, | ||
destinations: [{ | ||
id: "1", | ||
name: "Sample Destination", | ||
schema_version: 1, | ||
seq_no: 1, | ||
primary_term: 1, | ||
version: 1, | ||
ifSeqNo: 1, | ||
ifPrimaryTerm: 1, | ||
}], | ||
totalDestinations: 1, | ||
}, | ||
}); | ||
}); | ||
|
||
test("should handle index not found error", async () => { | ||
const mockReq = { | ||
query: { | ||
from: 0, | ||
size: 20, | ||
search: "", | ||
sortDirection: "desc", | ||
sortField: "name", | ||
type: "ALL", | ||
}, | ||
}; | ||
const error = new Error(); | ||
error.statusCode = 404; | ||
error.body = { | ||
error: { | ||
reason: 'Configured indices are not found: [.opendistro-alerting-config]' | ||
} | ||
}; | ||
mockClient.mockRejectedValueOnce(error); | ||
|
||
await destinationsService.getDestinations(mockContext, mockReq, mockRes); | ||
|
||
expect(mockRes.ok).toHaveBeenCalledWith({ | ||
body: { | ||
ok: false, | ||
totalMonitors: 0, | ||
monitors: [], | ||
message: "Config index will be created automatically when the monitor is created" | ||
}, | ||
}); | ||
}); | ||
|
||
test("should handle other errors", async () => { | ||
const mockReq = { | ||
query: { | ||
from: 0, | ||
size: 20, | ||
search: "", | ||
sortDirection: "desc", | ||
sortField: "name", | ||
type: "ALL", | ||
}, | ||
}; | ||
|
||
const error = new Error("Some error"); | ||
mockClient.mockRejectedValueOnce(error); | ||
|
||
await destinationsService.getDestinations(mockContext, mockReq, mockRes); | ||
|
||
expect(mockRes.ok).toHaveBeenCalledWith({ | ||
body: { | ||
ok: false, | ||
err: "Some error" | ||
}, | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am hazy on my JS but are you intending to check
response.totalMonitor > 0
if yes, why are we checking for >0 and then code comment says config index not created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the config index will be created automatically when the monitor is created. So, when the
totalMonitors
is 0 it is expected that the config index has not been created, and we don't want to show that error popup to the user.