Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat Sharma committed Apr 3, 2024
1 parent 14b8eeb commit 0eda66f
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 92 deletions.
30 changes: 18 additions & 12 deletions public/services/IndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ import { MDSEnabledClientService } from "./MDSEnabledClientService";
export default class IndexService extends MDSEnabledClientService {
getIndices = async (queryObject: HttpFetchQuery): Promise<ServerResponse<GetIndicesResponse>> => {
let url = `..${NODE_API._INDICES}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
return (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetIndicesResponse>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
return (await this.httpClient.get(url, params)) as ServerResponse<GetIndicesResponse>;
};

getDataStreams = async (queryObject: HttpFetchQuery): Promise<ServerResponse<GetDataStreamsResponse>> => {
const url = `..${NODE_API._DATA_STREAMS}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
return await this.httpClient.get(url, { query: queryObject });
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
return await this.httpClient.get(url, params);
};

getAliases = async (queryObject: HttpFetchQuery): Promise<ServerResponse<GetAliasesResponse>> => {
const url = `..${NODE_API._ALIASES}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
return await this.httpClient.get(url, { query: queryObject });
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
return await this.httpClient.get(url, params);
};

getDataStreamsAndIndicesNames = async (searchValue: string): Promise<ServerResponse<GetDataStreamsAndIndicesNamesResponse>> => {
Expand Down Expand Up @@ -88,28 +91,31 @@ export default class IndexService extends MDSEnabledClientService {

applyPolicy = async (indices: string[], policyId: string, queryObject?: HttpFetchQuery): Promise<ServerResponse<ApplyPolicyResponse>> => {
const body = { indices, policyId };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const url = `..${NODE_API.APPLY_POLICY}`;
return (await this.httpClient.post(url, {
body: JSON.stringify(body),
query: queryObject,
...params,
})) as ServerResponse<ApplyPolicyResponse>;
};

editRolloverAlias = async (index: string, alias: string, queryObject?: HttpFetchQuery): Promise<ServerResponse<AcknowledgedResponse>> => {
const body = { index, alias };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const url = `..${NODE_API.EDIT_ROLLOVER_ALIAS}`;
return (await this.httpClient.post(url, {
body: JSON.stringify(body),
query: queryObject,
...params,
})) as ServerResponse<AcknowledgedResponse>;
};

searchPolicies = async (searchValue: string, source: boolean = false): Promise<ServerResponse<GetPoliciesResponse>> => {
const str = searchValue.trim();
const queryObject = this.patchQueryObjectWithDataSourceId({ from: 0, size: 10, search: str, sortDirection: "desc", sortField: "id" });
const query = this.patchQueryObjectWithDataSourceId({ from: 0, size: 10, search: str, sortDirection: "desc", sortField: "id" });
const params = query ? { query } : {};
const url = `..${NODE_API.POLICIES}`;
return (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetPoliciesResponse>;
return (await this.httpClient.get(url, params)) as ServerResponse<GetPoliciesResponse>;
};
}
2 changes: 1 addition & 1 deletion public/services/MDSEnabledClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export abstract class MDSEnabledClientService {
}

patchQueryObjectWithDataSourceId(queryObject?: HttpFetchQuery): HttpFetchQuery | undefined {
queryObject = queryObject || {};
if (this.mdsEnabled) {
queryObject = queryObject || {};
queryObject.dataSourceId = this.dataSourceId;
}
return queryObject;
Expand Down
4 changes: 2 additions & 2 deletions public/services/ManagedIndexService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("ManagedIndexService spec", () => {
await managedIndexService.getManagedIndex(managedIndexUuid);

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.MANAGED_INDICES}/${managedIndexUuid}`);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.MANAGED_INDICES}/${managedIndexUuid}`, expect.anything());
});

it("calls get managed indices nodejs route when calling getManagedIndices", async () => {
Expand All @@ -33,7 +33,7 @@ describe("ManagedIndexService spec", () => {
await managedIndexService.getDataStreams();

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API._DATA_STREAMS}`);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API._DATA_STREAMS}`, expect.anything());
});

it("calls retry policy nodejs route when calling retryManagedIndexPolicy", async () => {
Expand Down
31 changes: 18 additions & 13 deletions public/services/ManagedIndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ import { MDSEnabledClientService } from "./MDSEnabledClientService";
export default class ManagedIndexService extends MDSEnabledClientService {
getManagedIndex = async (managedIndexUuid: string, queryObject: HttpFetchQuery | undefined): Promise<ServerResponse<any>> => {
let url = `..${NODE_API.MANAGED_INDICES}/${managedIndexUuid}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<any>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<any>;
return response;
};

