Skip to content

Commit

Permalink
test: add mocks and fixtures for compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
croissanne committed Sep 19, 2024
1 parent e15007e commit 4279a1e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/test/Components/Blueprints/Blueprints.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('Blueprints', () => {
user.click(button);

await waitFor(() => {
expect(screen.getAllByRole('checkbox')).toHaveLength(8);
expect(screen.getAllByRole('checkbox')).toHaveLength(9);
});
});
});
Expand Down
10 changes: 10 additions & 0 deletions src/test/fixtures/blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const mockBlueprintIds = {
packages: 'b3437c4e-f6f8-4270-8d32-323ac60bc929',
firstBoot: 'd0a8376e-e44e-47b3-845d-30f5199a35b6',
details: '58991b91-4b98-47e0-b26d-8d908678ddb3',
compliance: '21571945-fe23-45e9-8afb-4aa073b8d735',
};

export const mockBlueprintNames = {
Expand All @@ -55,6 +56,7 @@ export const mockBlueprintNames = {
packages: 'packages',
firstBoot: 'firstBoot',
details: 'details',
compliance: 'compliance',
};

export const mockBlueprintDescriptions = {
Expand All @@ -75,6 +77,7 @@ export const mockBlueprintDescriptions = {
packages: '',
firstBoot: '',
details: 'This is a test description for the Details step.',
compliance: '',
};

export const mockGetBlueprints: GetBlueprintsApiResponse = {
Expand Down Expand Up @@ -277,6 +280,13 @@ export const mockGetBlueprints: GetBlueprintsApiResponse = {
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
{
id: mockBlueprintIds['compliance'],
name: mockBlueprintNames['compliance'],
description: mockBlueprintDescriptions['compliance'],
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
],
};

Expand Down
43 changes: 43 additions & 0 deletions src/test/fixtures/compliance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const mockPolicies = {
data: [
{
id: '393bca7e-5d2b-4646-a86c-373fc5c50d8b',
title: 'CIS workstation l1',
description: 'Fancy description',
business_objective: null,
compliance_threshold: 100,
total_system_count: 0,
type: 'policy',
os_major_version: 8,
profile_title:
'CIS Red Hat Enterprise Linux 8 Benchmark for Level 1 - Workstation',
ref_id: 'xccdf_org.ssgproject.content_profile_cis_workstation_l1',
},
{
id: '0ee9a781-b53f-4d9e-91e1-d75aed088c44',
title: 'CIS workstation l2',
description: 'Fancy description',
compliance_threshold: 100,
total_system_count: 100,
type: 'policy',
os_major_version: 8,
profile_title:
'CIS Red Hat Enterprise Linux 8 Benchmark for Level 2 - Workstation',
ref_id: 'xccdf_org.ssgproject.content_profile_cis_workstation_l2',
},
{
id: '88359aa5-ba7e-44d9-9048-02c7918ff58c',
title: 'STIG GUI',
description: 'Fancy description',
compliance_threshold: 100,
total_system_count: 30,
type: 'policy',
os_major_version: 8,
profile_title: 'DISA STIG with GUI for Red Hat Enterprise Linux 8',
ref_id: 'xccdf_org.ssgproject.content_profile_stig_gui',
},
],
meta: {
total: 3,
},
};
23 changes: 23 additions & 0 deletions src/test/fixtures/editMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,27 @@ export const detailsBlueprintResponse: BlueprintResponse = {
description: mockBlueprintDescriptions['details'],
};

export const complianceCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['compliance'],
description: mockBlueprintDescriptions['compliance'],
customizations: {
packages: expectedPackagesCisL2,
openscap: {
policy_id: '0ee9a781-b53f-4d9e-91e1-d75aed088c44',
},
services: expectedServicesCisL2,
kernel: expectedKernelCisL2,
filesystem: expectedFilesystemCisL2,
},
};

export const complianceBlueprintResponse: BlueprintResponse = {
...complianceCreateBlueprintRequest,
id: mockBlueprintIds['compliance'],
description: mockBlueprintDescriptions['compliance'],
};

export const getMockBlueprintResponse = (id: string) => {
switch (id) {
case mockBlueprintIds['darkChocolate']:
Expand Down Expand Up @@ -485,6 +506,8 @@ export const getMockBlueprintResponse = (id: string) => {
return firstBootBlueprintResponse;
case mockBlueprintIds['details']:
return detailsBlueprintResponse;
case mockBlueprintIds['compliance']:
return complianceBlueprintResponse;
default:
return;
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/mocks/handlers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { http, HttpResponse } from 'msw';

import {
COMPLIANCE_API,
CONTENT_SOURCES_API,
CREATE_BLUEPRINT,
IMAGE_BUILDER_API,
Expand All @@ -19,6 +20,7 @@ import {
mockEmptyBlueprintsComposes,
mockGetBlueprints,
} from '../fixtures/blueprints';
import { mockPolicies } from '../fixtures/compliance';
import {
composesEndpoint,
mockClones,
Expand Down Expand Up @@ -212,4 +214,16 @@ export const handlers = [
http.post(`${IMAGE_BUILDER_API}/experimental/recommendations`, () => {
return HttpResponse.json(mockPkgRecommendations);
}),
http.get(`${COMPLIANCE_API}/policies`, () => {
return HttpResponse.json(mockPolicies);
}),
http.get(`${COMPLIANCE_API}/policies/:id`, ({ params }) => {
const id = params['id'];
for (const p of mockPolicies.data) {
if (p.id === id) {
return HttpResponse.json({ data: p });
}
}
return HttpResponse.error();
}),
];

0 comments on commit 4279a1e

Please sign in to comment.