Skip to content

Commit

Permalink
feat(UA-9134): added the getFailedInstances call in the datahealth re…
Browse files Browse the repository at this point in the history
…source (#861)

* feat(UA-9134): added the getFailedInstances call in the datahealth resource

* feat(UA-9134): added more comments

* Update src/resources/UsageAnalytics/Read/DataHealth/tests/DataHealth.spec.ts

Co-authored-by: Marie Payne <[email protected]>

* Update src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts

Co-authored-by: Marie Payne <[email protected]>

* feat(UA-9134): review changes

* feat(UA-9134): review changes

* feat(UA-8134): small fix

---------

Co-authored-by: Marie Payne <[email protected]>
  • Loading branch information
AdamMartineau-Coveo and mpayne-coveo authored Sep 26, 2024
1 parent fe32d54 commit ad1a21c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/resources/UsageAnalytics/Read/DataHealth/DataHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import ReadServiceResource from '../ReadServiceResource.js';
import {
DataHealthEventPayloadResponse,
DataHealthGetEventPayloadParams,
DataHealthGetFailedInstancesParams,
DataHealthGetFailedInstancesResponse,
DataHealthGetGroupDetailParams,
DataHealthGetGroupDetailResponse,
DataHealthGetGroupListingParams,
Expand All @@ -22,7 +24,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get health information about events.
*/
listEvents(params: DataHealthListEventsParameters, args?: RequestInit) {
listEvents(params: DataHealthListEventsParameters) {
return this.api.get<DataHealthListEventsResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/events`, params),
);
Expand All @@ -31,7 +33,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get original event payload.
*/
getEventPayload(params: DataHealthGetEventPayloadParams, args?: RequestInit) {
getEventPayload(params: DataHealthGetEventPayloadParams) {
return this.api.get<DataHealthEventPayloadResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/events/payload`, params),
);
Expand All @@ -40,7 +42,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* List applicable facet values in the specified time range.
*/
listFacetValues(params: DataHealthListFacetValueParams, args?: RequestInit) {
listFacetValues(params: DataHealthListFacetValueParams) {
return this.api.get<DataHealthListFacetsResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/facets`, params),
);
Expand All @@ -49,7 +51,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get general data health information.
*/
getOverview(params: DataHealthGetOverviewParams, args?: RequestInit) {
getOverview(params: DataHealthGetOverviewParams) {
return this.api.get<DataHealthGetOverviewResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/overview`, params),
);
Expand All @@ -58,7 +60,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get health information about groups of validation rules.
*/
getGroupListing(params: DataHealthGetGroupListingParams, args?: RequestInit) {
getGroupListing(params: DataHealthGetGroupListingParams) {
return this.api.get<DataHealthGetGroupListingResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/groups`, params),
);
Expand All @@ -67,7 +69,7 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get health information about validation rules of a specific group.
*/
getGroupDetail(params: DataHealthGetGroupDetailParams, args?: RequestInit) {
getGroupDetail(params: DataHealthGetGroupDetailParams) {
return this.api.get<DataHealthGetGroupDetailResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/groups/detail`, params),
);
Expand All @@ -76,12 +78,23 @@ export default class DataHealth extends ReadServiceResource {
/**
* Get a list of unique tracking ids.
*/
getTrackingIds(params: DataHealthGetTrackingIdsParams, args?: RequestInit) {
getTrackingIds(params: DataHealthGetTrackingIdsParams) {
return this.api.get<DataHealthGetTrackingIdsResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/facets`, {...params, facet: 'TRACKING_ID'}),
);
}

/**
* Get failed instances for a data health criterion
*
* @param params Parameters to fetch data health failed instances.
*/
getFailedInstances(params: DataHealthGetFailedInstancesParams) {
return this.api.get<DataHealthGetFailedInstancesResponse>(
this.buildPathWithOrg(`${DataHealth.baseUrl}/criteria/failedInstances`, params),
);
}

/**
* Build the request path, handling the optional `org` query parameter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,57 @@ export interface DataHealthGetTrackingIdsResponse {
*/
values: DataHealthFacetValue[];
}

export interface DataHealthGetFailedInstancesParams extends OrganizationParamParts, TimeRangeParamParts, Paginated {
/**
* The data health criterion for which the failed instances should be returned.
*/
criterionId: string;
/**
* The group for which data health information should be returned.
*/
group: string;
/**
* Optional value of the criterion scope for which failed instances should be returned.
*/
scopeValue?: string;
/**
* Optional set of tracking IDs for which the results should be returned.
*/
trackingId?: string[];
}

export interface DataHealthGetFailedInstancesResponse extends PaginatedResponse {
/**
* A collection of failed instances.
*/
failedInstances: DataHealthFailedInstanceEntry[];
}

export interface DataHealthFailedInstanceEntry {
/**
* The timestamp of the failed instance.
*/
timestamp: string;
/**
* The ID of the event.
*/
eventId: string;
/**
* The ID of the visit.
*/
visitId: string;
/**
* The client ID of the event.
*/
clientId: string;
/**
* The scope of the datahealth rule.
*/
scope: DataHealthRuleScope;
}

/**
* The scope of a datahealth rule.
*/
type DataHealthRuleScope = 'EVENT' | 'VISIT';
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import API from '../../../../../APICore.js';
import DataHealth from '../DataHealth.js';
import {
DataHealthGetEventPayloadParams,
DataHealthGetFailedInstancesParams,
DataHealthGetGroupDetailParams,
DataHealthGetGroupListingParams,
DataHealthGetOverviewParams,
Expand Down Expand Up @@ -125,4 +126,19 @@ describe('DataHealth', () => {
);
});
});

describe('getFailedInstances', () => {
it('should make a GET call to the data health get failed instances url', async () => {
const datahealthGetFailedInstancesParams: DataHealthGetFailedInstancesParams = {
...baseParams,
criterionId: 'criterion',
group: 'group',
};
await dataHealth.getFailedInstances(datahealthGetFailedInstancesParams);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${DataHealth.baseUrl}/criteria/failedInstances?org=someOrgId&from=1986-04-26T01%3A23%3A58.000Z&to=1986-04-27T02%3A32%3A15.000Z&criterionId=criterion&group=group`,
);
});
});
});

0 comments on commit ad1a21c

Please sign in to comment.