business-as-code 2.1.3 → 2.4.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.
Files changed (235) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +53 -0
  3. package/README.md +2 -0
  4. package/dist/dollar.d.ts.map +1 -1
  5. package/dist/dollar.js +2 -2
  6. package/dist/dollar.js.map +1 -1
  7. package/dist/entities/organization.d.ts +4 -0
  8. package/dist/entities/organization.d.ts.map +1 -1
  9. package/dist/entities/organization.js +27 -18
  10. package/dist/entities/organization.js.map +1 -1
  11. package/dist/entities/planning.d.ts +87 -0
  12. package/dist/finance/account.d.ts +44 -0
  13. package/dist/finance/account.d.ts.map +1 -0
  14. package/dist/finance/account.js +6 -0
  15. package/dist/finance/account.js.map +1 -0
  16. package/dist/finance/authority.d.ts +78 -0
  17. package/dist/finance/authority.d.ts.map +1 -0
  18. package/dist/finance/authority.js +27 -0
  19. package/dist/finance/authority.js.map +1 -0
  20. package/dist/finance/card.d.ts +36 -0
  21. package/dist/finance/card.d.ts.map +1 -0
  22. package/dist/finance/card.js +6 -0
  23. package/dist/finance/card.js.map +1 -0
  24. package/dist/finance/identity.d.ts +30 -0
  25. package/dist/finance/identity.d.ts.map +1 -0
  26. package/dist/finance/identity.js +8 -0
  27. package/dist/finance/identity.js.map +1 -0
  28. package/dist/finance/index.d.ts +36 -0
  29. package/dist/finance/index.d.ts.map +1 -0
  30. package/dist/finance/index.js +22 -0
  31. package/dist/finance/index.js.map +1 -0
  32. package/dist/finance/ledger.d.ts +24 -0
  33. package/dist/finance/ledger.d.ts.map +1 -0
  34. package/dist/finance/ledger.js +8 -0
  35. package/dist/finance/ledger.js.map +1 -0
  36. package/dist/finance/merchant.d.ts +129 -0
  37. package/dist/finance/merchant.d.ts.map +1 -0
  38. package/dist/finance/merchant.js +21 -0
  39. package/dist/finance/merchant.js.map +1 -0
  40. package/dist/finance/outcome-contract.d.ts +139 -0
  41. package/dist/finance/outcome-contract.d.ts.map +1 -0
  42. package/dist/finance/outcome-contract.js +27 -0
  43. package/dist/finance/outcome-contract.js.map +1 -0
  44. package/dist/finance/port.d.ts +121 -0
  45. package/dist/finance/port.d.ts.map +1 -0
  46. package/dist/finance/port.js +10 -0
  47. package/dist/finance/port.js.map +1 -0
  48. package/dist/finance/pricing.d.ts +154 -0
  49. package/dist/finance/pricing.d.ts.map +1 -0
  50. package/dist/finance/pricing.js +79 -0
  51. package/dist/finance/pricing.js.map +1 -0
  52. package/dist/finance/proof-predicate.d.ts +92 -0
  53. package/dist/finance/proof-predicate.d.ts.map +1 -0
  54. package/dist/finance/proof-predicate.js +80 -0
  55. package/dist/finance/proof-predicate.js.map +1 -0
  56. package/dist/finance/refund.d.ts +44 -0
  57. package/dist/finance/refund.d.ts.map +1 -0
  58. package/dist/finance/refund.js +41 -0
  59. package/dist/finance/refund.js.map +1 -0
  60. package/dist/finance/sla.d.ts +25 -0
  61. package/dist/finance/sla.d.ts.map +1 -0
  62. package/dist/finance/sla.js +7 -0
  63. package/dist/finance/sla.js.map +1 -0
  64. package/dist/finance/types.d.ts +79 -0
  65. package/dist/finance/types.d.ts.map +1 -0
  66. package/dist/finance/types.js +8 -0
  67. package/dist/{canvas → finance}/types.js.map +1 -1
  68. package/dist/goals.d.ts +19 -0
  69. package/dist/goals.d.ts.map +1 -1
  70. package/dist/goals.js +81 -12
  71. package/dist/goals.js.map +1 -1
  72. package/dist/index.d.ts +12 -8
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +19 -7
  75. package/dist/index.js.map +1 -1
  76. package/dist/kpis.d.ts +19 -0
  77. package/dist/kpis.d.ts.map +1 -1
  78. package/dist/kpis.js +71 -6
  79. package/dist/kpis.js.map +1 -1
  80. package/dist/metrics.d.ts.map +1 -1
  81. package/dist/metrics.js +29 -24
  82. package/dist/metrics.js.map +1 -1
  83. package/dist/okrs.d.ts +34 -0
  84. package/dist/okrs.d.ts.map +1 -1
  85. package/dist/okrs.js +135 -13
  86. package/dist/okrs.js.map +1 -1
  87. package/dist/organization.d.ts.map +1 -1
  88. package/dist/organization.js +11 -11
  89. package/dist/organization.js.map +1 -1
  90. package/dist/process.d.ts.map +1 -1
  91. package/dist/process.js +13 -12
  92. package/dist/process.js.map +1 -1
  93. package/dist/product.d.ts.map +1 -1
  94. package/dist/product.js +9 -9
  95. package/dist/product.js.map +1 -1
  96. package/dist/queries.d.ts.map +1 -1
  97. package/dist/queries.js +194 -32
  98. package/dist/queries.js.map +1 -1
  99. package/dist/roles.d.ts +25 -31
  100. package/dist/roles.d.ts.map +1 -1
  101. package/dist/roles.js +37 -10
  102. package/dist/roles.js.map +1 -1
  103. package/dist/workflow.d.ts.map +1 -1
  104. package/dist/workflow.js +13 -12
  105. package/dist/workflow.js.map +1 -1
  106. package/package.json +20 -13
  107. package/src/dollar.ts +5 -2
  108. package/src/entities/organization.ts +31 -18
  109. package/src/finance/account.ts +48 -0
  110. package/src/finance/authority.ts +42 -0
  111. package/src/finance/card.ts +38 -0
  112. package/src/finance/identity.ts +31 -0
  113. package/src/finance/index.ts +117 -0
  114. package/src/finance/ledger.ts +26 -0
  115. package/src/finance/merchant.ts +127 -0
  116. package/src/finance/outcome-contract.ts +157 -0
  117. package/src/finance/port.ts +144 -0
  118. package/src/finance/pricing.ts +197 -0
  119. package/src/finance/proof-predicate.ts +106 -0
  120. package/src/finance/refund.ts +52 -0
  121. package/src/finance/sla.ts +33 -0
  122. package/src/finance/types.ts +75 -0
  123. package/src/goals.ts +78 -12
  124. package/src/index.ts +48 -18
  125. package/src/kpis.ts +62 -8
  126. package/src/metrics.ts +92 -79
  127. package/src/okrs.ts +120 -20
  128. package/src/organization.ts +12 -15
  129. package/src/process.ts +11 -12
  130. package/src/product.ts +8 -9
  131. package/src/queries.ts +238 -75
  132. package/src/roles.ts +62 -61
  133. package/src/workflow.ts +22 -15
  134. package/test/business.test.ts +282 -0
  135. package/test/dollar.test.ts +270 -0
  136. package/test/entities.test.ts +628 -0
  137. package/test/financials.test.ts +539 -0
  138. package/test/goals.test.ts +451 -0
  139. package/{src → test}/index.test.ts +1 -1
  140. package/test/kpis.test.ts +440 -0
  141. package/test/metrics.test.ts +744 -0
  142. package/test/okrs.test.ts +741 -0
  143. package/test/organization.test.ts +548 -0
  144. package/test/process.test.ts +503 -0
  145. package/test/product.test.ts +430 -0
  146. package/test/queries.test.ts +556 -0
  147. package/test/roles.test.ts +546 -0
  148. package/test/service.test.ts +450 -0
  149. package/test/types.test.ts +1141 -0
  150. package/test/vision.test.ts +214 -0
  151. package/test/workflow.test.ts +501 -0
  152. package/vitest.config.ts +47 -0
  153. package/LICENSE +0 -21
  154. package/dist/canvas/activities.d.ts +0 -19
  155. package/dist/canvas/activities.d.ts.map +0 -1
  156. package/dist/canvas/activities.js +0 -20
  157. package/dist/canvas/activities.js.map +0 -1
  158. package/dist/canvas/channels.d.ts +0 -20
  159. package/dist/canvas/channels.d.ts.map +0 -1
  160. package/dist/canvas/channels.js +0 -21
  161. package/dist/canvas/channels.js.map +0 -1
  162. package/dist/canvas/relationships.d.ts +0 -20
  163. package/dist/canvas/relationships.d.ts.map +0 -1
  164. package/dist/canvas/relationships.js +0 -21
  165. package/dist/canvas/relationships.js.map +0 -1
  166. package/dist/canvas/resources.d.ts +0 -20
  167. package/dist/canvas/resources.d.ts.map +0 -1
  168. package/dist/canvas/resources.js +0 -30
  169. package/dist/canvas/resources.js.map +0 -1
  170. package/dist/canvas/revenue.d.ts +0 -22
  171. package/dist/canvas/revenue.d.ts.map +0 -1
  172. package/dist/canvas/revenue.js +0 -30
  173. package/dist/canvas/revenue.js.map +0 -1
  174. package/dist/canvas/segments.d.ts +0 -20
  175. package/dist/canvas/segments.d.ts.map +0 -1
  176. package/dist/canvas/segments.js +0 -28
  177. package/dist/canvas/segments.js.map +0 -1
  178. package/dist/canvas/types.d.ts +0 -232
  179. package/dist/canvas/types.d.ts.map +0 -1
  180. package/dist/canvas/types.js +0 -8
  181. package/dist/canvas/value.d.ts +0 -20
  182. package/dist/canvas/value.d.ts.map +0 -1
  183. package/dist/canvas/value.js +0 -21
  184. package/dist/canvas/value.js.map +0 -1
  185. package/src/business.js +0 -108
  186. package/src/canvas/activities.ts +0 -32
  187. package/src/canvas/canvas.ts +0 -482
  188. package/src/canvas/channels.ts +0 -34
  189. package/src/canvas/costs.ts +0 -43
  190. package/src/canvas/economics.ts +0 -99
  191. package/src/canvas/index.ts +0 -206
  192. package/src/canvas/partnerships.ts +0 -34
  193. package/src/canvas/projections.ts +0 -141
  194. package/src/canvas/relationships.ts +0 -34
  195. package/src/canvas/resources.ts +0 -43
  196. package/src/canvas/revenue.ts +0 -56
  197. package/src/canvas/segments.ts +0 -42
  198. package/src/canvas/types.ts +0 -363
  199. package/src/canvas/value.ts +0 -34
  200. package/src/dollar.js +0 -106
  201. package/src/entities/assets.js +0 -322
  202. package/src/entities/business.js +0 -369
  203. package/src/entities/communication.js +0 -254
  204. package/src/entities/customers.js +0 -988
  205. package/src/entities/financials.js +0 -931
  206. package/src/entities/goals.js +0 -799
  207. package/src/entities/index.js +0 -197
  208. package/src/entities/legal.js +0 -300
  209. package/src/entities/market.js +0 -300
  210. package/src/entities/marketing.js +0 -1156
  211. package/src/entities/offerings.js +0 -726
  212. package/src/entities/operations.js +0 -786
  213. package/src/entities/organization.js +0 -806
  214. package/src/entities/partnerships.js +0 -299
  215. package/src/entities/planning.js +0 -270
  216. package/src/entities/projects.js +0 -348
  217. package/src/entities/risk.js +0 -292
  218. package/src/entities/sales.js +0 -1247
  219. package/src/financials.js +0 -296
  220. package/src/goals.js +0 -214
  221. package/src/index.js +0 -131
  222. package/src/index.test.js +0 -274
  223. package/src/kpis.js +0 -231
  224. package/src/metrics.js +0 -324
  225. package/src/okrs.js +0 -268
  226. package/src/organization.js +0 -172
  227. package/src/process.js +0 -240
  228. package/src/product.js +0 -144
  229. package/src/queries.js +0 -414
  230. package/src/roles.js +0 -254
  231. package/src/service.js +0 -139
  232. package/src/types.js +0 -4
  233. package/src/vision.js +0 -67
  234. package/src/workflow.js +0 -246
  235. package/tests/canvas.test.ts +0 -842
