fleet/frontend/__mocks__/commandMock.ts

66 lines
1.8 KiB
TypeScript
Raw Normal View History

import { ICommand, ICommandResult } from "interfaces/command";
import { IGetCommandsResponse } from "services/entities/command";
const DEFAULT_COMMAND_MOCK: ICommand = {
host_uuid: "default-host-uuid",
command_uuid: "default-command-uuid",
command_status: "pending",
status: "Pending",
updated_at: "2024-01-01T00:00:00Z",
request_type: "InstallProfile",
hostname: "default-hostname",
Show configuration profile name and more fine-grained status (#42126) Resolves #40177 and subissues. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters. ## Testing - [x] Added/updated automated tests - [x] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [sorta] QA'd all new/changed functionality manually ## Database migrations - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Profile names are now displayed alongside mobile device management commands for installing or removing profiles. These names are visible in command details modals and within device activity timelines. * Added "NotNow" status for deferred profile commands, providing improved transparency into which profiles are being managed and the current status of profile installation or removal operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-09 17:46:11 +00:00
name: null,
};
export const createMockCommand = (overrides?: Partial<ICommand>): ICommand => ({
...DEFAULT_COMMAND_MOCK,
...overrides,
});
const DEFAULT_GET_COMMANDS_RESPONSE_MOCK: IGetCommandsResponse = {
count: 1,
results: [DEFAULT_COMMAND_MOCK],
meta: {
has_next_results: false,
has_previous_results: false,
},
};
export const createMockGetCommandsResponse = (
overrides?: Partial<IGetCommandsResponse>
): IGetCommandsResponse => ({
...DEFAULT_GET_COMMANDS_RESPONSE_MOCK,
...overrides,
});
const DEFAULT_COMMAND_RESULT_MOCK: ICommandResult = {
host_uuid: "11111111-2222-3333-4444-555555555555",
command_uuid: "mock-command-uuid-1234",
status: "Acknowledged", // or "Error", "NotNow", "200", etc.
updated_at: "2025-08-10T12:05:00Z",
request_type: "InstallApplication",
hostname: "Mock iPhone",
payload: btoa(`<Command>
<RequestType>InstallApplication</RequestType>
<Identifier>com.example.MockApp</Identifier>
</Command>`),
result: btoa(`<Result>
<Status>Acknowledged</Status>
<Message>Installation complete</Message>
</Result>`),
Show configuration profile name and more fine-grained status (#42126) Resolves #40177 and subissues. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters. ## Testing - [x] Added/updated automated tests - [x] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [sorta] QA'd all new/changed functionality manually ## Database migrations - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Profile names are now displayed alongside mobile device management commands for installing or removing profiles. These names are visible in command details modals and within device activity timelines. * Added "NotNow" status for deferred profile commands, providing improved transparency into which profiles are being managed and the current status of profile installation or removal operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-09 17:46:11 +00:00
name: null,
};
/**
* Creates mock of an Apple MDM command result that implements the ICommandResult interface.
*/
export const createMockAppleMdmCommandResult = (
overrides?: Partial<ICommandResult>
): ICommandResult => {
return {
...DEFAULT_COMMAND_RESULT_MOCK,
...overrides,
};
};