-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error toast message while configuring trigger while creating a m…
…onitor
- Loading branch information
Showing
3 changed files
with
194 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
"@babel/plugin-transform-modules-commonjs": "^7.22.9", | ||
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards", | ||
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards", | ||
"cypress": "9.5.4", | ||
"cypress": "12.17.4", | ||
"husky": "^8.0.0", | ||
"lint-staged": "^10.2.0", | ||
"@types/react": "^16.14.23" | ||
|
@@ -67,5 +67,6 @@ | |
}, | ||
"engines": { | ||
"yarn": "^1.21.1" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
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,186 @@ | ||
import DestinationsService from "./DestinationsService"; | ||
|
||
describe("Test DestinationsService -- getDestinations", () => { | ||
let destinationsService; | ||
let mockContext; | ||
let mockReq; | ||
let mockRes; | ||
let mockClient; | ||
|
||
beforeEach(() => { | ||
mockClient = jest.fn(); | ||
|
||
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: true, | ||
resp: "Indices will be configured when the monitor is created: [.opendistro-alerting-config]" | ||
}, | ||
}); | ||
}); | ||
|
||
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" | ||
}, | ||
}); | ||
}); | ||
|
||
}); | ||
}); |