business-as-code 2.1.1 → 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.
Files changed (212) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -0
  3. package/package.json +7 -4
  4. package/src/dollar.ts +5 -2
  5. package/src/entities/organization.ts +31 -18
  6. package/src/goals.ts +78 -12
  7. package/src/index.ts +48 -18
  8. package/src/kpis.ts +62 -8
  9. package/src/metrics.ts +92 -79
  10. package/src/okrs.ts +120 -20
  11. package/src/organization.ts +12 -15
  12. package/src/process.ts +11 -12
  13. package/src/product.ts +8 -9
  14. package/src/queries.ts +238 -75
  15. package/src/roles.ts +62 -61
  16. package/src/workflow.ts +22 -15
  17. package/test/business.test.ts +282 -0
  18. package/test/dollar.test.ts +270 -0
  19. package/test/entities.test.ts +628 -0
  20. package/test/financials.test.ts +539 -0
  21. package/test/goals.test.ts +451 -0
  22. package/{src → test}/index.test.ts +1 -1
  23. package/test/kpis.test.ts +440 -0
  24. package/test/metrics.test.ts +744 -0
  25. package/test/okrs.test.ts +741 -0
  26. package/test/organization.test.ts +548 -0
  27. package/test/process.test.ts +503 -0
  28. package/test/product.test.ts +430 -0
  29. package/test/queries.test.ts +556 -0
  30. package/test/roles.test.ts +546 -0
  31. package/test/service.test.ts +450 -0
  32. package/test/types.test.ts +1141 -0
  33. package/test/vision.test.ts +214 -0
  34. package/test/workflow.test.ts +501 -0
  35. package/vitest.config.ts +47 -0
  36. package/.turbo/turbo-build.log +0 -5
  37. package/dist/business.d.ts +0 -62
  38. package/dist/business.d.ts.map +0 -1
  39. package/dist/business.js +0 -109
  40. package/dist/business.js.map +0 -1
  41. package/dist/dollar.d.ts +0 -60
  42. package/dist/dollar.d.ts.map +0 -1
  43. package/dist/dollar.js +0 -107
  44. package/dist/dollar.js.map +0 -1
  45. package/dist/entities/assets.d.ts +0 -21
  46. package/dist/entities/assets.d.ts.map +0 -1
  47. package/dist/entities/assets.js +0 -323
  48. package/dist/entities/assets.js.map +0 -1
  49. package/dist/entities/business.d.ts +0 -36
  50. package/dist/entities/business.d.ts.map +0 -1
  51. package/dist/entities/business.js +0 -370
  52. package/dist/entities/business.js.map +0 -1
  53. package/dist/entities/communication.d.ts +0 -21
  54. package/dist/entities/communication.d.ts.map +0 -1
  55. package/dist/entities/communication.js +0 -255
  56. package/dist/entities/communication.js.map +0 -1
  57. package/dist/entities/customers.d.ts +0 -58
  58. package/dist/entities/customers.d.ts.map +0 -1
  59. package/dist/entities/customers.js +0 -989
  60. package/dist/entities/customers.js.map +0 -1
  61. package/dist/entities/financials.d.ts +0 -59
  62. package/dist/entities/financials.d.ts.map +0 -1
  63. package/dist/entities/financials.js +0 -932
  64. package/dist/entities/financials.js.map +0 -1
  65. package/dist/entities/goals.d.ts +0 -58
  66. package/dist/entities/goals.d.ts.map +0 -1
  67. package/dist/entities/goals.js +0 -800
  68. package/dist/entities/goals.js.map +0 -1
  69. package/dist/entities/index.d.ts +0 -299
  70. package/dist/entities/index.d.ts.map +0 -1
  71. package/dist/entities/index.js +0 -198
  72. package/dist/entities/index.js.map +0 -1
  73. package/dist/entities/legal.d.ts +0 -21
  74. package/dist/entities/legal.d.ts.map +0 -1
  75. package/dist/entities/legal.js +0 -301
  76. package/dist/entities/legal.js.map +0 -1
  77. package/dist/entities/market.d.ts +0 -21
  78. package/dist/entities/market.d.ts.map +0 -1
  79. package/dist/entities/market.js +0 -301
  80. package/dist/entities/market.js.map +0 -1
  81. package/dist/entities/marketing.d.ts +0 -67
  82. package/dist/entities/marketing.d.ts.map +0 -1
  83. package/dist/entities/marketing.js +0 -1157
  84. package/dist/entities/marketing.js.map +0 -1
  85. package/dist/entities/offerings.d.ts +0 -51
  86. package/dist/entities/offerings.d.ts.map +0 -1
  87. package/dist/entities/offerings.js +0 -727
  88. package/dist/entities/offerings.js.map +0 -1
  89. package/dist/entities/operations.d.ts +0 -58
  90. package/dist/entities/operations.d.ts.map +0 -1
  91. package/dist/entities/operations.js +0 -787
  92. package/dist/entities/operations.js.map +0 -1
  93. package/dist/entities/organization.d.ts +0 -57
  94. package/dist/entities/organization.d.ts.map +0 -1
  95. package/dist/entities/organization.js +0 -807
  96. package/dist/entities/organization.js.map +0 -1
  97. package/dist/entities/partnerships.d.ts +0 -21
  98. package/dist/entities/partnerships.d.ts.map +0 -1
  99. package/dist/entities/partnerships.js +0 -300
  100. package/dist/entities/partnerships.js.map +0 -1
  101. package/dist/entities/planning.d.ts +0 -87
  102. package/dist/entities/planning.d.ts.map +0 -1
  103. package/dist/entities/planning.js +0 -271
  104. package/dist/entities/planning.js.map +0 -1
  105. package/dist/entities/projects.d.ts +0 -25
  106. package/dist/entities/projects.d.ts.map +0 -1
  107. package/dist/entities/projects.js +0 -349
  108. package/dist/entities/projects.js.map +0 -1
  109. package/dist/entities/risk.d.ts +0 -21
  110. package/dist/entities/risk.d.ts.map +0 -1
  111. package/dist/entities/risk.js +0 -293
  112. package/dist/entities/risk.js.map +0 -1
  113. package/dist/entities/sales.d.ts +0 -72
  114. package/dist/entities/sales.d.ts.map +0 -1
  115. package/dist/entities/sales.js +0 -1248
  116. package/dist/entities/sales.js.map +0 -1
  117. package/dist/financials.d.ts +0 -130
  118. package/dist/financials.d.ts.map +0 -1
  119. package/dist/financials.js +0 -297
  120. package/dist/financials.js.map +0 -1
  121. package/dist/goals.d.ts +0 -87
  122. package/dist/goals.d.ts.map +0 -1
  123. package/dist/goals.js +0 -215
  124. package/dist/goals.js.map +0 -1
  125. package/dist/index.d.ts +0 -97
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/index.js +0 -132
  128. package/dist/index.js.map +0 -1
  129. package/dist/kpis.d.ts +0 -118
  130. package/dist/kpis.d.ts.map +0 -1
  131. package/dist/kpis.js +0 -232
  132. package/dist/kpis.js.map +0 -1
  133. package/dist/metrics.d.ts +0 -448
  134. package/dist/metrics.d.ts.map +0 -1
  135. package/dist/metrics.js +0 -325
  136. package/dist/metrics.js.map +0 -1
  137. package/dist/okrs.d.ts +0 -123
  138. package/dist/okrs.d.ts.map +0 -1
  139. package/dist/okrs.js +0 -269
  140. package/dist/okrs.js.map +0 -1
  141. package/dist/organization.d.ts +0 -585
  142. package/dist/organization.d.ts.map +0 -1
  143. package/dist/organization.js +0 -173
  144. package/dist/organization.js.map +0 -1
  145. package/dist/process.d.ts +0 -112
  146. package/dist/process.d.ts.map +0 -1
  147. package/dist/process.js +0 -241
  148. package/dist/process.js.map +0 -1
  149. package/dist/product.d.ts +0 -85
  150. package/dist/product.d.ts.map +0 -1
  151. package/dist/product.js +0 -145
  152. package/dist/product.js.map +0 -1
  153. package/dist/queries.d.ts +0 -304
  154. package/dist/queries.d.ts.map +0 -1
  155. package/dist/queries.js +0 -415
  156. package/dist/queries.js.map +0 -1
  157. package/dist/roles.d.ts +0 -340
  158. package/dist/roles.d.ts.map +0 -1
  159. package/dist/roles.js +0 -255
  160. package/dist/roles.js.map +0 -1
  161. package/dist/service.d.ts +0 -61
  162. package/dist/service.d.ts.map +0 -1
  163. package/dist/service.js +0 -140
  164. package/dist/service.js.map +0 -1
  165. package/dist/types.d.ts +0 -459
  166. package/dist/types.d.ts.map +0 -1
  167. package/dist/types.js +0 -5
  168. package/dist/types.js.map +0 -1
  169. package/dist/vision.d.ts +0 -38
  170. package/dist/vision.d.ts.map +0 -1
  171. package/dist/vision.js +0 -68
  172. package/dist/vision.js.map +0 -1
  173. package/dist/workflow.d.ts +0 -115
  174. package/dist/workflow.d.ts.map +0 -1
  175. package/dist/workflow.js +0 -247
  176. package/dist/workflow.js.map +0 -1
  177. package/src/business.js +0 -108
  178. package/src/dollar.js +0 -106
  179. package/src/entities/assets.js +0 -322
  180. package/src/entities/business.js +0 -369
  181. package/src/entities/communication.js +0 -254
  182. package/src/entities/customers.js +0 -988
  183. package/src/entities/financials.js +0 -931
  184. package/src/entities/goals.js +0 -799
  185. package/src/entities/index.js +0 -197
  186. package/src/entities/legal.js +0 -300
  187. package/src/entities/market.js +0 -300
  188. package/src/entities/marketing.js +0 -1156
  189. package/src/entities/offerings.js +0 -726
  190. package/src/entities/operations.js +0 -786
  191. package/src/entities/organization.js +0 -806
  192. package/src/entities/partnerships.js +0 -299
  193. package/src/entities/planning.js +0 -270
  194. package/src/entities/projects.js +0 -348
  195. package/src/entities/risk.js +0 -292
  196. package/src/entities/sales.js +0 -1247
  197. package/src/financials.js +0 -296
  198. package/src/goals.js +0 -214
  199. package/src/index.js +0 -131
  200. package/src/index.test.js +0 -274
  201. package/src/kpis.js +0 -231
  202. package/src/metrics.js +0 -324
  203. package/src/okrs.js +0 -268
  204. package/src/organization.js +0 -172
  205. package/src/process.js +0 -240
  206. package/src/product.js +0 -144
  207. package/src/queries.js +0 -414
  208. package/src/roles.js +0 -254
  209. package/src/service.js +0 -139
  210. package/src/types.js +0 -4
  211. package/src/vision.js +0 -67
  212. package/src/workflow.js +0 -246
