Skip to content

Commit

Permalink
Remove residual tracking event refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Nov 30, 2020
1 parent 2388c34 commit 3d02d87
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const ParamsSchema = schema.object({
geoField: schema.string({ minLength: 1 }),
entity: schema.string({ minLength: 1 }),
dateField: schema.string({ minLength: 1 }),
trackingEvent: schema.string({ minLength: 1 }),
boundaryType: schema.string({ minLength: 1 }),
boundaryIndexTitle: schema.string({ minLength: 1 }),
boundaryIndexId: schema.string({ minLength: 1 }),
Expand All @@ -108,7 +107,6 @@ export interface GeoContainmentParams {
geoField: string;
entity: string;
dateField: string;
trackingEvent: string;
boundaryType: string;
boundaryIndexTitle: string;
boundaryIndexId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Logger } from 'src/core/server';
import { executeEsQueryFactory, getShapesFilters, OTHER_CATEGORY } from './es_query_builder';
import { AlertServices, AlertTypeState } from '../../../../alerts/server';
import { ActionGroupId, GEO_CONTAINMENT_ID, GeoContainmentParams } from './alert_type';
import { ResolvedActionGroup } from '../../../../alerts/common';

interface LatestEntityLocation {
location: number[];
Expand Down Expand Up @@ -158,10 +157,6 @@ export const getGeoContainmentExecutor = (log: Logger) =>
currIntervalStartTime,
currIntervalEndTime
);
// No need to compare if no changes in current interval
if (!_.get(currentIntervalResults, 'hits.total.value')) {
return state;
}

const currLocationMap: Map<string, EntityLocation> = transformResults(
currentIntervalResults,
Expand All @@ -171,6 +166,7 @@ export const getGeoContainmentExecutor = (log: Logger) =>

// Cycle through instances that received no updates and keep active
const activeAlertsList = state.activeAlertsList || {};

_.forEach(activeAlertsList, (val, key) => {
if (!currLocationMap.has(key)) {
const containingBoundaryName =
Expand All @@ -185,19 +181,17 @@ export const getGeoContainmentExecutor = (log: Logger) =>
const containingBoundaryName = shapesIdsNamesMap[shapeLocationId] || shapeLocationId;
const context = {
entityId: entityName,
entityDateTime: new Date(dateInShape),
entityDateTime: new Date(dateInShape).getTime(),
entityDocumentId: docId,
detectionDateTime: new Date(currIntervalEndTime),
detectionDateTime: new Date(currIntervalEndTime).getTime(),
entityLocation: `POINT (${location[0]} ${location[1]})`,
containingBoundaryId: shapeLocationId,
containingBoundaryName,
};
const alertInstanceId = `${entityName}-${containingBoundaryName}`;
if (shapeLocationId !== OTHER_CATEGORY) {
activeAlertsList[entityName] = context;
services
.alertInstanceFactory(alertInstanceId)
.scheduleActions(ResolvedActionGroup.id, context);
services.alertInstanceFactory(alertInstanceId).scheduleActions(ActionGroupId, context);
} else {
delete activeAlertsList[entityName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('alertType', () => {
geoField: 'testField',
entity: 'testField',
dateField: 'testField',
trackingEvent: 'testEvent',
boundaryType: 'testType',
boundaryIndexTitle: 'testIndex',
boundaryIndexId: 'testIndex',
Expand All @@ -40,27 +39,4 @@ describe('alertType', () => {

expect(alertType.validate?.params?.validate(params)).toBeTruthy();
});

it('validator fails with invalid params', async () => {
const paramsSchema = alertType.validate?.params;
if (!paramsSchema) throw new Error('params validator not set');

const params: GeoContainmentParams = {
index: 'testIndex',
indexId: 'testIndexId',
geoField: 'testField',
entity: 'testField',
dateField: 'testField',
trackingEvent: '',
boundaryType: 'testType',
boundaryIndexTitle: '',
boundaryIndexId: 'testIndex',
boundaryGeoField: 'testField',
boundaryNameField: 'testField',
};

expect(() => paramsSchema.validate(params)).toThrowErrorMatchingInlineSnapshot(
`"[trackingEvent]: value has length [0] but it must have a minimum length of [1]."`
);
});
});

0 comments on commit 3d02d87

Please sign in to comment.