Skip to content

Commit

Permalink
Add tests to ExecutuionResults
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Nov 16, 2022
1 parent ce85a85 commit 3a326ce
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 9 deletions.
75 changes: 75 additions & 0 deletions assets/js/components/ExecutionResults/ExecutionResults.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { act, screen } from '@testing-library/react';

import { renderWithRouter } from '@lib/test-utils';
import {
hostnameFactory,
checksExecutionFactory,
catalogCheckFactory,
} from '@lib/test-utils/factories';

import ExecutionResults from './ExecutionResults';

describe('ExecutionResults', () => {
it('should render ExecutionResults with successfully fetched results', async () => {
const hostnames = hostnameFactory.buildList(2);
const [{ id: agentID, hostname }] = hostnames;
const executionResult = checksExecutionFactory.build({
agentID,
status: 'completed',
result: 'passing',
});
const {
groupID: clusterID,
execution_id: executionID,
check_results: [{ check_id: checkID }],
} = executionResult;
const catalog = [catalogCheckFactory.build({ id: checkID })];

await act(async () => {
renderWithRouter(
<ExecutionResults
clusterID={clusterID}
executionID={executionID}
onExecutionFetch={() => Promise.resolve({ data: executionResult })}
onCatalogFetch={() => Promise.resolve({ data: { items: catalog } })}
hostnames={hostnames}
/>
);
});

expect(screen.getByText(hostname)).toBeTruthy();
expect(screen.getByText(checkID)).toBeTruthy();
});

it('should render ExecutionResults with running state', async () => {
const hostnames = hostnameFactory.buildList(2);
const [{ id: agentID }] = hostnames;
const executionResult = checksExecutionFactory.build({
agentID,
status: 'running',
});
const {
groupID: clusterID,
execution_id: executionID,
check_results: [{ check_id: checkID }],
} = executionResult;
const catalog = [catalogCheckFactory.build({ id: checkID })];

await act(async () => {
renderWithRouter(
<ExecutionResults
clusterID={clusterID}
executionID={executionID}
onExecutionFetch={() => Promise.resolve({ data: executionResult })}
onCatalogFetch={() => Promise.resolve({ data: { items: catalog } })}
hostnames={hostnames}
/>
);
});

expect(
screen.getByText('Check execution currently running...')
).toBeTruthy();
});
});
66 changes: 57 additions & 9 deletions assets/js/lib/test-utils/factories.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

const healthEnum = faker.helpers.arrayElement([
'requested',
'running',
'not_running',
]);
const healthEnum = () =>
faker.helpers.arrayElement(['requested', 'running', 'not_running']);

const resultEnum = () =>
faker.helpers.arrayElement(['passing', 'critical', 'warning']);

export const checkFactory = Factory.define(() => ({
id: faker.datatype.uuid(),
Expand All @@ -16,12 +16,12 @@ export const checkFactory = Factory.define(() => ({

export const healthSummaryFactory = Factory.define(() => ({
clusterId: faker.datatype.uuid(),
clustersHealth: healthEnum,
databaseHealth: healthEnum,
clustersHealth: healthEnum(),
databaseHealth: healthEnum(),
databaseId: faker.datatype.uuid(),
hostsHealth: healthEnum,
hostsHealth: healthEnum(),
id: faker.datatype.uuid(),
sapsystemHealth: healthEnum,
sapsystemHealth: healthEnum(),
sid: faker.random.alphaNumeric({
length: 3,
casing: 'upper',
Expand All @@ -35,3 +35,51 @@ export const catalogCheckFactory = Factory.define(() => ({
description: faker.lorem.paragraph(),
remediation: faker.lorem.paragraph(),
}));

export const checksExecutionFactory = Factory.define(({ params }) => {
const {
agentID = faker.datatype.uuid(),
groupID = faker.datatype.uuid(),
executionID = faker.datatype.uuid(),
} = params;

return {
completed_at: '2022-11-09T17:02:20.629366Z',
execution_id: executionID,
group_id: groupID,
result: resultEnum(),
started_at: '2022-11-09T15:11:31.436586Z',
status: faker.helpers.arrayElement(['running', 'completed']),
timeout: [],
check_results: [
{
agents_check_results: [
{
agent_id: agentID,
expectation_evaluations: [
{
name: 'expectation_example',
return_value: 123,
type: 'expect',
},
],
facts: [
{ check_id: '156F64', name: 'lol_this_is_a_fact', value: 123 },
],
values: [],
},
],
check_id: faker.datatype.uuid(),
expectation_results: [
{ name: 'expectation_example', result: true, type: 'expect' },
],
result: resultEnum(),
},
],
};
});

export const hostnameFactory = Factory.define(() => ({
id: faker.datatype.uuid(),
hostname: faker.hacker.noun(),
}));

0 comments on commit 3a326ce

Please sign in to comment.