Skip to content
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

Add custom checks acceptance tests #2216

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cbd7f12
Testing
soujay Jan 10, 2025
778cbf2
raw testing of mock data Frontend custom checks
soujay Jan 11, 2025
07ade85
dynamic precondition function hasCustomChecks
cquirosj Jan 11, 2025
fcfd091
No data custom checks tests
cquirosj Jan 11, 2025
300bfd1
wip Failing custom checks tests
cquirosj Jan 11, 2025
44edfad
All custom checks are in a failed state TODOs
cquirosj Jan 11, 2025
a337eb2
precondition.hasCustomChecks params rename
cquirosj Jan 11, 2025
dca2eb7
WIP All custom checks are in a failed state asserts
cquirosj Jan 11, 2025
c78b1e9
Revert "WIP All custom checks are in a failed state asserts"
soujay Jan 12, 2025
3431943
Revert "precondition.hasCustomChecks params rename"
soujay Jan 12, 2025
0b93fd4
Revert "All custom checks are in a failed state TODOs"
soujay Jan 12, 2025
3c056ab
Revert "wip Failing custom checks tests"
soujay Jan 12, 2025
9e4bcbe
Revert "No data custom checks tests"
soujay Jan 12, 2025
3f810b0
Revert "dynamic precondition function hasCustomChecks"
soujay Jan 12, 2025
56aef1b
wip : add mocks for custom checks data, add test to check for "no fai…
soujay Jan 20, 2025
1d62fbe
add driver set up for servicecontrolwithmonitoring to fix the tests
soujay Jan 20, 2025
5991954
refactor files and code
soujay Jan 20, 2025
a624624
add a template for custom check items and use it for tests
soujay Jan 20, 2025
2bff573
use mockEndpointDynamic to add customchecks url by querystring
soujay Jan 20, 2025
48b9b80
remove extra space
soujay Jan 20, 2025
656dc45
Update src/Frontend/test/specs/customchecks/viewing-no-data.spec.ts
soujay Jan 22, 2025
17d3451
Update src/Frontend/test/specs/customchecks/viewing-no-data.spec.ts
soujay Jan 22, 2025
7579f0d
added some console.log for testing
soujay Jan 23, 2025
86737c9
Merge branch 'add-customchecks-acceptance-tests-js' of https://github…
soujay Jan 23, 2025
e8bcffa
add test for no custom check data scenario
soujay Jan 28, 2025
3db1192
set up mock data for custom check and write tests for empty and faile…
soujay Jan 28, 2025
b0171ce
add no data and failing cutom checks
soujay Jan 29, 2025
c623319
fix custom check pagination test
soujay Jan 29, 2025
383c6a7
generate custom check items
soujay Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const serviceControlWithHeartbeats = async ({ driver }: SetupFactoryOptio
await driver.setUp(precondition.hasUpToDateServicePulse);
await driver.setUp(precondition.hasUpToDateServiceControl);
await driver.setUp(precondition.errorsDefaultHandler);
await driver.setUp(precondition.hasNoFailingCustomChecks);
await driver.setUp(precondition.hasCustomChecksEmpty);
await driver.setUp(precondition.hasEventLogItems);
await driver.setUp(precondition.hasServiceControlMainInstance(minimumSCVersionForEndpointSettings));
await driver.setUp(precondition.hasNoDisconnectedEndpoints);
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/src/views/CustomChecksView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { pageNumber, failingCount, failedChecks } = storeToRefs(store);
</div>

<section name="custom_checks">
<NoData v-if="failingCount === 0" message="No failed custom checks" />
<NoData v-if="failingCount === 0" message="No failed custom checks" role="heading" aria-label="customcheck-message" />
<div v-else class="row">
<div class="col-sm-12">
<CustomCheckView v-for="item of failedChecks" :key="item.id" :custom-check="item" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const serviceControlWithThroughput = async ({ driver }: SetupFactoryOptio
await driver.setUp(precondition.hasUpToDateServicePulse);
await driver.setUp(precondition.hasUpToDateServiceControl);
await driver.setUp(precondition.errorsDefaultHandler);
await driver.setUp(precondition.hasNoFailingCustomChecks);
await driver.setUp(precondition.hasCustomChecksEmpty);
await driver.setUp(precondition.hasEventLogItems);
await driver.setUp(precondition.hasNoHeartbeatsEndpoints);
await driver.setUp(precondition.hasServiceControlMainInstance(minimumSCVersionForThroughput));
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/test/mocks/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const driver = makeDriver();
(async () => {
await driver.setUp(precondition.serviceControlWithMonitoring);
//override the default mocked endpoints with a custom list
await driver.setUp(precondition.hasCustomChecksEmpty);
await driver.setUp(
precondition.monitoredEndpointsNamed([
"Universe.Solarsystem.Mercury.Endpoint1",
Expand All @@ -35,7 +36,6 @@ const driver = makeDriver();
"Universe.Solarsystem.Earth.Endpoint6",
])
);

await driver.setUp(
precondition.hasFailedMessage({
withGroupId: "81dca64e-76fc-e1c3-11a2-3069f51c58c8",
Expand Down
108 changes: 108 additions & 0 deletions src/Frontend/test/mocks/custom-checks-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import CustomCheck, { Status } from "@/resources/CustomCheck";

export const customCheckItems: CustomCheck[] = [
{
id: "CustomChecks/6131fa95-9414-1898-9c83-c5b18587945b",
custom_check_id: "Audit Message Ingestion",
category: "ServiceControl.Audit Health",
status: Status.Fail,
failure_reason: "I dont know the reason",
reported_at: "2025-01-10T05:06:30.4074087Z",
originating_endpoint: {
name: "Particular.ServiceControl.Audit",
host_id: "ff605b55-6fbb-af56-5753-73c1ff73e601",
host: "COMPUSA",
},
},
{
id: "CustomChecks/36752f09-8a72-752e-e48f-6c378329d43b",
custom_check_id: "Error Message Ingestion",
category: "ServiceControl Health",
status: Status.Fail,
failure_reason: "I am unable to ingest error messages",
reported_at: "2025-01-10T05:42:00.531067Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/93b62dc3-e1bf-abfd-4268-8d36fef2b0c6",
custom_check_id: "ServiceControl database",
category: "Storage space",
status: Status.Pass,
failure_reason: "",
reported_at: "2025-01-10T05:52:03.8512021Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/7e09172e-7c59-9a0c-52da-e2ecc1784e15",
custom_check_id: "Saga Audit Configuration",
category: "Configuration",
status: Status.Fail,
failure_reason: "There is something wrong in Saga Audit configuration",
reported_at: "2025-01-10T05:52:03.850927Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/4dc66bce-632b-5404-bc3d-e1943d99c301",
custom_check_id: "Error Database Index Lag",
category: "ServiceControl Health",
status: Status.Pass,
failure_reason: "",
reported_at: "2025-01-10T05:52:05.8153025Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/66675ab0-b69a-6a5a-6a56-da7709464fba",
custom_check_id: "Message Ingestion Process",
category: "ServiceControl Health",
status: Status.Fail,
failure_reason: "Unable to ingest messages",
reported_at: "2025-01-10T05:52:29.398929Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/418dafe7-1dd2-886b-65d1-2b3e71e4feb2",
custom_check_id: "Error Message Ingestion Process",
category: "ServiceControl Health",
status: Status.Fail,
failure_reason: "No idea whats going on here",
reported_at: "2025-01-10T05:52:29.3984912Z",
originating_endpoint: {
name: "Particular.ServiceControl",
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
host: "COMPUSA",
},
},
{
id: "CustomChecks/a406f1a7-412c-dd2c-7f90-9aa32da0698b",
custom_check_id: "Audit Message Ingestion Process",
category: "ServiceControl Health",
status: Status.Pass,
failure_reason: "",
reported_at: "2025-01-10T05:52:31.4929675Z",
originating_endpoint: {
name: "Particular.ServiceControl.Audit",
host_id: "ff605b55-6fbb-af56-5753-73c1ff73e601",
host: "COMPUSA",
},
},
];
43 changes: 43 additions & 0 deletions src/Frontend/test/preconditions/customChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SetupFactoryOptions } from "../driver";
import { customCheckItems } from "../mocks/custom-checks-template";

const content = JSON.stringify([]);
const failedCustomCheckItems = customCheckItems.filter((check) => check.status === "Fail");
const passedCustomCheckItems = customCheckItems.filter((check) => check.status === "Pass");

export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
body: content,
headers: {
"Total-Count": "0", //count of failing custom checks
},
});
};

export const hasCustomChecksFailing = ({ driver }: SetupFactoryOptions) => {
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
const status = url.searchParams.get("status");
if (status === "fail") {
return {
body: failedCustomCheckItems,
headers: { "Total-Count": failedCustomCheckItems.length.toString() },
};
}

return {
body: passedCustomCheckItems,
headers: { "Total-Count": passedCustomCheckItems.length.toString() },
soujay marked this conversation as resolved.
Show resolved Hide resolved
};
});
};
export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => {
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
body: passedCustomCheckItems,
headers: {
"Total-Count": passedCustomCheckItems.length.toString(), //count of passing custom checks
},
});
};
11 changes: 0 additions & 11 deletions src/Frontend/test/preconditions/hasNoFailingCustomChecks.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/Frontend/test/preconditions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { hasServiceControlMonitoringInstanceUrl } from "../preconditions/hasServ
export { hasUpToDateServiceControl } from "../preconditions/hasUpToDateServiceControl";
export { hasUpToDateServicePulse } from "../preconditions/hasUpToDateServicePulse";
export { errorsDefaultHandler } from "../preconditions/hasNoErrors";
export { hasNoFailingCustomChecks } from "../preconditions/hasNoFailingCustomChecks";
export { hasCustomChecksEmpty, hasCustomChecksFailing, hasCustomChecksPassing } from "./customChecks";
export { hasNoDisconnectedEndpoints } from "../preconditions/hasNoDisconnectedEndpoints";
export { hasNoMonitoredEndpoints, hasMonitoredEndpointsList, monitoredEndpointsNamed } from "../preconditions/hasMonitoredEndpoints";
export { hasEventLogItems } from "../preconditions/hasEventLogItems";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const serviceControlWithMonitoring = async ({ driver }: SetupFactoryOptio
await driver.setUp(precondition.errorsDefaultHandler);

//http://localhost:33333/api/customchecks
await driver.setUp(precondition.hasNoFailingCustomChecks);
await driver.setUp(precondition.hasCustomChecksEmpty);

//http://localhost:33633/monitored-endpoints/disconnected
await driver.setUp(precondition.hasNoDisconnectedEndpoints);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { screen } from "@testing-library/vue";

export async function customChecksMessage() {
const txtMessage = await screen.findByRole("heading", { name: "customcheck-message" });
return txtMessage.textContent?.trim();
}
34 changes: 30 additions & 4 deletions src/Frontend/test/specs/customchecks/viewing-no-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
import { test, describe } from "../../drivers/vitest/driver";
import { expect } from "vitest";
import * as precondition from "../../preconditions";
import { customChecksMessage } from "./questions/customChecksMessage";
import { waitFor } from "@testing-library/vue";

describe("FEATURE: No data", () => {
describe("RULE: When there is no data to show a message should be displayed ", () => {
test.todo("EXAMPLE: 'No failed custom checks' should be displayed when there are no custom checks");

/* SCENARIO
Given there are no custom checks
When navigating to the custom checks tab
Then a message is shown "No failed custom checks"
*/
soujay marked this conversation as resolved.
Show resolved Hide resolved
test("EXAMPLE: 'No failed custom checks' should be displayed when there are no custom checks", async ({ driver }) => {
soujay marked this conversation as resolved.
Show resolved Hide resolved
//Arrange
await driver.setUp(precondition.serviceControlWithMonitoring);
// given that the custom check list is empty
await driver.setUp(precondition.hasCustomChecksEmpty);

test.todo("EXAMPLE: 'No failed custom checks' should be displayed when all custom checks are in a success state");
//Act - When navigating to the custom checks tab
await driver.goTo("/custom-checks");
//Expect
await waitFor(async () => {
expect(await customChecksMessage()).toBe("No failed custom checks");
});
});
/* SCENARIO
Given there are custom checks
And all custom checks are in a success state
When navigating to the custom checks tab
The a message is shown "No failed custom checks"
Then a message is shown "No failed custom checks"
*/
test("EXAMPLE: 'No failed custom checks' should be displayed when all custom checks are in a success state", async ({ driver }) => {
soujay marked this conversation as resolved.
Show resolved Hide resolved
//Arrange
await driver.setUp(precondition.serviceControlWithMonitoring);
// given that the custom check list is not empty and status of all checks are passing
await driver.setUp(precondition.hasCustomChecksPassing);
soujay marked this conversation as resolved.
Show resolved Hide resolved

//Act - When navigating to the custom checks tab
await driver.goTo("/custom-checks");
//Expect
await waitFor(async () => {
expect(await customChecksMessage()).toBe("No failed custom checks");
});
});
});
});