-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathto-list-workflow-parameters.test.ts
More file actions
108 lines (89 loc) · 2.93 KB
/
to-list-workflow-parameters.test.ts
File metadata and controls
108 lines (89 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { parseISO } from 'date-fns';
import { afterEach } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import {
getLargestDurationUnit,
toListWorkflowParameters,
} from './to-list-workflow-parameters';
const executionStatusQuery = 'ExecutionStatus="Completed"';
const workflowIdQuery = 'WorkflowId="Hello"';
const workflowTypeQuery = 'WorkflowType="World"';
const workflowQuery = 'WorkflowId="Hello" and WorkflowType="World"';
const startTimeQuery = 'StartTime > "2022-04-18T17:45:18-06:00"';
const defaultParameters = {
workflowId: '',
workflowType: '',
executionStatus: null,
timeRange: undefined,
activityId: '',
};
describe('toListWorkflowParameters', () => {
afterEach(() => {
vi.clearAllMocks();
vi.useRealTimers();
});
it('should parse a query with an executionStatus', () => {
const result = toListWorkflowParameters(executionStatusQuery);
expect(result).toEqual({
...defaultParameters,
executionStatus: 'Completed',
});
});
it('should parse a query with an workflowId', () => {
const result = toListWorkflowParameters(workflowIdQuery);
expect(result).toEqual({ ...defaultParameters, workflowId: 'Hello' });
});
it('should parse a query with an workflowType', () => {
const result = toListWorkflowParameters(workflowTypeQuery);
expect(result).toEqual({ ...defaultParameters, workflowType: 'World' });
});
it('should parse a query with an workflowType', () => {
const result = toListWorkflowParameters(workflowQuery);
expect(result).toEqual({
...defaultParameters,
workflowId: 'Hello',
workflowType: 'World',
});
});
it('should parse a query with an startTime', () => {
vi.useFakeTimers().setSystemTime(
parseISO('2022-04-20T17:45:18-06:00').getTime(),
);
const result = toListWorkflowParameters(startTimeQuery);
expect(result).toEqual({ ...defaultParameters, timeRange: '2 days' });
});
it('should not throw if given an invalid start time', () => {
expect(() => {
toListWorkflowParameters('StartTime = "bogus"');
}).not.toThrow();
});
it('should console error if given an invalid start time', () => {
const spy = vi.spyOn(console, 'error');
toListWorkflowParameters('StartTime = "bogus"');
expect(spy).toHaveBeenCalled();
});
});
describe('getLargestDurationUnit', () => {
it('should return years if present', () => {
const duration: Duration = {
years: 1,
months: 2,
weeks: 3,
days: 4,
hours: 5,
minutes: 6,
seconds: 7,
};
expect(getLargestDurationUnit(duration)).toEqual({
years: 1,
});
});
it('should return undefined if not given a duration', () => {
expect(
getLargestDurationUnit(undefined as unknown as Duration),
).toBeUndefined();
});
it('should return undefined if not given a duration', () => {
expect(getLargestDurationUnit({} as unknown as Duration)).toBeUndefined();
});
});