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:
noahtalerman
2021-06-10 11:37:25 -04:00
committed by GitHub
parent 78fb7e22cc
commit 7104d0312e
5 changed files with 19 additions and 6 deletions
@@ -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);
+8 -1
View File
@@ -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,
+3 -1
View File
@@ -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: [],
});
});
});
+3 -2
View File
@@ -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) => {
+2
View File
@@ -6,12 +6,14 @@ const defaultParams = {
selected: {
hosts: [],
labels: [],
teams: [],
},
};
const defaultResponse = {
targets: {
hosts: [],
labels: [],
teams: [],
},
};