@@ -0,0 +1,451 @@
1
+ /**
2
+ * Tests for goals.ts - Business goals definition and tracking
3
+ */
4
+
5
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
6
+ import {
7
+ Goals,
8
+ Goal,
9
+ updateProgress,
10
+ markAtRisk,
11
+ complete,
12
+ isOverdue,
13
+ getGoalsByCategory,
14
+ getGoalsByStatus,
15
+ getGoalsByOwner,
16
+ calculateOverallProgress,
17
+ hasCircularDependencies,
18
+ sortByDependencies,
19
+ validateGoals,
20
+ } from '../src/goals.js'
21
+ import type { GoalDefinition } from '../src/types.js'
22
+
23
+ describe('Goals', () => {
24
+ describe('Goals()', () => {
25
+ it('should create multiple goals', () => {
26
+ const goals = Goals([{ name: 'Goal 1' }, { name: 'Goal 2' }])
27
+
28
+ expect(goals).toHaveLength(2)
29
+ expect(goals[0]?.name).toBe('Goal 1')
30
+ expect(goals[1]?.name).toBe('Goal 2')
31
+ })
32
+
33
+ it('should normalize goal defaults', () => {
34
+ const goals = Goals([{ name: 'Test Goal' }])
35
+
36
+ expect(goals[0]?.category).toBe('operational')
37
+ expect(goals[0]?.status).toBe('not-started')
38
+ expect(goals[0]?.progress).toBe(0)
39
+ expect(goals[0]?.metrics).toEqual([])
40
+ expect(goals[0]?.dependencies).toEqual([])
41
+ expect(goals[0]?.metadata).toEqual({})
42
+ })
43
+
44
+ it('should preserve provided values', () => {
45
+ const goals = Goals([
46
+ {
47
+ name: 'Strategic Goal',
48
+ category: 'strategic',
49
+ status: 'in-progress',
50
+ progress: 50,
51
+ metrics: ['Revenue', 'Growth'],
52
+ },
53
+ ])
54
+
55
+ expect(goals[0]?.category).toBe('strategic')
56
+ expect(goals[0]?.status).toBe('in-progress')
57
+ expect(goals[0]?.progress).toBe(50)
58
+ expect(goals[0]?.metrics).toEqual(['Revenue', 'Growth'])
59
+ })
60
+
61
+ it('should throw error for goal without name', () => {
62
+ expect(() => Goals([{ name: '' }])).toThrow('Goal name is required')
63
+ })
64
+ })
65
+
66
+ describe('Goal()', () => {
67
+ it('should create a single goal', () => {
68
+ const goal = Goal({ name: 'Single Goal', category: 'financial' })
69
+
70
+ expect(goal.name).toBe('Single Goal')
71
+ expect(goal.category).toBe('financial')
72
+ })
73
+
74
+ it('should throw error for goal without name', () => {
75
+ expect(() => Goal({ name: '' })).toThrow('Goal name is required')
76
+ })
77
+ })
78
+
79
+ describe('updateProgress()', () => {
80
+ it('should update progress to 50%', () => {
81
+ const goal = Goal({ name: 'Test' })
82
+ const updated = updateProgress(goal, 50)
83
+
84
+ expect(updated.progress).toBe(50)
85
+ expect(updated.status).toBe('in-progress')
86
+ })
87
+
88
+ it('should mark as completed at 100%', () => {
89
+ const goal = Goal({ name: 'Test', status: 'in-progress' })
90
+ const updated = updateProgress(goal, 100)
91
+
92
+ expect(updated.progress).toBe(100)
93
+ expect(updated.status).toBe('completed')
94
+ })
95
+
96
+ it('should mark as not-started at 0%', () => {
97
+ const goal = Goal({ name: 'Test', status: 'in-progress', progress: 50 })
98
+ const updated = updateProgress(goal, 0)
99
+
100
+ expect(updated.progress).toBe(0)
101
+ expect(updated.status).toBe('not-started')
102
+ })
103
+
104
+ it('should throw error for progress below 0', () => {
105
+ const goal = Goal({ name: 'Test' })
106
+ expect(() => updateProgress(goal, -10)).toThrow('Progress must be between 0 and 100')
107
+ })
108
+
109
+ it('should throw error for progress above 100', () => {
110
+ const goal = Goal({ name: 'Test' })
111
+ expect(() => updateProgress(goal, 150)).toThrow('Progress must be between 0 and 100')
112
+ })
113
+
114
+ it('should handle edge case of exactly 0', () => {
115
+ const goal = Goal({ name: 'Test', progress: 50 })
116
+ const updated = updateProgress(goal, 0)
117
+
118
+ expect(updated.progress).toBe(0)
119
+ expect(updated.status).toBe('not-started')
120
+ })
121
+
122
+ it('should handle edge case of exactly 100', () => {
123
+ const goal = Goal({ name: 'Test' })
124
+ const updated = updateProgress(goal, 100)
125
+
126
+ expect(updated.progress).toBe(100)
127
+ expect(updated.status).toBe('completed')
128
+ })
129
+ })
130
+
131
+ describe('markAtRisk()', () => {
132
+ it('should mark goal as at-risk', () => {
133
+ const goal = Goal({ name: 'Test', status: 'in-progress' })
134
+ const updated = markAtRisk(goal)
135
+
136
+ expect(updated.status).toBe('at-risk')
137
+ })
138
+
139
+ it('should preserve other goal properties', () => {
140
+ const goal = Goal({ name: 'Test', progress: 50, owner: 'Alice' })
141
+ const updated = markAtRisk(goal)
142
+
143
+ expect(updated.name).toBe('Test')
144
+ expect(updated.progress).toBe(50)
145
+ expect(updated.owner).toBe('Alice')
146
+ })
147
+ })
148
+
149
+ describe('complete()', () => {
150
+ it('should mark goal as completed with 100% progress', () => {
151
+ const goal = Goal({ name: 'Test', status: 'in-progress', progress: 80 })
152
+ const updated = complete(goal)
153
+
154
+ expect(updated.status).toBe('completed')
155
+ expect(updated.progress).toBe(100)
156
+ })
157
+ })
158
+
159
+ describe('isOverdue()', () => {
160
+ beforeEach(() => {
161
+ vi.useFakeTimers()
162
+ vi.setSystemTime(new Date('2024-06-15'))
163
+ })
164
+
165
+ afterEach(() => {
166
+ vi.useRealTimers()
167
+ })
168
+
169
+ it('should return true for overdue goal', () => {
170
+ const goal = Goal({
171
+ name: 'Test',
172
+ targetDate: new Date('2024-06-01'),
173
+ status: 'in-progress',
174
+ })
175
+
176
+ expect(isOverdue(goal)).toBe(true)
177
+ })
178
+
179
+ it('should return false for goal with future target date', () => {
180
+ const goal = Goal({
181
+ name: 'Test',
182
+ targetDate: new Date('2024-12-31'),
183
+ status: 'in-progress',
184
+ })
185
+
186
+ expect(isOverdue(goal)).toBe(false)
187
+ })
188
+
189
+ it('should return false for completed goal even if past target date', () => {
190
+ const goal = Goal({
191
+ name: 'Test',
192
+ targetDate: new Date('2024-06-01'),
193
+ status: 'completed',
194
+ })
195
+
196
+ expect(isOverdue(goal)).toBe(false)
197
+ })
198
+
199
+ it('should return false for goal without target date', () => {
200
+ const goal = Goal({ name: 'Test' })
201
+ expect(isOverdue(goal)).toBe(false)
202
+ })
203
+ })
204
+
205
+ describe('getGoalsByCategory()', () => {
206
+ const goals = Goals([
207
+ { name: 'Goal 1', category: 'strategic' },
208
+ { name: 'Goal 2', category: 'operational' },
209
+ { name: 'Goal 3', category: 'strategic' },
210
+ { name: 'Goal 4', category: 'financial' },
211
+ ])
212
+
213
+ it('should filter goals by category', () => {
214
+ const strategic = getGoalsByCategory(goals, 'strategic')
215
+
216
+ expect(strategic).toHaveLength(2)
217
+ expect(strategic[0]?.name).toBe('Goal 1')
218
+ expect(strategic[1]?.name).toBe('Goal 3')
219
+ })
220
+
221
+ it('should return empty array for non-existent category', () => {
222
+ const learning = getGoalsByCategory(goals, 'learning')
223
+ expect(learning).toHaveLength(0)
224
+ })
225
+ })
226
+
227
+ describe('getGoalsByStatus()', () => {
228
+ const goals = Goals([
229
+ { name: 'Goal 1', status: 'in-progress' },
230
+ { name: 'Goal 2', status: 'completed' },
231
+ { name: 'Goal 3', status: 'in-progress' },
232
+ ])
233
+
234
+ it('should filter goals by status', () => {
235
+ const inProgress = getGoalsByStatus(goals, 'in-progress')
236
+
237
+ expect(inProgress).toHaveLength(2)
238
+ expect(inProgress[0]?.name).toBe('Goal 1')
239
+ expect(inProgress[1]?.name).toBe('Goal 3')
240
+ })
241
+
242
+ it('should return empty array for non-existent status', () => {
243
+ const cancelled = getGoalsByStatus(goals, 'cancelled')
244
+ expect(cancelled).toHaveLength(0)
245
+ })
246
+ })
247
+
248
+ describe('getGoalsByOwner()', () => {
249
+ const goals = Goals([
250
+ { name: 'Goal 1', owner: 'Alice' },
251
+ { name: 'Goal 2', owner: 'Bob' },
252
+ { name: 'Goal 3', owner: 'Alice' },
253
+ ])
254
+
255
+ it('should filter goals by owner', () => {
256
+ const aliceGoals = getGoalsByOwner(goals, 'Alice')
257
+
258
+ expect(aliceGoals).toHaveLength(2)
259
+ expect(aliceGoals[0]?.name).toBe('Goal 1')
260
+ expect(aliceGoals[1]?.name).toBe('Goal 3')
261
+ })
262
+
263
+ it('should return empty array for non-existent owner', () => {
264
+ const charlieGoals = getGoalsByOwner(goals, 'Charlie')
265
+ expect(charlieGoals).toHaveLength(0)
266
+ })
267
+ })
268
+
269
+ describe('calculateOverallProgress()', () => {
270
+ it('should return 0 for empty goals array', () => {
271
+ expect(calculateOverallProgress([])).toBe(0)
272
+ })
273
+
274
+ it('should calculate average progress', () => {
275
+ const goals = Goals([
276
+ { name: 'Goal 1', progress: 50 },
277
+ { name: 'Goal 2', progress: 100 },
278
+ ])
279
+
280
+ expect(calculateOverallProgress(goals)).toBe(75)
281
+ })
282
+
283
+ it('should handle goals with 0 progress', () => {
284
+ const goals = Goals([
285
+ { name: 'Goal 1', progress: 0 },
286
+ { name: 'Goal 2', progress: 100 },
287
+ ])
288
+
289
+ expect(calculateOverallProgress(goals)).toBe(50)
290
+ })
291
+
292
+ it('should handle single goal', () => {
293
+ const goals = Goals([{ name: 'Goal 1', progress: 75 }])
294
+ expect(calculateOverallProgress(goals)).toBe(75)
295
+ })
296
+ })
297
+
298
+ describe('hasCircularDependencies()', () => {
299
+ it('should return false for goals without dependencies', () => {
300
+ const goals = Goals([{ name: 'Goal 1' }, { name: 'Goal 2' }])
301
+
302
+ expect(hasCircularDependencies(goals)).toBe(false)
303
+ })
304
+
305
+ it('should return false for linear dependencies', () => {
306
+ const goals = Goals([
307
+ { name: 'Goal 1' },
308
+ { name: 'Goal 2', dependencies: ['Goal 1'] },
309
+ { name: 'Goal 3', dependencies: ['Goal 2'] },
310
+ ])
311
+
312
+ expect(hasCircularDependencies(goals)).toBe(false)
313
+ })
314
+
315
+ it('should detect direct circular dependency', () => {
316
+ const goals: GoalDefinition[] = [
317
+ { name: 'Goal 1', dependencies: ['Goal 2'] },
318
+ { name: 'Goal 2', dependencies: ['Goal 1'] },
319
+ ]
320
+
321
+ expect(hasCircularDependencies(goals)).toBe(true)
322
+ })
323
+
324
+ it('should detect indirect circular dependency', () => {
325
+ const goals: GoalDefinition[] = [
326
+ { name: 'Goal 1', dependencies: ['Goal 3'] },
327
+ { name: 'Goal 2', dependencies: ['Goal 1'] },
328
+ { name: 'Goal 3', dependencies: ['Goal 2'] },
329
+ ]
330
+
331
+ expect(hasCircularDependencies(goals)).toBe(true)
332
+ })
333
+
334
+ it('should handle self-referencing dependency', () => {
335
+ const goals: GoalDefinition[] = [{ name: 'Goal 1', dependencies: ['Goal 1'] }]
336
+
337
+ expect(hasCircularDependencies(goals)).toBe(true)
338
+ })
339
+ })
340
+
341
+ describe('sortByDependencies()', () => {
342
+ it('should return goals in dependency order', () => {
343
+ const goals = Goals([
344
+ { name: 'Goal C', dependencies: ['Goal B'] },
345
+ { name: 'Goal A' },
346
+ { name: 'Goal B', dependencies: ['Goal A'] },
347
+ ])
348
+
349
+ const sorted = sortByDependencies(goals)
350
+
351
+ expect(sorted[0]?.name).toBe('Goal A')
352
+ expect(sorted[1]?.name).toBe('Goal B')
353
+ expect(sorted[2]?.name).toBe('Goal C')
354
+ })
355
+
356
+ it('should handle goals without dependencies', () => {
357
+ const goals = Goals([{ name: 'Goal B' }, { name: 'Goal A' }])
358
+
359
+ const sorted = sortByDependencies(goals)
360
+
361
+ expect(sorted).toHaveLength(2)
362
+ })
363
+
364
+ it('should handle complex dependency graph', () => {
365
+ const goals = Goals([
366
+ { name: 'Deploy', dependencies: ['Test', 'Build'] },
367
+ { name: 'Build', dependencies: ['Design'] },
368
+ { name: 'Design' },
369
+ { name: 'Test', dependencies: ['Build'] },
370
+ ])
371
+
372
+ const sorted = sortByDependencies(goals)
373
+
374
+ // Design should come before Build
375
+ const designIndex = sorted.findIndex((g) => g.name === 'Design')
376
+ const buildIndex = sorted.findIndex((g) => g.name === 'Build')
377
+ const testIndex = sorted.findIndex((g) => g.name === 'Test')
378
+ const deployIndex = sorted.findIndex((g) => g.name === 'Deploy')
379
+
380
+ expect(designIndex).toBeLessThan(buildIndex)
381
+ expect(buildIndex).toBeLessThan(testIndex)
382
+ expect(testIndex).toBeLessThan(deployIndex)
383
+ })
384
+ })
385
+
386
+ describe('validateGoals()', () => {
387
+ it('should validate valid goals', () => {
388
+ const goals = Goals([
389
+ { name: 'Goal 1', progress: 50 },
390
+ { name: 'Goal 2', progress: 75 },
391
+ ])
392
+
393
+ const result = validateGoals(goals)
394
+ expect(result.valid).toBe(true)
395
+ expect(result.errors).toHaveLength(0)
396
+ })
397
+
398
+ it('should fail for goal without name', () => {
399
+ const goals: GoalDefinition[] = [{ name: '' }]
400
+ const result = validateGoals(goals)
401
+
402
+ expect(result.valid).toBe(false)
403
+ expect(result.errors).toContain('Goal name is required')
404
+ })
405
+
406
+ it('should fail for progress out of range', () => {
407
+ const goals: GoalDefinition[] = [{ name: 'Test', progress: 150 }]
408
+ const result = validateGoals(goals)
409
+
410
+ expect(result.valid).toBe(false)
411
+ expect(result.errors).toContain('Goal Test progress must be between 0 and 100')
412
+ })
413
+
414
+ it('should fail for negative progress', () => {
415
+ const goals: GoalDefinition[] = [{ name: 'Test', progress: -10 }]
416
+ const result = validateGoals(goals)
417
+
418
+ expect(result.valid).toBe(false)
419
+ })
420
+
421
+ it('should fail for unknown dependency', () => {
422
+ const goals: GoalDefinition[] = [{ name: 'Goal 1', dependencies: ['NonExistent'] }]
423
+ const result = validateGoals(goals)
424
+
425
+ expect(result.valid).toBe(false)
426
+ expect(result.errors).toContain('Goal Goal 1 depends on unknown goal: NonExistent')
427
+ })
428
+
429
+ it('should fail for circular dependencies', () => {
430
+ const goals: GoalDefinition[] = [
431
+ { name: 'Goal 1', dependencies: ['Goal 2'] },
432
+ { name: 'Goal 2', dependencies: ['Goal 1'] },
433
+ ]
434
+ const result = validateGoals(goals)
435
+
436
+ expect(result.valid).toBe(false)
437
+ expect(result.errors).toContain('Circular dependencies detected in goals')
438
+ })
439
+
440
+ it('should return multiple errors', () => {
441
+ const goals: GoalDefinition[] = [
442
+ { name: '', progress: 150 },
443
+ { name: 'Goal 2', dependencies: ['NonExistent'] },
444
+ ]
445
+ const result = validateGoals(goals)
446
+
447
+ expect(result.valid).toBe(false)
448
+ expect(result.errors.length).toBeGreaterThan(1)
449
+ })
450
+ })
451
+ })
@@ -20,7 +20,7 @@ import {
20
20
  updateProgress,
21
21
  calculateOKRProgress,
22
22
  updateKeyResult,
23
- } from './index.js'
23
+ } from '../src/index.js'
24
24
 
25
25
  describe('Business', () => {
26
26
  it('should create a business entity', () => {