business-as-code 2.1.3 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/package.json +16 -13
- package/src/dollar.ts +5 -2
- package/src/entities/organization.ts +31 -18
- package/src/goals.ts +78 -12
- package/src/index.ts +48 -18
- package/src/kpis.ts +62 -8
- package/src/metrics.ts +92 -79
- package/src/okrs.ts +120 -20
- package/src/organization.ts +12 -15
- package/src/process.ts +11 -12
- package/src/product.ts +8 -9
- package/src/queries.ts +238 -75
- package/src/roles.ts +62 -61
- package/src/workflow.ts +22 -15
- package/test/business.test.ts +282 -0
- package/test/dollar.test.ts +270 -0
- package/test/entities.test.ts +628 -0
- package/test/financials.test.ts +539 -0
- package/test/goals.test.ts +451 -0
- package/{src → test}/index.test.ts +1 -1
- package/test/kpis.test.ts +440 -0
- package/test/metrics.test.ts +744 -0
- package/test/okrs.test.ts +741 -0
- package/test/organization.test.ts +548 -0
- package/test/process.test.ts +503 -0
- package/test/product.test.ts +430 -0
- package/test/queries.test.ts +556 -0
- package/test/roles.test.ts +546 -0
- package/test/service.test.ts +450 -0
- package/test/types.test.ts +1141 -0
- package/test/vision.test.ts +214 -0
- package/test/workflow.test.ts +501 -0
- package/vitest.config.ts +47 -0
- package/.turbo/turbo-build.log +0 -5
- package/LICENSE +0 -21
- package/dist/business.d.ts +0 -62
- package/dist/business.d.ts.map +0 -1
- package/dist/business.js +0 -109
- package/dist/business.js.map +0 -1
- package/dist/canvas/activities.d.ts +0 -19
- package/dist/canvas/activities.d.ts.map +0 -1
- package/dist/canvas/activities.js +0 -20
- package/dist/canvas/activities.js.map +0 -1
- package/dist/canvas/channels.d.ts +0 -20
- package/dist/canvas/channels.d.ts.map +0 -1
- package/dist/canvas/channels.js +0 -21
- package/dist/canvas/channels.js.map +0 -1
- package/dist/canvas/relationships.d.ts +0 -20
- package/dist/canvas/relationships.d.ts.map +0 -1
- package/dist/canvas/relationships.js +0 -21
- package/dist/canvas/relationships.js.map +0 -1
- package/dist/canvas/resources.d.ts +0 -20
- package/dist/canvas/resources.d.ts.map +0 -1
- package/dist/canvas/resources.js +0 -30
- package/dist/canvas/resources.js.map +0 -1
- package/dist/canvas/revenue.d.ts +0 -22
- package/dist/canvas/revenue.d.ts.map +0 -1
- package/dist/canvas/revenue.js +0 -30
- package/dist/canvas/revenue.js.map +0 -1
- package/dist/canvas/segments.d.ts +0 -20
- package/dist/canvas/segments.d.ts.map +0 -1
- package/dist/canvas/segments.js +0 -28
- package/dist/canvas/segments.js.map +0 -1
- package/dist/canvas/types.d.ts +0 -232
- package/dist/canvas/types.d.ts.map +0 -1
- package/dist/canvas/types.js +0 -8
- package/dist/canvas/types.js.map +0 -1
- package/dist/canvas/value.d.ts +0 -20
- package/dist/canvas/value.d.ts.map +0 -1
- package/dist/canvas/value.js +0 -21
- package/dist/canvas/value.js.map +0 -1
- package/dist/dollar.d.ts +0 -60
- package/dist/dollar.d.ts.map +0 -1
- package/dist/dollar.js +0 -107
- package/dist/dollar.js.map +0 -1
- package/dist/entities/assets.d.ts +0 -21
- package/dist/entities/assets.d.ts.map +0 -1
- package/dist/entities/assets.js +0 -323
- package/dist/entities/assets.js.map +0 -1
- package/dist/entities/business.d.ts +0 -36
- package/dist/entities/business.d.ts.map +0 -1
- package/dist/entities/business.js +0 -370
- package/dist/entities/business.js.map +0 -1
- package/dist/entities/communication.d.ts +0 -21
- package/dist/entities/communication.d.ts.map +0 -1
- package/dist/entities/communication.js +0 -255
- package/dist/entities/communication.js.map +0 -1
- package/dist/entities/customers.d.ts +0 -58
- package/dist/entities/customers.d.ts.map +0 -1
- package/dist/entities/customers.js +0 -989
- package/dist/entities/customers.js.map +0 -1
- package/dist/entities/financials.d.ts +0 -59
- package/dist/entities/financials.d.ts.map +0 -1
- package/dist/entities/financials.js +0 -932
- package/dist/entities/financials.js.map +0 -1
- package/dist/entities/goals.d.ts +0 -58
- package/dist/entities/goals.d.ts.map +0 -1
- package/dist/entities/goals.js +0 -800
- package/dist/entities/goals.js.map +0 -1
- package/dist/entities/index.d.ts +0 -299
- package/dist/entities/index.d.ts.map +0 -1
- package/dist/entities/index.js +0 -198
- package/dist/entities/index.js.map +0 -1
- package/dist/entities/legal.d.ts +0 -21
- package/dist/entities/legal.d.ts.map +0 -1
- package/dist/entities/legal.js +0 -301
- package/dist/entities/legal.js.map +0 -1
- package/dist/entities/market.d.ts +0 -21
- package/dist/entities/market.d.ts.map +0 -1
- package/dist/entities/market.js +0 -301
- package/dist/entities/market.js.map +0 -1
- package/dist/entities/marketing.d.ts +0 -67
- package/dist/entities/marketing.d.ts.map +0 -1
- package/dist/entities/marketing.js +0 -1157
- package/dist/entities/marketing.js.map +0 -1
- package/dist/entities/offerings.d.ts +0 -51
- package/dist/entities/offerings.d.ts.map +0 -1
- package/dist/entities/offerings.js +0 -727
- package/dist/entities/offerings.js.map +0 -1
- package/dist/entities/operations.d.ts +0 -58
- package/dist/entities/operations.d.ts.map +0 -1
- package/dist/entities/operations.js +0 -787
- package/dist/entities/operations.js.map +0 -1
- package/dist/entities/organization.d.ts +0 -57
- package/dist/entities/organization.d.ts.map +0 -1
- package/dist/entities/organization.js +0 -807
- package/dist/entities/organization.js.map +0 -1
- package/dist/entities/partnerships.d.ts +0 -21
- package/dist/entities/partnerships.d.ts.map +0 -1
- package/dist/entities/partnerships.js +0 -300
- package/dist/entities/partnerships.js.map +0 -1
- package/dist/entities/planning.d.ts +0 -0
- package/dist/entities/planning.d.ts.map +0 -1
- package/dist/entities/planning.js +0 -271
- package/dist/entities/planning.js.map +0 -1
- package/dist/entities/projects.d.ts +0 -25
- package/dist/entities/projects.d.ts.map +0 -1
- package/dist/entities/projects.js +0 -349
- package/dist/entities/projects.js.map +0 -1
- package/dist/entities/risk.d.ts +0 -21
- package/dist/entities/risk.d.ts.map +0 -1
- package/dist/entities/risk.js +0 -293
- package/dist/entities/risk.js.map +0 -1
- package/dist/entities/sales.d.ts +0 -72
- package/dist/entities/sales.d.ts.map +0 -1
- package/dist/entities/sales.js +0 -1248
- package/dist/entities/sales.js.map +0 -1
- package/dist/financials.d.ts +0 -130
- package/dist/financials.d.ts.map +0 -1
- package/dist/financials.js +0 -297
- package/dist/financials.js.map +0 -1
- package/dist/goals.d.ts +0 -87
- package/dist/goals.d.ts.map +0 -1
- package/dist/goals.js +0 -215
- package/dist/goals.js.map +0 -1
- package/dist/index.d.ts +0 -97
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -132
- package/dist/index.js.map +0 -1
- package/dist/kpis.d.ts +0 -118
- package/dist/kpis.d.ts.map +0 -1
- package/dist/kpis.js +0 -232
- package/dist/kpis.js.map +0 -1
- package/dist/metrics.d.ts +0 -448
- package/dist/metrics.d.ts.map +0 -1
- package/dist/metrics.js +0 -325
- package/dist/metrics.js.map +0 -1
- package/dist/okrs.d.ts +0 -123
- package/dist/okrs.d.ts.map +0 -1
- package/dist/okrs.js +0 -269
- package/dist/okrs.js.map +0 -1
- package/dist/organization.d.ts +0 -585
- package/dist/organization.d.ts.map +0 -1
- package/dist/organization.js +0 -173
- package/dist/organization.js.map +0 -1
- package/dist/process.d.ts +0 -112
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -241
- package/dist/process.js.map +0 -1
- package/dist/product.d.ts +0 -85
- package/dist/product.d.ts.map +0 -1
- package/dist/product.js +0 -145
- package/dist/product.js.map +0 -1
- package/dist/queries.d.ts +0 -304
- package/dist/queries.d.ts.map +0 -1
- package/dist/queries.js +0 -415
- package/dist/queries.js.map +0 -1
- package/dist/roles.d.ts +0 -340
- package/dist/roles.d.ts.map +0 -1
- package/dist/roles.js +0 -255
- package/dist/roles.js.map +0 -1
- package/dist/service.d.ts +0 -61
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -140
- package/dist/service.js.map +0 -1
- package/dist/types.d.ts +0 -459
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/vision.d.ts +0 -38
- package/dist/vision.d.ts.map +0 -1
- package/dist/vision.js +0 -68
- package/dist/vision.js.map +0 -1
- package/dist/workflow.d.ts +0 -115
- package/dist/workflow.d.ts.map +0 -1
- package/dist/workflow.js +0 -247
- package/dist/workflow.js.map +0 -1
- package/src/business.js +0 -108
- package/src/canvas/activities.ts +0 -32
- package/src/canvas/canvas.ts +0 -482
- package/src/canvas/channels.ts +0 -34
- package/src/canvas/costs.ts +0 -43
- package/src/canvas/economics.ts +0 -99
- package/src/canvas/index.ts +0 -206
- package/src/canvas/partnerships.ts +0 -34
- package/src/canvas/projections.ts +0 -141
- package/src/canvas/relationships.ts +0 -34
- package/src/canvas/resources.ts +0 -43
- package/src/canvas/revenue.ts +0 -56
- package/src/canvas/segments.ts +0 -42
- package/src/canvas/types.ts +0 -363
- package/src/canvas/value.ts +0 -34
- package/src/dollar.js +0 -106
- package/src/entities/assets.js +0 -322
- package/src/entities/business.js +0 -369
- package/src/entities/communication.js +0 -254
- package/src/entities/customers.js +0 -988
- package/src/entities/financials.js +0 -931
- package/src/entities/goals.js +0 -799
- package/src/entities/index.js +0 -197
- package/src/entities/legal.js +0 -300
- package/src/entities/market.js +0 -300
- package/src/entities/marketing.js +0 -1156
- package/src/entities/offerings.js +0 -726
- package/src/entities/operations.js +0 -786
- package/src/entities/organization.js +0 -806
- package/src/entities/partnerships.js +0 -299
- package/src/entities/planning.js +0 -270
- package/src/entities/projects.js +0 -348
- package/src/entities/risk.js +0 -292
- package/src/entities/sales.js +0 -1247
- package/src/financials.js +0 -296
- package/src/goals.js +0 -214
- package/src/index.js +0 -131
- package/src/index.test.js +0 -274
- package/src/kpis.js +0 -231
- package/src/metrics.js +0 -324
- package/src/okrs.js +0 -268
- package/src/organization.js +0 -172
- package/src/process.js +0 -240
- package/src/product.js +0 -144
- package/src/queries.js +0 -414
- package/src/roles.js +0 -254
- package/src/service.js +0 -139
- package/src/types.js +0 -4
- package/src/vision.js +0 -67
- package/src/workflow.js +0 -246
- package/tests/canvas.test.ts +0 -842
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for process.ts - Business process definition and management
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
Process,
|
|
8
|
+
getStepsInOrder,
|
|
9
|
+
getStepsByAutomationLevel,
|
|
10
|
+
calculateTotalDuration,
|
|
11
|
+
formatDuration,
|
|
12
|
+
calculateAutomationPercentage,
|
|
13
|
+
getMetric,
|
|
14
|
+
meetsTarget,
|
|
15
|
+
calculateMetricAchievement,
|
|
16
|
+
updateMetric,
|
|
17
|
+
addStep,
|
|
18
|
+
removeStep,
|
|
19
|
+
validateProcess,
|
|
20
|
+
} from '../src/process.js'
|
|
21
|
+
import type { ProcessDefinition, ProcessStep, ProcessMetric } from '../src/types.js'
|
|
22
|
+
|
|
23
|
+
describe('Process', () => {
|
|
24
|
+
describe('Process()', () => {
|
|
25
|
+
it('should create a process with required fields', () => {
|
|
26
|
+
const process = Process({ name: 'Test Process' })
|
|
27
|
+
|
|
28
|
+
expect(process.name).toBe('Test Process')
|
|
29
|
+
expect(process.category).toBe('support')
|
|
30
|
+
expect(process.steps).toEqual([])
|
|
31
|
+
expect(process.inputs).toEqual([])
|
|
32
|
+
expect(process.outputs).toEqual([])
|
|
33
|
+
expect(process.metrics).toEqual([])
|
|
34
|
+
expect(process.metadata).toEqual({})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should create a process with all fields', () => {
|
|
38
|
+
const process = Process({
|
|
39
|
+
name: 'Customer Onboarding',
|
|
40
|
+
description: 'Onboard new customers',
|
|
41
|
+
category: 'core',
|
|
42
|
+
owner: 'Customer Success',
|
|
43
|
+
steps: [
|
|
44
|
+
{ order: 1, name: 'Welcome Email', automationLevel: 'automated' },
|
|
45
|
+
{ order: 2, name: 'Setup Call', automationLevel: 'manual' },
|
|
46
|
+
],
|
|
47
|
+
inputs: ['Customer Info', 'Subscription Plan'],
|
|
48
|
+
outputs: ['Configured Account'],
|
|
49
|
+
metrics: [{ name: 'Time to Value', target: 24, unit: 'hours' }],
|
|
50
|
+
metadata: { version: 1 },
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
expect(process.name).toBe('Customer Onboarding')
|
|
54
|
+
expect(process.category).toBe('core')
|
|
55
|
+
expect(process.steps).toHaveLength(2)
|
|
56
|
+
expect(process.inputs).toHaveLength(2)
|
|
57
|
+
expect(process.outputs).toHaveLength(1)
|
|
58
|
+
expect(process.metrics).toHaveLength(1)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should throw error if name is missing', () => {
|
|
62
|
+
expect(() => Process({ name: '' })).toThrow('Process name is required')
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe('getStepsInOrder()', () => {
|
|
67
|
+
const process = Process({
|
|
68
|
+
name: 'Test',
|
|
69
|
+
steps: [
|
|
70
|
+
{ order: 3, name: 'Third' },
|
|
71
|
+
{ order: 1, name: 'First' },
|
|
72
|
+
{ order: 2, name: 'Second' },
|
|
73
|
+
],
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('should return steps sorted by order', () => {
|
|
77
|
+
const sorted = getStepsInOrder(process)
|
|
78
|
+
|
|
79
|
+
expect(sorted[0]?.name).toBe('First')
|
|
80
|
+
expect(sorted[1]?.name).toBe('Second')
|
|
81
|
+
expect(sorted[2]?.name).toBe('Third')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should handle empty steps', () => {
|
|
85
|
+
const emptyProcess = Process({ name: 'Empty' })
|
|
86
|
+
const sorted = getStepsInOrder(emptyProcess)
|
|
87
|
+
|
|
88
|
+
expect(sorted).toEqual([])
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('getStepsByAutomationLevel()', () => {
|
|
93
|
+
const process = Process({
|
|
94
|
+
name: 'Test',
|
|
95
|
+
steps: [
|
|
96
|
+
{ order: 1, name: 'Step 1', automationLevel: 'automated' },
|
|
97
|
+
{ order: 2, name: 'Step 2', automationLevel: 'manual' },
|
|
98
|
+
{ order: 3, name: 'Step 3', automationLevel: 'automated' },
|
|
99
|
+
{ order: 4, name: 'Step 4', automationLevel: 'semi-automated' },
|
|
100
|
+
],
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should filter by automated level', () => {
|
|
104
|
+
const automated = getStepsByAutomationLevel(process, 'automated')
|
|
105
|
+
|
|
106
|
+
expect(automated).toHaveLength(2)
|
|
107
|
+
expect(automated[0]?.name).toBe('Step 1')
|
|
108
|
+
expect(automated[1]?.name).toBe('Step 3')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('should filter by manual level', () => {
|
|
112
|
+
const manual = getStepsByAutomationLevel(process, 'manual')
|
|
113
|
+
|
|
114
|
+
expect(manual).toHaveLength(1)
|
|
115
|
+
expect(manual[0]?.name).toBe('Step 2')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('should return empty for non-existent level', () => {
|
|
119
|
+
const emptyProcess = Process({ name: 'Empty' })
|
|
120
|
+
const result = getStepsByAutomationLevel(emptyProcess, 'automated')
|
|
121
|
+
|
|
122
|
+
expect(result).toEqual([])
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe('calculateTotalDuration()', () => {
|
|
127
|
+
it('should calculate total duration in minutes', () => {
|
|
128
|
+
const process = Process({
|
|
129
|
+
name: 'Test',
|
|
130
|
+
steps: [
|
|
131
|
+
{ order: 1, name: 'Step 1', duration: '5 minutes' },
|
|
132
|
+
{ order: 2, name: 'Step 2', duration: '30 minutes' },
|
|
133
|
+
{ order: 3, name: 'Step 3', duration: '1 hour' },
|
|
134
|
+
],
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
expect(calculateTotalDuration(process)).toBe(95)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('should handle hours', () => {
|
|
141
|
+
const process = Process({
|
|
142
|
+
name: 'Test',
|
|
143
|
+
steps: [{ order: 1, name: 'Step 1', duration: '2 hours' }],
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
expect(calculateTotalDuration(process)).toBe(120)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('should handle days', () => {
|
|
150
|
+
const process = Process({
|
|
151
|
+
name: 'Test',
|
|
152
|
+
steps: [{ order: 1, name: 'Step 1', duration: '1 day' }],
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
expect(calculateTotalDuration(process)).toBe(1440)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should handle weeks', () => {
|
|
159
|
+
const process = Process({
|
|
160
|
+
name: 'Test',
|
|
161
|
+
steps: [{ order: 1, name: 'Step 1', duration: '1 week' }],
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
expect(calculateTotalDuration(process)).toBe(10080)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('should handle missing duration', () => {
|
|
168
|
+
const process = Process({
|
|
169
|
+
name: 'Test',
|
|
170
|
+
steps: [
|
|
171
|
+
{ order: 1, name: 'Step 1' },
|
|
172
|
+
{ order: 2, name: 'Step 2', duration: '10 minutes' },
|
|
173
|
+
],
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
expect(calculateTotalDuration(process)).toBe(10)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('should return 0 for empty steps', () => {
|
|
180
|
+
const process = Process({ name: 'Test' })
|
|
181
|
+
expect(calculateTotalDuration(process)).toBe(0)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('should handle singular/plural units', () => {
|
|
185
|
+
const process = Process({
|
|
186
|
+
name: 'Test',
|
|
187
|
+
steps: [
|
|
188
|
+
{ order: 1, name: 'Step 1', duration: '1 minute' },
|
|
189
|
+
{ order: 2, name: 'Step 2', duration: '1 hour' },
|
|
190
|
+
{ order: 3, name: 'Step 3', duration: '1 day' },
|
|
191
|
+
],
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
expect(calculateTotalDuration(process)).toBe(1 + 60 + 1440)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('should handle abbreviations', () => {
|
|
198
|
+
const process = Process({
|
|
199
|
+
name: 'Test',
|
|
200
|
+
steps: [
|
|
201
|
+
{ order: 1, name: 'Step 1', duration: '5 min' },
|
|
202
|
+
{ order: 2, name: 'Step 2', duration: '1 hr' },
|
|
203
|
+
],
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
expect(calculateTotalDuration(process)).toBe(65)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
describe('formatDuration()', () => {
|
|
211
|
+
it('should format minutes', () => {
|
|
212
|
+
expect(formatDuration(45)).toBe('45 minutes')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('should format hours', () => {
|
|
216
|
+
expect(formatDuration(120)).toBe('2 hours')
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('should format hours and minutes', () => {
|
|
220
|
+
expect(formatDuration(150)).toBe('2 hours 30 minutes')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('should format days', () => {
|
|
224
|
+
expect(formatDuration(2880)).toBe('2 days')
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it('should format days and hours', () => {
|
|
228
|
+
expect(formatDuration(1560)).toBe('1 days 2 hours')
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
describe('calculateAutomationPercentage()', () => {
|
|
233
|
+
it('should calculate percentage of automated steps', () => {
|
|
234
|
+
const process = Process({
|
|
235
|
+
name: 'Test',
|
|
236
|
+
steps: [
|
|
237
|
+
{ order: 1, name: 'Step 1', automationLevel: 'automated' },
|
|
238
|
+
{ order: 2, name: 'Step 2', automationLevel: 'automated' },
|
|
239
|
+
{ order: 3, name: 'Step 3', automationLevel: 'manual' },
|
|
240
|
+
{ order: 4, name: 'Step 4', automationLevel: 'semi-automated' },
|
|
241
|
+
],
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
expect(calculateAutomationPercentage(process)).toBe(75)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('should return 0 for empty steps', () => {
|
|
248
|
+
const process = Process({ name: 'Test' })
|
|
249
|
+
expect(calculateAutomationPercentage(process)).toBe(0)
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('should return 100 for fully automated process', () => {
|
|
253
|
+
const process = Process({
|
|
254
|
+
name: 'Test',
|
|
255
|
+
steps: [
|
|
256
|
+
{ order: 1, name: 'Step 1', automationLevel: 'automated' },
|
|
257
|
+
{ order: 2, name: 'Step 2', automationLevel: 'semi-automated' },
|
|
258
|
+
],
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
expect(calculateAutomationPercentage(process)).toBe(100)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('should return 0 for fully manual process', () => {
|
|
265
|
+
const process = Process({
|
|
266
|
+
name: 'Test',
|
|
267
|
+
steps: [
|
|
268
|
+
{ order: 1, name: 'Step 1', automationLevel: 'manual' },
|
|
269
|
+
{ order: 2, name: 'Step 2', automationLevel: 'manual' },
|
|
270
|
+
],
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
expect(calculateAutomationPercentage(process)).toBe(0)
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
describe('getMetric()', () => {
|
|
278
|
+
const process = Process({
|
|
279
|
+
name: 'Test',
|
|
280
|
+
metrics: [
|
|
281
|
+
{ name: 'Time to Value', target: 24 },
|
|
282
|
+
{ name: 'Completion Rate', target: 90 },
|
|
283
|
+
],
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('should find metric by name', () => {
|
|
287
|
+
const metric = getMetric(process, 'Time to Value')
|
|
288
|
+
|
|
289
|
+
expect(metric?.name).toBe('Time to Value')
|
|
290
|
+
expect(metric?.target).toBe(24)
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
it('should return undefined for non-existent metric', () => {
|
|
294
|
+
const metric = getMetric(process, 'NonExistent')
|
|
295
|
+
expect(metric).toBeUndefined()
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
describe('meetsTarget()', () => {
|
|
300
|
+
it('should return true when current meets target', () => {
|
|
301
|
+
const metric: ProcessMetric = { name: 'Test', target: 90, current: 95 }
|
|
302
|
+
expect(meetsTarget(metric)).toBe(true)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
it('should return true when current equals target', () => {
|
|
306
|
+
const metric: ProcessMetric = { name: 'Test', target: 90, current: 90 }
|
|
307
|
+
expect(meetsTarget(metric)).toBe(true)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('should return false when current is below target', () => {
|
|
311
|
+
const metric: ProcessMetric = { name: 'Test', target: 90, current: 85 }
|
|
312
|
+
expect(meetsTarget(metric)).toBe(false)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
it('should return false when target is undefined', () => {
|
|
316
|
+
const metric: ProcessMetric = { name: 'Test', current: 90 }
|
|
317
|
+
expect(meetsTarget(metric)).toBe(false)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
it('should return false when current is undefined', () => {
|
|
321
|
+
const metric: ProcessMetric = { name: 'Test', target: 90 }
|
|
322
|
+
expect(meetsTarget(metric)).toBe(false)
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
describe('calculateMetricAchievement()', () => {
|
|
327
|
+
it('should calculate achievement percentage', () => {
|
|
328
|
+
const metric: ProcessMetric = { name: 'Test', target: 100, current: 75 }
|
|
329
|
+
expect(calculateMetricAchievement(metric)).toBe(75)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
it('should handle over-achievement', () => {
|
|
333
|
+
const metric: ProcessMetric = { name: 'Test', target: 100, current: 150 }
|
|
334
|
+
expect(calculateMetricAchievement(metric)).toBe(150)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it('should return 100 when target is 0', () => {
|
|
338
|
+
const metric: ProcessMetric = { name: 'Test', target: 0, current: 50 }
|
|
339
|
+
expect(calculateMetricAchievement(metric)).toBe(100)
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
it('should return 0 when values are undefined', () => {
|
|
343
|
+
const metric: ProcessMetric = { name: 'Test' }
|
|
344
|
+
expect(calculateMetricAchievement(metric)).toBe(0)
|
|
345
|
+
})
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
describe('updateMetric()', () => {
|
|
349
|
+
const process = Process({
|
|
350
|
+
name: 'Test',
|
|
351
|
+
metrics: [
|
|
352
|
+
{ name: 'Metric 1', target: 100, current: 50 },
|
|
353
|
+
{ name: 'Metric 2', target: 200, current: 100 },
|
|
354
|
+
],
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('should update metric current value', () => {
|
|
358
|
+
const updated = updateMetric(process, 'Metric 1', 75)
|
|
359
|
+
const metric = updated.metrics?.find((m) => m.name === 'Metric 1')
|
|
360
|
+
|
|
361
|
+
expect(metric?.current).toBe(75)
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('should not affect other metrics', () => {
|
|
365
|
+
const updated = updateMetric(process, 'Metric 1', 75)
|
|
366
|
+
const metric2 = updated.metrics?.find((m) => m.name === 'Metric 2')
|
|
367
|
+
|
|
368
|
+
expect(metric2?.current).toBe(100)
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
it('should handle non-existent metric', () => {
|
|
372
|
+
const updated = updateMetric(process, 'NonExistent', 75)
|
|
373
|
+
expect(updated.metrics).toHaveLength(2)
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
describe('addStep()', () => {
|
|
378
|
+
it('should add step to process', () => {
|
|
379
|
+
const process = Process({
|
|
380
|
+
name: 'Test',
|
|
381
|
+
steps: [{ order: 1, name: 'First' }],
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
const updated = addStep(process, { order: 2, name: 'Second' })
|
|
385
|
+
|
|
386
|
+
expect(updated.steps).toHaveLength(2)
|
|
387
|
+
expect(updated.steps?.[1]?.name).toBe('Second')
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
it('should add step to empty process', () => {
|
|
391
|
+
const process = Process({ name: 'Test' })
|
|
392
|
+
const updated = addStep(process, { order: 1, name: 'First' })
|
|
393
|
+
|
|
394
|
+
expect(updated.steps).toHaveLength(1)
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
describe('removeStep()', () => {
|
|
399
|
+
const process = Process({
|
|
400
|
+
name: 'Test',
|
|
401
|
+
steps: [
|
|
402
|
+
{ order: 1, name: 'First' },
|
|
403
|
+
{ order: 2, name: 'Second' },
|
|
404
|
+
{ order: 3, name: 'Third' },
|
|
405
|
+
],
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('should remove step by order', () => {
|
|
409
|
+
const updated = removeStep(process, 2)
|
|
410
|
+
|
|
411
|
+
expect(updated.steps).toHaveLength(2)
|
|
412
|
+
expect(updated.steps?.find((s) => s.order === 2)).toBeUndefined()
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
it('should handle removing non-existent step', () => {
|
|
416
|
+
const updated = removeStep(process, 99)
|
|
417
|
+
expect(updated.steps).toHaveLength(3)
|
|
418
|
+
})
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
describe('validateProcess()', () => {
|
|
422
|
+
it('should validate valid process', () => {
|
|
423
|
+
const process: ProcessDefinition = {
|
|
424
|
+
name: 'Valid Process',
|
|
425
|
+
steps: [
|
|
426
|
+
{ order: 1, name: 'Step 1' },
|
|
427
|
+
{ order: 2, name: 'Step 2' },
|
|
428
|
+
],
|
|
429
|
+
metrics: [{ name: 'Metric 1', target: 100, current: 50 }],
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const result = validateProcess(process)
|
|
433
|
+
expect(result.valid).toBe(true)
|
|
434
|
+
expect(result.errors).toHaveLength(0)
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
it('should fail if name is missing', () => {
|
|
438
|
+
const process: ProcessDefinition = { name: '' }
|
|
439
|
+
|
|
440
|
+
const result = validateProcess(process)
|
|
441
|
+
expect(result.valid).toBe(false)
|
|
442
|
+
expect(result.errors).toContain('Process name is required')
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
it('should fail if step has no name', () => {
|
|
446
|
+
const process: ProcessDefinition = {
|
|
447
|
+
name: 'Test',
|
|
448
|
+
steps: [{ order: 1, name: '' }],
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const result = validateProcess(process)
|
|
452
|
+
expect(result.valid).toBe(false)
|
|
453
|
+
expect(result.errors).toContain('Step at order 1 must have a name')
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('should fail for duplicate step orders', () => {
|
|
457
|
+
const process: ProcessDefinition = {
|
|
458
|
+
name: 'Test',
|
|
459
|
+
steps: [
|
|
460
|
+
{ order: 1, name: 'First' },
|
|
461
|
+
{ order: 1, name: 'Duplicate' },
|
|
462
|
+
],
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const result = validateProcess(process)
|
|
466
|
+
expect(result.valid).toBe(false)
|
|
467
|
+
expect(result.errors).toContain('Duplicate step order: 1')
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
it('should fail if metric has no name', () => {
|
|
471
|
+
const process: ProcessDefinition = {
|
|
472
|
+
name: 'Test',
|
|
473
|
+
metrics: [{ name: '', target: 100 }],
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const result = validateProcess(process)
|
|
477
|
+
expect(result.valid).toBe(false)
|
|
478
|
+
expect(result.errors).toContain('Metric must have a name')
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
it('should fail if metric target is negative', () => {
|
|
482
|
+
const process: ProcessDefinition = {
|
|
483
|
+
name: 'Test',
|
|
484
|
+
metrics: [{ name: 'Test Metric', target: -10 }],
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const result = validateProcess(process)
|
|
488
|
+
expect(result.valid).toBe(false)
|
|
489
|
+
expect(result.errors).toContain('Metric Test Metric target cannot be negative')
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
it('should fail if metric current is negative', () => {
|
|
493
|
+
const process: ProcessDefinition = {
|
|
494
|
+
name: 'Test',
|
|
495
|
+
metrics: [{ name: 'Test Metric', target: 100, current: -5 }],
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const result = validateProcess(process)
|
|
499
|
+
expect(result.valid).toBe(false)
|
|
500
|
+
expect(result.errors).toContain('Metric Test Metric current value cannot be negative')
|
|
501
|
+
})
|
|
502
|
+
})
|
|
503
|
+
})
|