Fix for cannot run query for selected teams (#1037)
- Fix ability to run live query against teams - Update unit tests to support live queries against teams
This commit is contained in:
+3
-2
@@ -101,15 +101,17 @@ describe("SelectTargetsDropdown - component", () => {
|
||||
targets: {
|
||||
hosts: [],
|
||||
labels: [Test.Stubs.labelStub],
|
||||
teams: [],
|
||||
},
|
||||
};
|
||||
const apiResponseWithoutTargets = {
|
||||
targets: {
|
||||
hosts: [],
|
||||
labels: [],
|
||||
teams: [],
|
||||
},
|
||||
};
|
||||
const defaultSelectedTargets = { hosts: [], labels: [] };
|
||||
const defaultSelectedTargets = { hosts: [], labels: [], teams: [] };
|
||||
const defaultParams = {
|
||||
query: "",
|
||||
query_id: 1,
|
||||
@@ -155,7 +157,6 @@ describe("SelectTargetsDropdown - component", () => {
|
||||
const node = Component.instance();
|
||||
|
||||
Test.Mocks.targetMock(defaultParams, apiResponseWithoutTargets);
|
||||
|
||||
expect.assertions(3);
|
||||
return node.fetchTargets().then(() => {
|
||||
expect(Component.state("isEmpty")).toEqual(true);
|
||||
|
||||
@@ -43,7 +43,13 @@ describe("Kolide - API client (packs)", () => {
|
||||
describe("#create", () => {
|
||||
it("calls the correct endpoint with the correct parameters", () => {
|
||||
const { description, name } = packStub;
|
||||
const params = { description, name, host_ids: [], label_ids: [] };
|
||||
const params = {
|
||||
description,
|
||||
name,
|
||||
host_ids: [],
|
||||
label_ids: [],
|
||||
team_ids: [],
|
||||
};
|
||||
const request = packMocks.create.valid(bearerToken, params);
|
||||
|
||||
Fleet.setBearerToken(bearerToken);
|
||||
@@ -79,6 +85,7 @@ describe("Kolide - API client (packs)", () => {
|
||||
name: "New Pack Name",
|
||||
host_ids: [host2.id, hostStub.id],
|
||||
label_ids: [label2.id, labelStub.id],
|
||||
team_ids: [],
|
||||
};
|
||||
const request = packMocks.update.valid(
|
||||
bearerToken,
|
||||
|
||||
@@ -149,12 +149,13 @@ describe("Kolide API - helpers", () => {
|
||||
describe("#formatSelectedTargetsForApi", () => {
|
||||
const { formatSelectedTargetsForApi } = helpers;
|
||||
|
||||
it("splits targets into labels and hosts", () => {
|
||||
it("splits targets into labels, hosts, and teams", () => {
|
||||
const targets = [host1, host2, label1, label2];
|
||||
|
||||
expect(formatSelectedTargetsForApi(targets)).toEqual({
|
||||
hosts: [6, 5],
|
||||
labels: [1, 2],
|
||||
teams: [],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -164,6 +165,7 @@ describe("Kolide API - helpers", () => {
|
||||
expect(formatSelectedTargetsForApi(targets, true)).toEqual({
|
||||
host_ids: [6, 5],
|
||||
label_ids: [1, 2],
|
||||
team_ids: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -174,12 +174,13 @@ export const formatSelectedTargetsForApi = (
|
||||
const targets = selectedTargets || [];
|
||||
const hosts = flatMap(targets, filterTarget("hosts"));
|
||||
const labels = flatMap(targets, filterTarget("labels"));
|
||||
const teams = flatMap(targets, filterTarget("teams"));
|
||||
|
||||
if (appendID) {
|
||||
return { host_ids: hosts, label_ids: labels };
|
||||
return { host_ids: hosts, label_ids: labels, team_ids: teams };
|
||||
}
|
||||
|
||||
return { hosts, labels };
|
||||
return { hosts, labels, teams };
|
||||
};
|
||||
|
||||
export const formatScheduledQueryForServer = (scheduledQuery: any) => {
|
||||
|
||||
@@ -6,12 +6,14 @@ const defaultParams = {
|
||||
selected: {
|
||||
hosts: [],
|
||||
labels: [],
|
||||
teams: [],
|
||||
},
|
||||
};
|
||||
const defaultResponse = {
|
||||
targets: {
|
||||
hosts: [],
|
||||
labels: [],
|
||||
teams: [],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user