Frontend: Combine queries and schedules mock API calls for FE development (#12670)

This commit is contained in:
RachelElysia
2023-07-13 12:04:08 -07:00
committed by GitHub
parent 9aa7c0c714
commit 1d8d6d8c15
5 changed files with 153 additions and 19 deletions
@@ -0,0 +1,39 @@
// "SchedulableQuery" to be used in developing frontend for #7765
import { ISchedulableQuery } from "interfaces/schedulable_query";
const DEFAULT_SCHEDULABLE_QUERY_MOCK: ISchedulableQuery = {
created_at: "2022-11-03T17:22:14Z",
updated_at: "2022-11-03T17:22:14Z",
id: 1,
name: "Test Query",
description: "A test query",
query: "SELECT * FROM users",
team_id: null,
interval: 3600,
platform: "darwin,windows,linux",
min_osquery_version: "",
automations_enabled: true,
logging: "snapshot",
saved: true,
author_id: 1,
author_name: "Test User",
author_email: "test@example.com",
observer_can_run: false,
packs: [],
stats: {
system_time_p50: 1,
system_time_p95: 1,
user_time_p50: 1,
user_time_p95: 1,
total_executions: 3,
},
};
const createMockSchedulableQuery = (
overrides?: Partial<ISchedulableQuery>
): ISchedulableQuery => {
return { ...DEFAULT_SCHEDULABLE_QUERY_MOCK, ...overrides };
};
export default createMockSchedulableQuery;
+2 -19
View File
@@ -1,24 +1,7 @@
import PropTypes from "prop-types";
import { IFormField } from "./form_field";
import packInterface, { IPack } from "./pack";
import scheduledQueryStatsInterface, {
IScheduledQueryStats,
} from "./scheduled_query_stats";
import { IPack } from "./pack";
import { IScheduledQueryStats } from "./scheduled_query_stats";
export default PropTypes.shape({
created_at: PropTypes.string,
updated_at: PropTypes.string,
id: PropTypes.number,
name: PropTypes.string,
description: PropTypes.string,
query: PropTypes.string,
saved: PropTypes.bool,
author_id: PropTypes.number,
author_name: PropTypes.string,
observer_can_run: PropTypes.bool,
packs: PropTypes.arrayOf(packInterface),
stats: scheduledQueryStatsInterface,
});
export interface IQueryFormData {
description?: string | number | boolean | undefined;
name?: string | number | boolean | undefined;
+3
View File
@@ -5,6 +5,9 @@ import { IQueryFormData } from "interfaces/query";
import { ISelectedTargets } from "interfaces/target";
import { AxiosResponse } from "axios";
// Mock API requests to be used in developing FE for #7765 in parallel with BE development
// import { sendRequest } from "services/mock_service/service/service";
export default {
create: ({ description, name, query, observer_can_run }: IQueryFormData) => {
const { QUERIES } = endpoints;
@@ -22,6 +22,11 @@ const REQUEST_RESPONSE_MAPPINGS: IResponses = {
// request query string is hostname, uuid, or mac address; response is host detail excluding any
// expensive data operations
"targets?query={*}": RESPONSES.hosts,
// "SchedulableQueries" to be used in developing frontend for #7765
queries: RESPONSES.queries,
"queries/1": RESPONSES.query1,
"queries/2": RESPONSES.query2,
"queries/3": RESPONSES.query3,
},
POST: {
// request body is ISelectedTargets
@@ -31,6 +36,15 @@ const REQUEST_RESPONSE_MAPPINGS: IResponses = {
targets_offline: 1,
targets_missing_in_action: 0,
},
// "SchedulableQueries" to be used in developing frontend for #7765
queries: {
description: "Ok",
name: "New query name",
observer_can_run: false,
query: "SELECT * FROM osquery_info;",
team_id: null,
platform: "linux",
},
},
} as IResponses;
@@ -364,8 +364,103 @@ const labels = {
],
};
// "SchedulableQueries" to be used in developing frontend for #7765
const queries = {
queries: [
{
created_at: "2022-11-03T17:22:14Z",
updated_at: "2022-11-03T17:22:14Z",
id: 1,
name: "Test Query",
description: "A test query",
query: "SELECT * FROM users",
team_id: null,
interval: 3600,
platform: "darwin,windows,linux",
min_osquery_version: "",
automations_enabled: true,
logging: "snapshot",
saved: true,
author_id: 1,
author_name: "Test User",
author_email: "test@example.com",
observer_can_run: false,
packs: [],
stats: {
system_time_p50: null,
system_time_p95: null,
user_time_p50: null,
user_time_p95: null,
total_executions: null,
},
},
{
created_at: "2022-11-03T17:22:14Z",
updated_at: "2022-11-03T17:22:14Z",
id: 2,
name: "Test Query 2",
description: "A second test query",
query: "SELECT * FROM osquery_info",
team_id: 1,
interval: 3600,
platform: "linux",
min_osquery_version: "",
automations_enabled: false,
logging: "differential",
saved: false,
author_id: 2,
author_name: "Test User 2",
author_email: "test2@example.com",
observer_can_run: true,
packs: [],
stats: {
system_time_p50: null,
system_time_p95: null,
user_time_p50: null,
user_time_p95: null,
total_executions: null,
},
},
{
created_at: "2022-11-03T17:22:14Z",
updated_at: "2022-11-03T17:22:14Z",
id: 3,
name: "Test Query 3",
description: "A third test query",
query: "SELECT * FROM osquery_info",
team_id: 2,
interval: 3600,
platform: "",
min_osquery_version: "",
automations_enabled: false,
logging: "differential",
saved: false,
author_id: 2,
author_name: "Test User 2",
author_email: "test2@example.com",
observer_can_run: true,
packs: [],
stats: {
system_time_p50: null,
system_time_p95: null,
user_time_p50: null,
user_time_p95: null,
total_executions: null,
},
},
],
};
const query1 = { query: queries.queries[0] };
const query2 = { query: queries.queries[1] };
const query3 = { query: queries.queries[2] };
export default {
count,
hosts,
labels,
queries,
query1,
query2,
query3,
};