Skip to content

Commit

Permalink
Add tests for cases involving multiple final locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Jan 25, 2021
1 parent 8439114 commit cb24ca6
Showing 1 changed file with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ describe('geo_containment', () => {
expect(allActiveEntriesMap.has('d')).toBeTruthy();
expect(testAlertActionArr).toMatchObject(expectedContextPlusD);
});

it('should remove "other" entries and schedule the expected number of actions', () => {
const emptyPrevLocationMap = new Map();
const currLocationMapWithOther = new Map([...currLocationMap]).set('d', [
Expand All @@ -332,5 +333,106 @@ describe('geo_containment', () => {
expect(allActiveEntriesMap).toEqual(currLocationMap);
expect(testAlertActionArr).toMatchObject(expectedContext);
});

it('should generate multiple alerts per entity if found in multiple shapes in interval', () => {
const emptyPrevLocationMap = new Map();
const currLocationMapWithThreeMore = new Map([...currLocationMap]).set('d', [
{
location: [0, 0],
shapeLocationId: '789',
dateInShape: 'Wed Dec 10 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
{
location: [0, 0],
shapeLocationId: '123',
dateInShape: 'Wed Dec 08 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId2',
},
{
location: [0, 0],
shapeLocationId: '456',
dateInShape: 'Wed Dec 07 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId3',
},
]);
getActiveEntriesAndGenerateAlerts(
emptyPrevLocationMap,
currLocationMapWithThreeMore,
alertInstanceFactory,
emptyShapesIdsNamesMap,
currentDateTime
);
let numEntitiesInShapes = 0;
currLocationMapWithThreeMore.forEach((v) => {
numEntitiesInShapes += v.length;
});
expect(testAlertActionArr.length).toEqual(numEntitiesInShapes);
});

it('should not return entity as active entry if most recent location is "other"', () => {
const emptyPrevLocationMap = new Map();
const currLocationMapWithOther = new Map([...currLocationMap]).set('d', [
{
location: [0, 0],
shapeLocationId: OTHER_CATEGORY,
dateInShape: 'Wed Dec 10 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
{
location: [0, 0],
shapeLocationId: '123',
dateInShape: 'Wed Dec 08 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
{
location: [0, 0],
shapeLocationId: '456',
dateInShape: 'Wed Dec 07 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
]);
expect(currLocationMapWithOther).not.toEqual(currLocationMap);
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
emptyPrevLocationMap,
currLocationMapWithOther,
alertInstanceFactory,
emptyShapesIdsNamesMap,
currentDateTime
);
expect(allActiveEntriesMap).toEqual(currLocationMap);
});

it('should return entity as active entry if "other" not the latest location', () => {
const emptyPrevLocationMap = new Map();
const currLocationMapWithOther = new Map([...currLocationMap]).set('d', [
{
location: [0, 0],
shapeLocationId: '123',
dateInShape: 'Wed Dec 10 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
{
location: [0, 0],
shapeLocationId: OTHER_CATEGORY,
dateInShape: 'Wed Dec 08 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
{
location: [0, 0],
shapeLocationId: '456',
dateInShape: 'Wed Dec 07 2020 14:31:31 GMT-0700 (Mountain Standard Time)',
docId: 'docId1',
},
]);
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
emptyPrevLocationMap,
currLocationMapWithOther,
alertInstanceFactory,
emptyShapesIdsNamesMap,
currentDateTime
);
expect(allActiveEntriesMap).toEqual(currLocationMapWithOther);
});
});
});

0 comments on commit cb24ca6

Please sign in to comment.