getManagedIndices = async (queryObject: HttpFetchQuery | undefined): Promise<ServerResponse<GetManagedIndicesResponse>> => {
let url = `..${NODE_API.MANAGED_INDICES}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
console.log("queryObject", queryObject);
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetManagedIndicesResponse>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<GetManagedIndicesResponse>;
return response;
};

getDataStreams = async (queryObject: HttpFetchQuery | undefined): Promise<ServerResponse<GetDataStreamsResponse>> => {
let url = `..${NODE_API._DATA_STREAMS}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetDataStreamsResponse>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<GetDataStreamsResponse>;
return response;
};

Expand All @@ -44,20 +46,22 @@ export default class ManagedIndexService extends MDSEnabledClientService {
queryObject: HttpFetchQuery | undefined
): Promise<ServerResponse<RetryManagedIndexResponse>> => {
const body = { index, state };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.post(`..${NODE_API.RETRY}`, {
body: JSON.stringify(body),
query: queryObject,
...params,
})) as ServerResponse<RetryManagedIndexResponse>;
return response;
};

removePolicy = async (indices: string[], queryObject: HttpFetchQuery | undefined): Promise<ServerResponse<RemovePolicyResponse>> => {
const body = { indices };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.post(`..${NODE_API.REMOVE_POLICY}`, {
body: JSON.stringify(body),
query: queryObject,
...params,
})) as ServerResponse<RemovePolicyResponse>;
return response;
};
Expand All @@ -70,10 +74,11 @@ export default class ManagedIndexService extends MDSEnabledClientService {
queryObject?: HttpFetchQuery | undefined
): Promise<ServerResponse<ChangePolicyResponse>> => {
const body = { indices, policyId, state, include };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.post(`..${NODE_API.CHANGE_POLICY}`, {
body: JSON.stringify(body),
query: queryObject,
...params,
})) as ServerResponse<ChangePolicyResponse>;
return response;
};
Expand Down
2 changes: 1 addition & 1 deletion public/services/NotificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ describe("NotificationService spec", () => {
await notificationService.getChannels();

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.CHANNELS}`);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.CHANNELS}`, expect.anything());
});
});
10 changes: 6 additions & 4 deletions public/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import { MDSEnabledClientService } from "./MDSEnabledClientService";
export default class NotificationService extends MDSEnabledClientService {
getChannels = async (): Promise<ServerResponse<GetChannelsResponse>> => {
let url = `..${NODE_API.CHANNELS}`;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetChannelsResponse>;
const query = this.patchQueryObjectWithDataSourceId();
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<GetChannelsResponse>;
return response;
};

getChannel = async (channelId: string): Promise<ServerResponse<GetNotificationConfigsResponse>> => {
let url = `..${NODE_API.CHANNELS}/${channelId}`;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetNotificationConfigsResponse>;
const query = this.patchQueryObjectWithDataSourceId();
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<GetNotificationConfigsResponse>;
return response;
};
}
4 changes: 2 additions & 2 deletions public/services/PolicyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("PolicyService spec", () => {
await policyService.getPolicy(policyId);

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}`);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}`, expect.anything());
});