@@ -0,0 +1,450 @@
1
+ /**
2
+ * Tests for service.ts - Service definition and management
3
+ */
4
+
5
+ import { describe, it, expect } from 'vitest'
6
+ import {
7
+ Service,
8
+ calculateHourlyPrice,
9
+ calculateMonthlyRetainer,
10
+ checkSLAUptime,
11
+ parseDeliveryTimeToDays,
12
+ estimateCompletionDate,
13
+ calculateValueBasedPrice,
14
+ validateService,
15
+ } from '../src/service.js'
16
+ import type { ServiceDefinition } from '../src/types.js'
17
+
18
+ describe('Service', () => {
19
+ describe('Service()', () => {
20
+ it('should create a service with required fields', () => {
21
+ const service = Service({ name: 'Test Service' })
22
+
23
+ expect(service.name).toBe('Test Service')
24
+ expect(service.pricingModel).toBe('hourly')
25
+ expect(service.currency).toBe('USD')
26
+ expect(service.metadata).toEqual({})
27
+ })
28
+
29
+ it('should create a service with all fields', () => {
30
+ const service = Service({
31
+ name: 'Consulting Service',
32
+ description: 'Expert consulting',
33
+ category: 'Professional Services',
34
+ targetSegment: 'Enterprise',
35
+ valueProposition: 'Maximize ROI',
36
+ pricingModel: 'fixed',
37
+ price: 5000,
38
+ currency: 'EUR',
39
+ deliveryTime: '2 weeks',
40
+ sla: {
41
+ uptime: 99.9,
42
+ responseTime: '< 24 hours',
43
+ supportHours: '9-5 EST',
44
+ penalties: '10% refund per day',
45
+ },
46
+ metadata: { type: 'premium' },
47
+ })
48
+
49
+ expect(service.name).toBe('Consulting Service')
50
+ expect(service.description).toBe('Expert consulting')
51
+ expect(service.pricingModel).toBe('fixed')
52
+ expect(service.price).toBe(5000)
53
+ expect(service.currency).toBe('EUR')
54
+ expect(service.deliveryTime).toBe('2 weeks')
55
+ expect(service.sla?.uptime).toBe(99.9)
56
+ expect(service.metadata).toEqual({ type: 'premium' })
57
+ })
58
+
59
+ it('should throw error if name is missing', () => {
60
+ expect(() => Service({ name: '' })).toThrow('Service name is required')
61
+ })
62
+
63
+ it('should preserve provided values', () => {
64
+ const service = Service({
65
+ name: 'Test',
66
+ pricingModel: 'retainer',
67
+ currency: 'GBP',
68
+ })
69
+
70
+ expect(service.pricingModel).toBe('retainer')
71
+ expect(service.currency).toBe('GBP')
72
+ })
73
+ })
74
+
75
+ describe('calculateHourlyPrice()', () => {
76
+ it('should calculate price for hours', () => {
77
+ const service = Service({
78
+ name: 'Consulting',
79
+ pricingModel: 'hourly',
80
+ price: 150,
81
+ })
82
+
83
+ expect(calculateHourlyPrice(service, 10)).toBe(1500)
84
+ })
85
+
86
+ it('should throw error for non-hourly pricing', () => {
87
+ const service = Service({
88
+ name: 'Consulting',
89
+ pricingModel: 'fixed',
90
+ price: 5000,
91
+ })
92
+
93
+ expect(() => calculateHourlyPrice(service, 10)).toThrow(
94
+ 'Service must use hourly pricing model'
95
+ )
96
+ })
97
+
98
+ it('should throw error if price is missing', () => {
99
+ const service = Service({
100
+ name: 'Consulting',
101
+ pricingModel: 'hourly',
102
+ })
103
+
104
+ expect(() => calculateHourlyPrice(service, 10)).toThrow(
105
+ 'Service must use hourly pricing model'
106
+ )
107
+ })
108
+
109
+ it('should handle zero hours', () => {
110
+ const service = Service({
111
+ name: 'Consulting',
112
+ pricingModel: 'hourly',
113
+ price: 150,
114
+ })
115
+
116
+ expect(calculateHourlyPrice(service, 0)).toBe(0)
117
+ })
118
+
119
+ it('should handle fractional hours', () => {
120
+ const service = Service({
121
+ name: 'Consulting',
122
+ pricingModel: 'hourly',
123
+ price: 100,
124
+ })
125
+
126
+ expect(calculateHourlyPrice(service, 1.5)).toBe(150)
127
+ })
128
+ })
129
+
130
+ describe('calculateMonthlyRetainer()', () => {
131
+ it('should calculate monthly retainer', () => {
132
+ const service = Service({
133
+ name: 'Support',
134
+ pricingModel: 'hourly',
135
+ price: 100,
136
+ })
137
+
138
+ expect(calculateMonthlyRetainer(service, 40)).toBe(4000)
139
+ })
140
+
141
+ it('should throw error for non-hourly pricing', () => {
142
+ const service = Service({
143
+ name: 'Support',
144
+ pricingModel: 'fixed',
145
+ price: 5000,
146
+ })
147
+
148
+ expect(() => calculateMonthlyRetainer(service, 40)).toThrow(
149
+ 'Service must use hourly pricing model'
150
+ )
151
+ })
152
+
153
+ it('should handle zero hours', () => {
154
+ const service = Service({
155
+ name: 'Support',
156
+ pricingModel: 'hourly',
157
+ price: 100,
158
+ })
159
+
160
+ expect(calculateMonthlyRetainer(service, 0)).toBe(0)
161
+ })
162
+ })
163
+
164
+ describe('checkSLAUptime()', () => {
165
+ it('should return true when uptime meets SLA', () => {
166
+ const service = Service({
167
+ name: 'API',
168
+ sla: { uptime: 99.9 },
169
+ })
170
+
171
+ expect(checkSLAUptime(service, 99.95)).toBe(true)
172
+ })
173
+
174
+ it('should return true when uptime equals SLA', () => {
175
+ const service = Service({
176
+ name: 'API',
177
+ sla: { uptime: 99.9 },
178
+ })
179
+
180
+ expect(checkSLAUptime(service, 99.9)).toBe(true)
181
+ })
182
+
183
+ it('should return false when uptime below SLA', () => {
184
+ const service = Service({
185
+ name: 'API',
186
+ sla: { uptime: 99.9 },
187
+ })
188
+
189
+ expect(checkSLAUptime(service, 99.5)).toBe(false)
190
+ })
191
+
192
+ it('should return true when no SLA uptime defined', () => {
193
+ const service = Service({ name: 'API' })
194
+ expect(checkSLAUptime(service, 99.5)).toBe(true)
195
+ })
196
+
197
+ it('should return true when no SLA defined', () => {
198
+ const service = Service({
199
+ name: 'API',
200
+ sla: { responseTime: '< 24 hours' },
201
+ })
202
+
203
+ expect(checkSLAUptime(service, 99.5)).toBe(true)
204
+ })
205
+ })
206
+
207
+ describe('parseDeliveryTimeToDays()', () => {
208
+ it('should parse days', () => {
209
+ expect(parseDeliveryTimeToDays('5 days')).toBe(5)
210
+ expect(parseDeliveryTimeToDays('1 day')).toBe(1)
211
+ })
212
+
213
+ it('should parse weeks', () => {
214
+ expect(parseDeliveryTimeToDays('2 weeks')).toBe(14)
215
+ expect(parseDeliveryTimeToDays('1 week')).toBe(7)
216
+ })
217
+
218
+ it('should parse months', () => {
219
+ expect(parseDeliveryTimeToDays('1 month')).toBe(30)
220
+ expect(parseDeliveryTimeToDays('3 months')).toBe(90)
221
+ })
222
+
223
+ it('should parse hours', () => {
224
+ expect(parseDeliveryTimeToDays('24 hours')).toBe(1)
225
+ expect(parseDeliveryTimeToDays('48 hours')).toBe(2)
226
+ })
227
+
228
+ it('should return 0 for undefined', () => {
229
+ expect(parseDeliveryTimeToDays(undefined)).toBe(0)
230
+ })
231
+
232
+ it('should return 0 for invalid format', () => {
233
+ expect(parseDeliveryTimeToDays('invalid')).toBe(0)
234
+ expect(parseDeliveryTimeToDays('soon')).toBe(0)
235
+ })
236
+
237
+ it('should handle case insensitivity', () => {
238
+ expect(parseDeliveryTimeToDays('2 WEEKS')).toBe(14)
239
+ expect(parseDeliveryTimeToDays('1 Day')).toBe(1)
240
+ })
241
+ })
242
+
243
+ describe('estimateCompletionDate()', () => {
244
+ it('should estimate completion date', () => {
245
+ const service = Service({
246
+ name: 'Project',
247
+ deliveryTime: '2 weeks',
248
+ })
249
+
250
+ const startDate = new Date('2024-01-01')
251
+ const completion = estimateCompletionDate(service, startDate)
252
+
253
+ expect(completion.getTime()).toBe(new Date('2024-01-15').getTime())
254
+ })
255
+
256
+ it('should use current date if no start date provided', () => {
257
+ const service = Service({
258
+ name: 'Project',
259
+ deliveryTime: '1 day',
260
+ })
261
+
262
+ const now = new Date()
263
+ const completion = estimateCompletionDate(service)
264
+
265
+ // Allow for small timing differences
266
+ const expectedDate = new Date(now)
267
+ expectedDate.setDate(now.getDate() + 1)
268
+ expect(completion.getDate()).toBe(expectedDate.getDate())
269
+ })
270
+
271
+ it('should handle no delivery time', () => {
272
+ const service = Service({ name: 'Project' })
273
+
274
+ const startDate = new Date('2024-01-01')
275
+ const completion = estimateCompletionDate(service, startDate)
276
+
277
+ expect(completion.getTime()).toBe(startDate.getTime())
278
+ })
279
+ })
280
+
281
+ describe('calculateValueBasedPrice()', () => {
282
+ it('should calculate value-based price', () => {
283
+ const service = Service({
284
+ name: 'Consulting',
285
+ pricingModel: 'value-based',
286
+ })
287
+
288
+ expect(calculateValueBasedPrice(service, 100000, 20)).toBe(20000)
289
+ })
290
+
291
+ it('should throw error for non-value-based pricing', () => {
292
+ const service = Service({
293
+ name: 'Consulting',
294
+ pricingModel: 'hourly',
295
+ price: 150,
296
+ })
297
+
298
+ expect(() => calculateValueBasedPrice(service, 100000, 20)).toThrow(
299
+ 'Service must use value-based pricing model'
300
+ )
301
+ })
302
+
303
+ it('should throw error for invalid percentage (below 0)', () => {
304
+ const service = Service({
305
+ name: 'Consulting',
306
+ pricingModel: 'value-based',
307
+ })
308
+
309
+ expect(() => calculateValueBasedPrice(service, 100000, -10)).toThrow(
310
+ 'Value share percentage must be between 0 and 100'
311
+ )
312
+ })
313
+
314
+ it('should throw error for invalid percentage (above 100)', () => {
315
+ const service = Service({
316
+ name: 'Consulting',
317
+ pricingModel: 'value-based',
318
+ })
319
+
320
+ expect(() => calculateValueBasedPrice(service, 100000, 150)).toThrow(
321
+ 'Value share percentage must be between 0 and 100'
322
+ )
323
+ })
324
+
325
+ it('should handle zero value', () => {
326
+ const service = Service({
327
+ name: 'Consulting',
328
+ pricingModel: 'value-based',
329
+ })
330
+
331
+ expect(calculateValueBasedPrice(service, 0, 20)).toBe(0)
332
+ })
333
+
334
+ it('should handle zero percentage', () => {
335
+ const service = Service({
336
+ name: 'Consulting',
337
+ pricingModel: 'value-based',
338
+ })
339
+
340
+ expect(calculateValueBasedPrice(service, 100000, 0)).toBe(0)
341
+ })
342
+
343
+ it('should handle 100% percentage', () => {
344
+ const service = Service({
345
+ name: 'Consulting',
346
+ pricingModel: 'value-based',
347
+ })
348
+
349
+ expect(calculateValueBasedPrice(service, 100000, 100)).toBe(100000)
350
+ })
351
+ })
352
+
353
+ describe('validateService()', () => {
354
+ it('should validate valid service', () => {
355
+ const service: ServiceDefinition = {
356
+ name: 'Valid Service',
357
+ pricingModel: 'hourly',
358
+ price: 100,
359
+ }
360
+
361
+ const result = validateService(service)
362
+ expect(result.valid).toBe(true)
363
+ expect(result.errors).toHaveLength(0)
364
+ })
365
+
366
+ it('should fail if name is missing', () => {
367
+ const service: ServiceDefinition = { name: '' }
368
+
369
+ const result = validateService(service)
370
+ expect(result.valid).toBe(false)
371
+ expect(result.errors).toContain('Service name is required')
372
+ })
373
+
374
+ it('should fail if price is negative', () => {
375
+ const service: ServiceDefinition = { name: 'Test', price: -100 }
376
+
377
+ const result = validateService(service)
378
+ expect(result.valid).toBe(false)
379
+ expect(result.errors).toContain('Service price cannot be negative')
380
+ })
381
+
382
+ it('should fail if SLA uptime is below 0', () => {
383
+ const service: ServiceDefinition = {
384
+ name: 'Test',
385
+ sla: { uptime: -1 },
386
+ }
387
+
388
+ const result = validateService(service)
389
+ expect(result.valid).toBe(false)
390
+ expect(result.errors).toContain('SLA uptime must be between 0 and 100')
391
+ })
392
+
393
+ it('should fail if SLA uptime is above 100', () => {
394
+ const service: ServiceDefinition = {
395
+ name: 'Test',
396
+ sla: { uptime: 101 },
397
+ }
398
+
399
+ const result = validateService(service)
400
+ expect(result.valid).toBe(false)
401
+ expect(result.errors).toContain('SLA uptime must be between 0 and 100')
402
+ })
403
+
404
+ it('should fail for invalid pricing model', () => {
405
+ const service: ServiceDefinition = {
406
+ name: 'Test',
407
+ pricingModel: 'invalid' as ServiceDefinition['pricingModel'],
408
+ }
409
+
410
+ const result = validateService(service)
411
+ expect(result.valid).toBe(false)
412
+ expect(result.errors).toContain('Invalid pricing model')
413
+ })
414
+
415
+ it('should allow all valid pricing models', () => {
416
+ const pricingModels: ServiceDefinition['pricingModel'][] = [
417
+ 'hourly',
418
+ 'fixed',
419
+ 'retainer',
420
+ 'value-based',
421
+ ]
422
+
423
+ for (const model of pricingModels) {
424
+ const service: ServiceDefinition = { name: 'Test', pricingModel: model }
425
+ const result = validateService(service)
426
+ expect(result.valid).toBe(true)
427
+ }
428
+ })
429
+
430
+ it('should allow zero price', () => {
431
+ const service: ServiceDefinition = { name: 'Free Service', price: 0 }
432
+
433
+ const result = validateService(service)
434
+ expect(result.valid).toBe(true)
435
+ })
436
+
437
+ it('should return multiple errors', () => {
438
+ const service: ServiceDefinition = {
439
+ name: '',
440
+ price: -100,
441
+ sla: { uptime: 150 },
442
+ pricingModel: 'invalid' as ServiceDefinition['pricingModel'],
443
+ }
444
+
445
+ const result = validateService(service)
446
+ expect(result.valid).toBe(false)
447
+ expect(result.errors.length).toBeGreaterThan(1)
448
+ })
449
+ })
450
+ })