Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ResourceType } from '../../../models/Common/types';
import { Execution } from '../../../models/Execution/types';
import {
isExecutionTaskOrWorkflow,
getTaskOrWorkflowName,
getTaskOrWorkflowVersion,
} from './executionContext';

const makeExecution = (overrides: {
launchPlanResourceType: ResourceType;
launchPlanName: string;
launchPlanVersion: string;
workflowIdName: string;
workflowIdVersion: string;
}): Execution =>
({
spec: {
launchPlan: {
resourceType: overrides.launchPlanResourceType,
name: overrides.launchPlanName,
version: overrides.launchPlanVersion,
},
},
closure: {
workflowId: {
name: overrides.workflowIdName,
version: overrides.workflowIdVersion,
},
},
}) as unknown as Execution;

describe('executionContext helpers', () => {
const taskExecution = makeExecution({
launchPlanResourceType: ResourceType.TASK,
launchPlanName: 'my-task',
launchPlanVersion: 'task-v1',
workflowIdName: 'my-workflow',
workflowIdVersion: 'wf-v1',
});

const workflowExecution = makeExecution({
launchPlanResourceType: ResourceType.WORKFLOW,
launchPlanName: 'my-launch-plan',
launchPlanVersion: 'lp-v1',
workflowIdName: 'my-workflow',
workflowIdVersion: 'wf-v1',
});

describe('isExecutionTaskOrWorkflow', () => {
it('returns TASK when launchPlan resourceType is TASK', () => {
expect(isExecutionTaskOrWorkflow(taskExecution)).toBe(ResourceType.TASK);
});

it('returns WORKFLOW when launchPlan resourceType is WORKFLOW', () => {
expect(isExecutionTaskOrWorkflow(workflowExecution)).toBe(ResourceType.WORKFLOW);
});
});

describe('getTaskOrWorkflowName', () => {
it('returns launchPlan name for task executions', () => {
expect(getTaskOrWorkflowName(taskExecution)).toBe('my-task');
});

it('returns workflowId name for workflow executions', () => {
expect(getTaskOrWorkflowName(workflowExecution)).toBe('my-workflow');
});
});

describe('getTaskOrWorkflowVersion', () => {
it('returns launchPlan version for task executions', () => {
expect(getTaskOrWorkflowVersion(taskExecution)).toBe('task-v1');
});

it('returns workflowId version for workflow executions', () => {
expect(getTaskOrWorkflowVersion(workflowExecution)).toBe('wf-v1');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ const getExecutionData = async (projectId: string, domainId: string, executionId
return executionData;
};

const isExecutionTaskOrWorkflow = (executionData: Execution) => {
export const isExecutionTaskOrWorkflow = (executionData: Execution) => {
return executionData.spec.launchPlan.resourceType === ResourceType.TASK
? ResourceType.TASK
: ResourceType.WORKFLOW;
};

const getTaskOrWorkflowName = (executionData: Execution): string => {
return executionData.spec.launchPlan.name;
export const getTaskOrWorkflowName = (executionData: Execution): string => {
if (isExecutionTaskOrWorkflow(executionData) === ResourceType.TASK) {
return executionData.spec.launchPlan.name;
}
return executionData.closure.workflowId.name;
};

const getTaskOrWorkflowVersion = (executionData: Execution): string => {
return executionData.spec.launchPlan.version;
export const getTaskOrWorkflowVersion = (executionData: Execution): string => {
if (isExecutionTaskOrWorkflow(executionData) === ResourceType.TASK) {
return executionData.spec.launchPlan.version;
}
return executionData.closure.workflowId.version;
};

const getExecutionValue = (location: Location) => {
Expand Down