it("calls get policies nodejs route when calling getPolicies", async () => {
Expand Down Expand Up @@ -44,6 +44,6 @@ describe("PolicyService spec", () => {
await policyService.deletePolicy(policyId);

expect(httpClientMock.delete).toHaveBeenCalledTimes(1);
expect(httpClientMock.delete).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}`);
expect(httpClientMock.delete).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}`, expect.anything());
});
});
23 changes: 12 additions & 11 deletions public/services/PolicyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { MDSEnabledClientService } from "./MDSEnabledClientService";
export default class PolicyService extends MDSEnabledClientService {
getPolicies = async (queryObject: HttpFetchQuery | undefined): Promise<ServerResponse<GetPoliciesResponse>> => {
let url = `..${NODE_API.POLICIES}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetPoliciesResponse>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<GetPoliciesResponse>;
return response;
};

Expand All @@ -26,25 +27,25 @@ export default class PolicyService extends MDSEnabledClientService {
): Promise<ServerResponse<PutPolicyResponse>> => {
let url = `..${NODE_API.POLICIES}/${policyId}`;
let queryObject: HttpFetchQuery | undefined = { seqNo, primaryTerm };
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
console.log("PolicyService putPolicy queryObject: ", queryObject);
const response = (await this.httpClient.put(url, { query: queryObject, body: JSON.stringify(policy) })) as ServerResponse<
PutPolicyResponse
>;
const query = this.patchQueryObjectWithDataSourceId(queryObject);
const params = query ? { query } : {};
const response = (await this.httpClient.put(url, { body: JSON.stringify(policy), ...params })) as ServerResponse<PutPolicyResponse>;
return response;
};

getPolicy = async (policyId: string): Promise<ServerResponse<DocumentPolicy>> => {
const url = `..${NODE_API.POLICIES}/${policyId}`;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<DocumentPolicy>;
const query = this.patchQueryObjectWithDataSourceId();
const params = query ? { query } : {};
const response = (await this.httpClient.get(url, params)) as ServerResponse<DocumentPolicy>;
return response;
};

deletePolicy = async (policyId: string): Promise<ServerResponse<boolean>> => {
const url = `..${NODE_API.POLICIES}/${policyId}`;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.delete(url, { query: queryObject })) as ServerResponse<boolean>;
const query = this.patchQueryObjectWithDataSourceId();
const params = query ? { query } : {};
const response = (await this.httpClient.delete(url, params)) as ServerResponse<boolean>;
return response;
};
}
8 changes: 4 additions & 4 deletions public/services/RollupService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("rollupService spec", () => {
await rollupService.getRollup(rollupId);

expect(httpClientMock.get).toHaveBeenCalledTimes(1);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}`);
expect(httpClientMock.get).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}`, expect.anything());
});

it("calls get rollups nodejs route when calling getRollups", async () => {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("rollupService spec", () => {
await rollupService.deleteRollup(rollupId);

expect(httpClientMock.delete).toHaveBeenCalledTimes(1);
expect(httpClientMock.delete).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}`);
expect(httpClientMock.delete).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}`, expect.anything());
});

it("calls start rollup nodejs route when calling startRollup", async () => {
Expand All @@ -56,7 +56,7 @@ describe("rollupService spec", () => {
await rollupService.startRollup(rollupId);

expect(httpClientMock.post).toHaveBeenCalledTimes(1);
expect(httpClientMock.post).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}/_start`);
expect(httpClientMock.post).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}/_start`, expect.anything());
});

it("calls stop rollup nodejs route when calling stopRollup", async () => {
Expand All @@ -65,7 +65,7 @@ describe("rollupService spec", () => {
await rollupService.stopRollup(rollupId);

expect(httpClientMock.post).toHaveBeenCalledTimes(1);
expect(httpClientMock.post).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}/_stop`);
expect(httpClientMock.post).toHaveBeenCalledWith(`..${NODE_API.ROLLUPS}/${rollupId}/_stop`, expect.anything());
});

it("calls get mappings nodejs route when calling getMappings", async () => {
Expand Down
Loading

0 comments on commit 0eda66f

Please sign in to comment.