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

test: Firewall edit tests (HMS-5399) #2804

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -2,14 +2,18 @@ import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';

import { CREATE_BLUEPRINT } from '../../../../../constants';
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { firewallCreateBlueprintRequest } from '../../../../fixtures/editMode';
import {
blueprintRequest,
clickBack,
clickNext,
enterBlueprintName,
interceptBlueprintRequest,
interceptEditBlueprintRequest,
openAndDismissSaveAndBuildModal,
renderEditMode,
verifyCancelButton,
} from '../../wizardTestUtils';
import { clickRegisterLater, renderCreateMode } from '../../wizardTestUtils';
Expand Down Expand Up @@ -205,5 +209,22 @@ describe('Firewall request generated correctly', () => {
});
});

describe('Firewall edit mode', () => {
beforeEach(() => {
vi.clearAllMocks();
});

test('edit mode works', async () => {
const id = mockBlueprintIds['firewall'];
await renderEditMode(id);

// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`
);
const expectedRequest = firewallCreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
});

// TO DO Step Firewall -> revisit step button on Review works
// TO DO Firewall edit mode
10 changes: 10 additions & 0 deletions src/test/fixtures/blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const mockBlueprintIds = {
locale: '6e982b49-cd2e-4ad0-9962-39315a0ed9d1',
hostname: '05677f58-56c5-4c1e-953b-c8a93da70cc5',
kernel: '8d6d35c7-a098-4bf5-a67f-5c59628210dc',
firewall: '26f14b17-bdee-4c06-a12b-b6ee384350de',
firstBoot: 'd0a8376e-e44e-47b3-845d-30f5199a35b6',
details: '58991b91-4b98-47e0-b26d-8d908678ddb3',
compliance: '21571945-fe23-45e9-8afb-4aa073b8d735',
Expand All @@ -64,6 +65,7 @@ export const mockBlueprintNames = {
locale: 'locale',
hostname: 'hostname',
kernel: 'kernel',
firewall: 'firewall',
firstBoot: 'firstBoot',
details: 'details',
compliance: 'compliance',
Expand All @@ -90,6 +92,7 @@ export const mockBlueprintDescriptions = {
locale: '',
hostname: '',
kernel: '',
firewall: '',
firstBoot: '',
details: 'This is a test description for the Details step.',
compliance: '',
Expand Down Expand Up @@ -316,6 +319,13 @@ export const mockGetBlueprints: GetBlueprintsApiResponse = {
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
{
id: mockBlueprintIds['firewall'],
name: mockBlueprintNames['firewall'],
description: mockBlueprintDescriptions['firewall'],
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
{
id: mockBlueprintIds['firstBoot'],
name: mockBlueprintNames['firstBoot'],
Expand Down
31 changes: 31 additions & 0 deletions src/test/fixtures/editMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,35 @@ export const kernelBlueprintResponse: BlueprintResponse = {
description: mockBlueprintDescriptions['kernel'],
};

export const firewallCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['firewall'],
description: mockBlueprintDescriptions['firewall'],
customizations: {
firewall: {
ports: [
'22:tcp',
'80:tcp',
'imap:tcp',
'53:tcp',
'53:udp',
'30000-32767:tcp',
'30000-32767:udp',
],
services: {
disabled: ['telnet'],
enabled: ['ftp', 'ntp', 'dhcp'],
},
},
},
};

export const firewallBlueprintResponse: BlueprintResponse = {
...firewallCreateBlueprintRequest,
id: mockBlueprintIds['firewall'],
description: mockBlueprintDescriptions['firewall'],
};

export const firstBootCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['firstBoot'],
Expand Down Expand Up @@ -605,6 +634,8 @@ export const getMockBlueprintResponse = (id: string) => {
return hostnameBlueprintResponse;
case mockBlueprintIds['kernel']:
return kernelBlueprintResponse;
case mockBlueprintIds['firewall']:
return firewallBlueprintResponse;
case mockBlueprintIds['firstBoot']:
return firstBootBlueprintResponse;
case mockBlueprintIds['details']:
Expand Down
Loading