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.
- package/CHANGELOG.md +18 -0
- package/README.md +2 -0
- package/package.json +7 -4
- 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/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/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 -87
- 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/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
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for product.ts - Product definition and management
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
Product,
|
|
8
|
+
calculateGrossMargin,
|
|
9
|
+
calculateGrossProfit,
|
|
10
|
+
getRoadmapByStatus,
|
|
11
|
+
getRoadmapByPriority,
|
|
12
|
+
getOverdueRoadmapItems,
|
|
13
|
+
updateRoadmapItem,
|
|
14
|
+
addFeature,
|
|
15
|
+
removeFeature,
|
|
16
|
+
validateProduct,
|
|
17
|
+
} from '../src/product.js'
|
|
18
|
+
import type { ProductDefinition, RoadmapItem } from '../src/types.js'
|
|
19
|
+
|
|
20
|
+
describe('Product', () => {
|
|
21
|
+
describe('Product()', () => {
|
|
22
|
+
it('should create a product with required fields', () => {
|
|
23
|
+
const product = Product({ name: 'Test Product' })
|
|
24
|
+
|
|
25
|
+
expect(product.name).toBe('Test Product')
|
|
26
|
+
expect(product.pricingModel).toBe('one-time')
|
|
27
|
+
expect(product.currency).toBe('USD')
|
|
28
|
+
expect(product.features).toEqual([])
|
|
29
|
+
expect(product.roadmap).toEqual([])
|
|
30
|
+
expect(product.metadata).toEqual({})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should create a product with all fields', () => {
|
|
34
|
+
const product = Product({
|
|
35
|
+
name: 'Widget Pro',
|
|
36
|
+
description: 'Enterprise widget platform',
|
|
37
|
+
category: 'SaaS',
|
|
38
|
+
targetSegment: 'Enterprise',
|
|
39
|
+
valueProposition: 'Reduce costs by 50%',
|
|
40
|
+
pricingModel: 'subscription',
|
|
41
|
+
price: 99,
|
|
42
|
+
currency: 'EUR',
|
|
43
|
+
cogs: 20,
|
|
44
|
+
features: ['Feature 1', 'Feature 2'],
|
|
45
|
+
roadmap: [{ name: 'Mobile App', status: 'planned', priority: 'high' }],
|
|
46
|
+
metadata: { tier: 'premium' },
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
expect(product.name).toBe('Widget Pro')
|
|
50
|
+
expect(product.description).toBe('Enterprise widget platform')
|
|
51
|
+
expect(product.category).toBe('SaaS')
|
|
52
|
+
expect(product.pricingModel).toBe('subscription')
|
|
53
|
+
expect(product.price).toBe(99)
|
|
54
|
+
expect(product.currency).toBe('EUR')
|
|
55
|
+
expect(product.cogs).toBe(20)
|
|
56
|
+
expect(product.features).toHaveLength(2)
|
|
57
|
+
expect(product.roadmap).toHaveLength(1)
|
|
58
|
+
expect(product.metadata).toEqual({ tier: 'premium' })
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should throw error if name is missing', () => {
|
|
62
|
+
expect(() => Product({ name: '' })).toThrow('Product name is required')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should preserve provided values and not override with defaults', () => {
|
|
66
|
+
const product = Product({
|
|
67
|
+
name: 'Test',
|
|
68
|
+
pricingModel: 'usage-based',
|
|
69
|
+
currency: 'GBP',
|
|
70
|
+
features: ['Custom Feature'],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
expect(product.pricingModel).toBe('usage-based')
|
|
74
|
+
expect(product.currency).toBe('GBP')
|
|
75
|
+
expect(product.features).toEqual(['Custom Feature'])
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe('calculateGrossMargin()', () => {
|
|
80
|
+
it('should calculate gross margin percentage', () => {
|
|
81
|
+
const product = Product({ name: 'Test', price: 100, cogs: 30 })
|
|
82
|
+
expect(calculateGrossMargin(product)).toBe(70)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should return 0 if price is missing', () => {
|
|
86
|
+
const product = Product({ name: 'Test', cogs: 30 })
|
|
87
|
+
expect(calculateGrossMargin(product)).toBe(0)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should return 0 if cogs is missing', () => {
|
|
91
|
+
const product = Product({ name: 'Test', price: 100 })
|
|
92
|
+
expect(calculateGrossMargin(product)).toBe(0)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('should handle zero cogs (returns 0 since cogs is falsy)', () => {
|
|
96
|
+
// The implementation treats cogs: 0 as missing (falsy check)
|
|
97
|
+
const product = Product({ name: 'Test', price: 100, cogs: 0 })
|
|
98
|
+
expect(calculateGrossMargin(product)).toBe(0)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('should handle high cogs (low margin)', () => {
|
|
102
|
+
const product = Product({ name: 'Test', price: 100, cogs: 90 })
|
|
103
|
+
expect(calculateGrossMargin(product)).toBe(10)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('calculateGrossProfit()', () => {
|
|
108
|
+
it('should calculate gross profit for units sold', () => {
|
|
109
|
+
const product = Product({ name: 'Test', price: 100, cogs: 30 })
|
|
110
|
+
expect(calculateGrossProfit(product, 10)).toBe(700)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should return 0 if price is missing', () => {
|
|
114
|
+
const product = Product({ name: 'Test', cogs: 30 })
|
|
115
|
+
expect(calculateGrossProfit(product, 10)).toBe(0)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('should return 0 if cogs is missing', () => {
|
|
119
|
+
const product = Product({ name: 'Test', price: 100 })
|
|
120
|
+
expect(calculateGrossProfit(product, 10)).toBe(0)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('should handle zero units sold', () => {
|
|
124
|
+
const product = Product({ name: 'Test', price: 100, cogs: 30 })
|
|
125
|
+
expect(calculateGrossProfit(product, 0)).toBe(0)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('should handle large volume', () => {
|
|
129
|
+
const product = Product({ name: 'Test', price: 50, cogs: 20 })
|
|
130
|
+
expect(calculateGrossProfit(product, 1000)).toBe(30000)
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('getRoadmapByStatus()', () => {
|
|
135
|
+
const product = Product({
|
|
136
|
+
name: 'Test',
|
|
137
|
+
roadmap: [
|
|
138
|
+
{ name: 'Feature A', status: 'planned' },
|
|
139
|
+
{ name: 'Feature B', status: 'in-progress' },
|
|
140
|
+
{ name: 'Feature C', status: 'planned' },
|
|
141
|
+
{ name: 'Feature D', status: 'completed' },
|
|
142
|
+
],
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('should filter roadmap items by status', () => {
|
|
146
|
+
const planned = getRoadmapByStatus(product, 'planned')
|
|
147
|
+
expect(planned).toHaveLength(2)
|
|
148
|
+
expect(planned[0]?.name).toBe('Feature A')
|
|
149
|
+
expect(planned[1]?.name).toBe('Feature C')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('should return empty array for non-existent status', () => {
|
|
153
|
+
const cancelled = getRoadmapByStatus(product, 'cancelled')
|
|
154
|
+
expect(cancelled).toHaveLength(0)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('should handle product without roadmap', () => {
|
|
158
|
+
const emptyProduct = Product({ name: 'Empty' })
|
|
159
|
+
const result = getRoadmapByStatus(emptyProduct, 'planned')
|
|
160
|
+
expect(result).toEqual([])
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('getRoadmapByPriority()', () => {
|
|
165
|
+
const product = Product({
|
|
166
|
+
name: 'Test',
|
|
167
|
+
roadmap: [
|
|
168
|
+
{ name: 'Feature A', priority: 'high' },
|
|
169
|
+
{ name: 'Feature B', priority: 'low' },
|
|
170
|
+
{ name: 'Feature C', priority: 'high' },
|
|
171
|
+
{ name: 'Feature D', priority: 'critical' },
|
|
172
|
+
],
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('should filter roadmap items by priority', () => {
|
|
176
|
+
const high = getRoadmapByPriority(product, 'high')
|
|
177
|
+
expect(high).toHaveLength(2)
|
|
178
|
+
expect(high[0]?.name).toBe('Feature A')
|
|
179
|
+
expect(high[1]?.name).toBe('Feature C')
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('should return empty array for non-existent priority', () => {
|
|
183
|
+
const medium = getRoadmapByPriority(product, 'medium')
|
|
184
|
+
expect(medium).toHaveLength(0)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('should handle product without roadmap', () => {
|
|
188
|
+
const emptyProduct = Product({ name: 'Empty' })
|
|
189
|
+
const result = getRoadmapByPriority(emptyProduct, 'high')
|
|
190
|
+
expect(result).toEqual([])
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
describe('getOverdueRoadmapItems()', () => {
|
|
195
|
+
beforeEach(() => {
|
|
196
|
+
vi.useFakeTimers()
|
|
197
|
+
vi.setSystemTime(new Date('2024-06-15'))
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
afterEach(() => {
|
|
201
|
+
vi.useRealTimers()
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('should return overdue roadmap items', () => {
|
|
205
|
+
const product = Product({
|
|
206
|
+
name: 'Test',
|
|
207
|
+
roadmap: [
|
|
208
|
+
{ name: 'Feature A', targetDate: new Date('2024-06-01'), status: 'in-progress' },
|
|
209
|
+
{ name: 'Feature B', targetDate: new Date('2024-12-01'), status: 'planned' },
|
|
210
|
+
{ name: 'Feature C', targetDate: new Date('2024-05-01'), status: 'planned' },
|
|
211
|
+
],
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const overdue = getOverdueRoadmapItems(product)
|
|
215
|
+
expect(overdue).toHaveLength(2)
|
|
216
|
+
expect(overdue.map((i) => i.name)).toContain('Feature A')
|
|
217
|
+
expect(overdue.map((i) => i.name)).toContain('Feature C')
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('should not include completed items', () => {
|
|
221
|
+
const product = Product({
|
|
222
|
+
name: 'Test',
|
|
223
|
+
roadmap: [
|
|
224
|
+
{ name: 'Feature A', targetDate: new Date('2024-06-01'), status: 'completed' },
|
|
225
|
+
{ name: 'Feature B', targetDate: new Date('2024-05-01'), status: 'in-progress' },
|
|
226
|
+
],
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const overdue = getOverdueRoadmapItems(product)
|
|
230
|
+
expect(overdue).toHaveLength(1)
|
|
231
|
+
expect(overdue[0]?.name).toBe('Feature B')
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('should not include cancelled items', () => {
|
|
235
|
+
const product = Product({
|
|
236
|
+
name: 'Test',
|
|
237
|
+
roadmap: [{ name: 'Feature A', targetDate: new Date('2024-06-01'), status: 'cancelled' }],
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
const overdue = getOverdueRoadmapItems(product)
|
|
241
|
+
expect(overdue).toHaveLength(0)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('should handle items without target date', () => {
|
|
245
|
+
const product = Product({
|
|
246
|
+
name: 'Test',
|
|
247
|
+
roadmap: [{ name: 'Feature A', status: 'in-progress' }],
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
const overdue = getOverdueRoadmapItems(product)
|
|
251
|
+
expect(overdue).toHaveLength(0)
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
describe('updateRoadmapItem()', () => {
|
|
256
|
+
it('should update roadmap item properties', () => {
|
|
257
|
+
const product = Product({
|
|
258
|
+
name: 'Test',
|
|
259
|
+
roadmap: [
|
|
260
|
+
{ name: 'Feature A', status: 'planned', priority: 'low' },
|
|
261
|
+
{ name: 'Feature B', status: 'planned', priority: 'medium' },
|
|
262
|
+
],
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
const updated = updateRoadmapItem(product, 'Feature A', {
|
|
266
|
+
status: 'in-progress',
|
|
267
|
+
priority: 'high',
|
|
268
|
+
})
|
|
269
|
+
const item = updated.roadmap?.find((i) => i.name === 'Feature A')
|
|
270
|
+
|
|
271
|
+
expect(item?.status).toBe('in-progress')
|
|
272
|
+
expect(item?.priority).toBe('high')
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('should not affect other roadmap items', () => {
|
|
276
|
+
const product = Product({
|
|
277
|
+
name: 'Test',
|
|
278
|
+
roadmap: [
|
|
279
|
+
{ name: 'Feature A', status: 'planned' },
|
|
280
|
+
{ name: 'Feature B', status: 'planned' },
|
|
281
|
+
],
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
const updated = updateRoadmapItem(product, 'Feature A', { status: 'completed' })
|
|
285
|
+
const itemB = updated.roadmap?.find((i) => i.name === 'Feature B')
|
|
286
|
+
|
|
287
|
+
expect(itemB?.status).toBe('planned')
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
it('should handle non-existent item', () => {
|
|
291
|
+
const product = Product({
|
|
292
|
+
name: 'Test',
|
|
293
|
+
roadmap: [{ name: 'Feature A', status: 'planned' }],
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
const updated = updateRoadmapItem(product, 'NonExistent', { status: 'completed' })
|
|
297
|
+
expect(updated.roadmap).toHaveLength(1)
|
|
298
|
+
expect(updated.roadmap?.[0]?.status).toBe('planned')
|
|
299
|
+
})
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
describe('addFeature()', () => {
|
|
303
|
+
it('should add feature to product', () => {
|
|
304
|
+
const product = Product({
|
|
305
|
+
name: 'Test',
|
|
306
|
+
features: ['Feature 1'],
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
const updated = addFeature(product, 'Feature 2')
|
|
310
|
+
expect(updated.features).toHaveLength(2)
|
|
311
|
+
expect(updated.features).toContain('Feature 2')
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('should add feature to product without features', () => {
|
|
315
|
+
const product = Product({ name: 'Test' })
|
|
316
|
+
|
|
317
|
+
const updated = addFeature(product, 'New Feature')
|
|
318
|
+
expect(updated.features).toHaveLength(1)
|
|
319
|
+
expect(updated.features).toContain('New Feature')
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('should preserve existing features', () => {
|
|
323
|
+
const product = Product({
|
|
324
|
+
name: 'Test',
|
|
325
|
+
features: ['Feature 1', 'Feature 2'],
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
const updated = addFeature(product, 'Feature 3')
|
|
329
|
+
expect(updated.features).toContain('Feature 1')
|
|
330
|
+
expect(updated.features).toContain('Feature 2')
|
|
331
|
+
expect(updated.features).toContain('Feature 3')
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
describe('removeFeature()', () => {
|
|
336
|
+
it('should remove feature from product', () => {
|
|
337
|
+
const product = Product({
|
|
338
|
+
name: 'Test',
|
|
339
|
+
features: ['Feature 1', 'Feature 2', 'Feature 3'],
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
const updated = removeFeature(product, 'Feature 2')
|
|
343
|
+
expect(updated.features).toHaveLength(2)
|
|
344
|
+
expect(updated.features).not.toContain('Feature 2')
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
it('should handle removing non-existent feature', () => {
|
|
348
|
+
const product = Product({
|
|
349
|
+
name: 'Test',
|
|
350
|
+
features: ['Feature 1'],
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
const updated = removeFeature(product, 'NonExistent')
|
|
354
|
+
expect(updated.features).toHaveLength(1)
|
|
355
|
+
expect(updated.features).toContain('Feature 1')
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
it('should handle product without features', () => {
|
|
359
|
+
const product = Product({ name: 'Test' })
|
|
360
|
+
|
|
361
|
+
const updated = removeFeature(product, 'Feature')
|
|
362
|
+
expect(updated.features).toEqual([])
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
describe('validateProduct()', () => {
|
|
367
|
+
it('should validate valid product', () => {
|
|
368
|
+
const product: ProductDefinition = {
|
|
369
|
+
name: 'Valid Product',
|
|
370
|
+
price: 100,
|
|
371
|
+
cogs: 30,
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const result = validateProduct(product)
|
|
375
|
+
expect(result.valid).toBe(true)
|
|
376
|
+
expect(result.errors).toHaveLength(0)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
it('should fail if name is missing', () => {
|
|
380
|
+
const product: ProductDefinition = { name: '' }
|
|
381
|
+
|
|
382
|
+
const result = validateProduct(product)
|
|
383
|
+
expect(result.valid).toBe(false)
|
|
384
|
+
expect(result.errors).toContain('Product name is required')
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
it('should fail if price is negative', () => {
|
|
388
|
+
const product: ProductDefinition = { name: 'Test', price: -100 }
|
|
389
|
+
|
|
390
|
+
const result = validateProduct(product)
|
|
391
|
+
expect(result.valid).toBe(false)
|
|
392
|
+
expect(result.errors).toContain('Product price cannot be negative')
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('should fail if cogs is negative', () => {
|
|
396
|
+
const product: ProductDefinition = { name: 'Test', cogs: -30 }
|
|
397
|
+
|
|
398
|
+
const result = validateProduct(product)
|
|
399
|
+
expect(result.valid).toBe(false)
|
|
400
|
+
expect(result.errors).toContain('Product COGS cannot be negative')
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
it('should fail if cogs exceeds price', () => {
|
|
404
|
+
const product: ProductDefinition = { name: 'Test', price: 50, cogs: 100 }
|
|
405
|
+
|
|
406
|
+
const result = validateProduct(product)
|
|
407
|
+
expect(result.valid).toBe(false)
|
|
408
|
+
expect(result.errors).toContain('Product COGS cannot exceed price')
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('should allow zero price', () => {
|
|
412
|
+
const product: ProductDefinition = { name: 'Free Product', price: 0 }
|
|
413
|
+
|
|
414
|
+
const result = validateProduct(product)
|
|
415
|
+
expect(result.valid).toBe(true)
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
it('should return multiple errors', () => {
|
|
419
|
+
const product: ProductDefinition = {
|
|
420
|
+
name: '',
|
|
421
|
+
price: -100,
|
|
422
|
+
cogs: -50,
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const result = validateProduct(product)
|
|
426
|
+
expect(result.valid).toBe(false)
|
|
427
|
+
expect(result.errors.length).toBeGreaterThan(1)
|
|
428
|
+
})
|
|
429
|
+
})
|
|
430
|
+
})
|