Skip to content

Commit

Permalink
test: Firewall edit tests
Browse files Browse the repository at this point in the history
This adds firewall tests for the edit mode.
  • Loading branch information
regexowl committed Jan 28, 2025
1 parent 2089cdf commit d5adb4a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
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 @@ -37,6 +37,7 @@ export const mockBlueprintIds = {
timezone: 'c535dc6e-93b0-4592-ad29-fe46ba7dac73',
locale: '6e982b49-cd2e-4ad0-9962-39315a0ed9d1',
hostname: '05677f58-56c5-4c1e-953b-c8a93da70cc5',
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 @@ -62,6 +63,7 @@ export const mockBlueprintNames = {
timezone: 'timezone',
locale: 'locale',
hostname: 'hostname',
firewall: 'firewall',
firstBoot: 'firstBoot',
details: 'details',
compliance: 'compliance',
Expand All @@ -87,6 +89,7 @@ export const mockBlueprintDescriptions = {
timezone: '',
locale: '',
hostname: '',
firewall: '',
firstBoot: '',
details: 'This is a test description for the Details step.',
compliance: '',
Expand Down Expand Up @@ -306,6 +309,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 @@ -493,6 +493,35 @@ export const hostnameBlueprintResponse: BlueprintResponse = {
description: mockBlueprintDescriptions['hostname'],
};

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 @@ -585,6 +614,8 @@ export const getMockBlueprintResponse = (id: string) => {
return localeBlueprintResponse;
case mockBlueprintIds['hostname']:
return hostnameBlueprintResponse;
case mockBlueprintIds['firewall']:
return firewallBlueprintResponse;
case mockBlueprintIds['firstBoot']:
return firstBootBlueprintResponse;
case mockBlueprintIds['details']:
Expand Down

0 comments on commit d5adb4a

Please sign in to comment.