Skip to content

Commit

Permalink
Add basic test for isProcessTerminated selector
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Jul 27, 2020
1 parent 692736c commit 759bff5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
mockTreeWithNoAncestorsAnd2Children,
mockTreeWith2AncestorsAndNoChildren,
mockTreeWith1AncestorAnd2ChildrenAndAllNodesHave2GraphableEvents,
mockTreeWithAllProcessesTerminated,
} from '../mocks/resolver_tree';
import { uniquePidForProcess } from '../../models/process_event';
import { EndpointEvent } from '../../../../common/endpoint/types';
Expand Down Expand Up @@ -299,6 +300,34 @@ describe('data state', () => {
expect(selectors.ariaFlowtoCandidate(state())(secondAncestorID)).toBe(null);
});
});
describe('with a tree with all processes terminated', () => {
const originID = 'c';
const firstAncestorID = 'b';
const secondAncestorID = 'a';
beforeEach(() => {
actions.push({
type: 'serverReturnedResolverData',
payload: {
result: mockTreeWithAllProcessesTerminated({
originID,
firstAncestorID,
secondAncestorID,
}),
// this value doesn't matter
databaseDocumentID: '',
},
});
});
it('should have origin as terminated', () => {
expect(selectors.isProcessTerminated(state())(originID)).toBe(true);
});
it('should have first ancestor as termianted', () => {
expect(selectors.isProcessTerminated(state())(firstAncestorID)).toBe(true);
});
it('should have second ancestor as terminated', () => {
expect(selectors.isProcessTerminated(state())(secondAncestorID)).toBe(true);
});
});
describe('with a tree with 2 children and no ancestors', () => {
const originID = 'c';
const firstChildID = 'd';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ export function mockEndpointEvent({
name,
parentEntityId,
timestamp,
lifecycleType,
}: {
entityID: string;
name: string;
parentEntityId: string | undefined;
timestamp: number;
lifecycleType?: string;
}): EndpointEvent {
return {
'@timestamp': timestamp,
event: {
type: 'start',
type: lifecycleType ? lifecycleType : 'start',
category: 'process',
},
process: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,69 @@ export function mockTreeWith2AncestorsAndNoChildren({
} as unknown) as ResolverTree;
}

export function mockTreeWithAllProcessesTerminated({
originID,
firstAncestorID,
secondAncestorID,
}: {
secondAncestorID: string;
firstAncestorID: string;
originID: string;
}): ResolverTree {
const secondAncestor: ResolverEvent = mockEndpointEvent({
entityID: secondAncestorID,
name: 'a',
parentEntityId: 'none',
timestamp: 0,
});
const firstAncestor: ResolverEvent = mockEndpointEvent({
entityID: firstAncestorID,
name: 'b',
parentEntityId: secondAncestorID,
timestamp: 1,
});
const originEvent: ResolverEvent = mockEndpointEvent({
entityID: originID,
name: 'c',
parentEntityId: firstAncestorID,
timestamp: 2,
});
const secondAncestorTermination: ResolverEvent = mockEndpointEvent({
entityID: secondAncestorID,
name: 'a',
parentEntityId: 'none',
timestamp: 0,
lifecycleType: 'end',
});
const firstAncestorTermination: ResolverEvent = mockEndpointEvent({
entityID: firstAncestorID,
name: 'b',
parentEntityId: secondAncestorID,
timestamp: 1,
lifecycleType: 'end',
});
const originEventTermination: ResolverEvent = mockEndpointEvent({
entityID: originID,
name: 'c',
parentEntityId: firstAncestorID,
timestamp: 2,
lifecycleType: 'end',
});
return ({
entityID: originID,
children: {
childNodes: [],
},
ancestry: {
ancestors: [
{ lifecycle: [secondAncestor, secondAncestorTermination] },
{ lifecycle: [firstAncestor, firstAncestorTermination] },
],
},
lifecycle: [originEvent, originEventTermination],
} as unknown) as ResolverTree;
}

export function mockTreeWithNoAncestorsAnd2Children({
originID,
firstChildID,
Expand Down

0 comments on commit 759bff5

Please sign in to comment.