From 4279a1ead80bc1842045707d1eb6712b416a4ee1 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Thu, 12 Sep 2024 11:53:09 +0200 Subject: [PATCH] test: add mocks and fixtures for compliance --- .../Components/Blueprints/Blueprints.test.tsx | 2 +- src/test/fixtures/blueprints.ts | 10 +++++ src/test/fixtures/compliance.ts | 43 +++++++++++++++++++ src/test/fixtures/editMode.ts | 23 ++++++++++ src/test/mocks/handlers.js | 14 ++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/test/fixtures/compliance.ts diff --git a/src/test/Components/Blueprints/Blueprints.test.tsx b/src/test/Components/Blueprints/Blueprints.test.tsx index 73cc82b43..47ae5d5fc 100644 --- a/src/test/Components/Blueprints/Blueprints.test.tsx +++ b/src/test/Components/Blueprints/Blueprints.test.tsx @@ -271,7 +271,7 @@ describe('Blueprints', () => { user.click(button); await waitFor(() => { - expect(screen.getAllByRole('checkbox')).toHaveLength(8); + expect(screen.getAllByRole('checkbox')).toHaveLength(9); }); }); }); diff --git a/src/test/fixtures/blueprints.ts b/src/test/fixtures/blueprints.ts index 9f9dc3f4c..8e146f035 100644 --- a/src/test/fixtures/blueprints.ts +++ b/src/test/fixtures/blueprints.ts @@ -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 = { @@ -55,6 +56,7 @@ export const mockBlueprintNames = { packages: 'packages', firstBoot: 'firstBoot', details: 'details', + compliance: 'compliance', }; export const mockBlueprintDescriptions = { @@ -75,6 +77,7 @@ export const mockBlueprintDescriptions = { packages: '', firstBoot: '', details: 'This is a test description for the Details step.', + compliance: '', }; export const mockGetBlueprints: GetBlueprintsApiResponse = { @@ -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', + }, ], }; diff --git a/src/test/fixtures/compliance.ts b/src/test/fixtures/compliance.ts new file mode 100644 index 000000000..5556352fd --- /dev/null +++ b/src/test/fixtures/compliance.ts @@ -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, + }, +}; diff --git a/src/test/fixtures/editMode.ts b/src/test/fixtures/editMode.ts index 909aad0bd..345fab713 100644 --- a/src/test/fixtures/editMode.ts +++ b/src/test/fixtures/editMode.ts @@ -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']: @@ -485,6 +506,8 @@ export const getMockBlueprintResponse = (id: string) => { return firstBootBlueprintResponse; case mockBlueprintIds['details']: return detailsBlueprintResponse; + case mockBlueprintIds['compliance']: + return complianceBlueprintResponse; default: return; } diff --git a/src/test/mocks/handlers.js b/src/test/mocks/handlers.js index d1ffdc220..c5d7891c0 100644 --- a/src/test/mocks/handlers.js +++ b/src/test/mocks/handlers.js @@ -1,6 +1,7 @@ import { http, HttpResponse } from 'msw'; import { + COMPLIANCE_API, CONTENT_SOURCES_API, CREATE_BLUEPRINT, IMAGE_BUILDER_API, @@ -19,6 +20,7 @@ import { mockEmptyBlueprintsComposes, mockGetBlueprints, } from '../fixtures/blueprints'; +import { mockPolicies } from '../fixtures/compliance'; import { composesEndpoint, mockClones, @@ -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(); + }), ];