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,556 @@
1
+ /**
2
+ * Tests for queries.ts - Live Queries & Views for ai-database
3
+ */
4
+
5
+ import { describe, it, expect } from 'vitest'
6
+ import {
7
+ // Types
8
+ StandardDimensions,
9
+ StandardMeasures,
10
+ CalculatedMetrics,
11
+
12
+ // Builders
13
+ query,
14
+ QueryBuilder,
15
+ view,
16
+ ViewBuilder,
17
+ dashboard,
18
+ DashboardBuilder,
19
+
20
+ // Pre-built queries
21
+ MrrOverview,
22
+ ArrBySegment,
23
+ CohortRetention,
24
+ UnitEconomics,
25
+ RevenueByChannel,
26
+ GrowthMetrics,
27
+
28
+ // Pre-built dashboards
29
+ ExecutiveDashboard,
30
+ } from '../src/queries.js'
31
+
32
+ describe('StandardDimensions', () => {
33
+ it('should have time dimensions', () => {
34
+ expect(StandardDimensions.date).toBeDefined()
35
+ expect(StandardDimensions.date.name).toBe('date')
36
+ expect(StandardDimensions.date.type).toBe('date')
37
+
38
+ expect(StandardDimensions.month).toBeDefined()
39
+ expect(StandardDimensions.month.granularity).toBe('month')
40
+
41
+ expect(StandardDimensions.quarter).toBeDefined()
42
+ expect(StandardDimensions.quarter.granularity).toBe('quarter')
43
+
44
+ expect(StandardDimensions.year).toBeDefined()
45
+ expect(StandardDimensions.year.granularity).toBe('year')
46
+ })
47
+
48
+ it('should have customer dimensions', () => {
49
+ expect(StandardDimensions.customerId).toBeDefined()
50
+ expect(StandardDimensions.customerSegment).toBeDefined()
51
+ expect(StandardDimensions.plan).toBeDefined()
52
+ expect(StandardDimensions.cohort).toBeDefined()
53
+ })
54
+
55
+ it('should have product dimensions', () => {
56
+ expect(StandardDimensions.productId).toBeDefined()
57
+ expect(StandardDimensions.productName).toBeDefined()
58
+ expect(StandardDimensions.feature).toBeDefined()
59
+ })
60
+
61
+ it('should have geography dimensions', () => {
62
+ expect(StandardDimensions.country).toBeDefined()
63
+ expect(StandardDimensions.region).toBeDefined()
64
+ })
65
+
66
+ it('should have channel dimensions', () => {
67
+ expect(StandardDimensions.channel).toBeDefined()
68
+ expect(StandardDimensions.source).toBeDefined()
69
+ expect(StandardDimensions.campaign).toBeDefined()
70
+ })
71
+ })
72
+
73
+ describe('StandardMeasures', () => {
74
+ it('should have revenue measures', () => {
75
+ expect(StandardMeasures.revenue).toBeDefined()
76
+ expect(StandardMeasures.revenue.aggregate).toBe('sum')
77
+ expect(StandardMeasures.revenue.type).toBe('currency')
78
+
79
+ expect(StandardMeasures.mrr).toBeDefined()
80
+ expect(StandardMeasures.newMrr).toBeDefined()
81
+ expect(StandardMeasures.expansionMrr).toBeDefined()
82
+ expect(StandardMeasures.contractionMrr).toBeDefined()
83
+ expect(StandardMeasures.churnedMrr).toBeDefined()
84
+ })
85
+
86
+ it('should have customer measures', () => {
87
+ expect(StandardMeasures.customers).toBeDefined()
88
+ expect(StandardMeasures.customers.aggregate).toBe('countDistinct')
89
+
90
+ expect(StandardMeasures.newCustomers).toBeDefined()
91
+ expect(StandardMeasures.churnedCustomers).toBeDefined()
92
+ })
93
+
94
+ it('should have usage measures', () => {
95
+ expect(StandardMeasures.events).toBeDefined()
96
+ expect(StandardMeasures.events.aggregate).toBe('count')
97
+
98
+ expect(StandardMeasures.sessions).toBeDefined()
99
+ expect(StandardMeasures.activeUsers).toBeDefined()
100
+ })
101
+
102
+ it('should have cost measures', () => {
103
+ expect(StandardMeasures.cogs).toBeDefined()
104
+ expect(StandardMeasures.salesSpend).toBeDefined()
105
+ expect(StandardMeasures.marketingSpend).toBeDefined()
106
+ })
107
+ })
108
+
109
+ describe('CalculatedMetrics', () => {
110
+ it('should have revenue calculated metrics', () => {
111
+ expect(CalculatedMetrics.arr).toBeDefined()
112
+ expect(CalculatedMetrics.arr.expression).toBe('mrr * 12')
113
+ expect(CalculatedMetrics.arr.measures).toContain('mrr')
114
+
115
+ expect(CalculatedMetrics.netNewMrr).toBeDefined()
116
+ expect(CalculatedMetrics.arpu).toBeDefined()
117
+ })
118
+
119
+ it('should have margin calculated metrics', () => {
120
+ expect(CalculatedMetrics.grossProfit).toBeDefined()
121
+ expect(CalculatedMetrics.grossMargin).toBeDefined()
122
+ expect(CalculatedMetrics.grossMargin.type).toBe('percent')
123
+ })
124
+
125
+ it('should have efficiency calculated metrics', () => {
126
+ expect(CalculatedMetrics.cac).toBeDefined()
127
+ expect(CalculatedMetrics.ltv).toBeDefined()
128
+ expect(CalculatedMetrics.ltvCacRatio).toBeDefined()
129
+ })
130
+
131
+ it('should have churn calculated metrics', () => {
132
+ expect(CalculatedMetrics.customerChurnRate).toBeDefined()
133
+ expect(CalculatedMetrics.revenueChurnRate).toBeDefined()
134
+ expect(CalculatedMetrics.nrr).toBeDefined()
135
+ })
136
+
137
+ it('should have growth calculated metrics', () => {
138
+ expect(CalculatedMetrics.quickRatio).toBeDefined()
139
+ expect(CalculatedMetrics.magicNumber).toBeDefined()
140
+ })
141
+ })
142
+
143
+ describe('QueryBuilder', () => {
144
+ describe('query()', () => {
145
+ it('should create a basic query', () => {
146
+ const q = query('test_query', 'test_table').build()
147
+
148
+ expect(q.name).toBe('test_query')
149
+ expect(q.source).toBe('test_table')
150
+ })
151
+
152
+ it('should set description', () => {
153
+ const q = query('test', 'table').describe('A test query').build()
154
+
155
+ expect(q.description).toBe('A test query')
156
+ })
157
+
158
+ it('should set dimensions', () => {
159
+ const q = query('test', 'table').dimensions('month', 'segment').build()
160
+
161
+ expect(q.dimensions).toEqual(['month', 'segment'])
162
+ })
163
+
164
+ it('should set measures', () => {
165
+ const q = query('test', 'table').measures('mrr', 'customers').build()
166
+
167
+ expect(q.measures).toEqual(['mrr', 'customers'])
168
+ })
169
+
170
+ it('should add filters', () => {
171
+ const q = query('test', 'table')
172
+ .filter('status', 'eq', 'active')
173
+ .filter('revenue', 'gt', 1000)
174
+ .build()
175
+
176
+ expect(q.filters).toHaveLength(2)
177
+ expect(q.filters![0]).toEqual({ field: 'status', operator: 'eq', value: 'active' })
178
+ expect(q.filters![1]).toEqual({ field: 'revenue', operator: 'gt', value: 1000 })
179
+ })
180
+
181
+ it('should set where filters', () => {
182
+ const filters = [
183
+ { field: 'status', operator: 'eq' as const, value: 'active' },
184
+ { field: 'revenue', operator: 'gt' as const, value: 1000 },
185
+ ]
186
+ const q = query('test', 'table').where(filters).build()
187
+
188
+ expect(q.filters).toEqual(filters)
189
+ })
190
+
191
+ it('should set time range', () => {
192
+ const start = new Date('2024-01-01')
193
+ const end = new Date('2024-12-31')
194
+ const q = query('test', 'table').timeRange('created_at', start, end, 'month').build()
195
+
196
+ expect(q.timeRange).toEqual({
197
+ field: 'created_at',
198
+ start,
199
+ end,
200
+ granularity: 'month',
201
+ })
202
+ })
203
+
204
+ it('should set last duration', () => {
205
+ const q = query('test', 'table').last('30d').build()
206
+
207
+ expect(q.timeRange).toEqual({
208
+ field: 'date',
209
+ start: '-30d',
210
+ })
211
+ })
212
+
213
+ it('should set last duration with custom field', () => {
214
+ const q = query('test', 'table').last('7d', 'created_at').build()
215
+
216
+ expect(q.timeRange?.field).toBe('created_at')
217
+ expect(q.timeRange?.start).toBe('-7d')
218
+ })
219
+
220
+ it('should add sort', () => {
221
+ const q = query('test', 'table').sort('revenue', 'desc').sort('date', 'asc').build()
222
+
223
+ expect(q.sort).toHaveLength(2)
224
+ expect(q.sort![0]).toEqual({ field: 'revenue', direction: 'desc' })
225
+ expect(q.sort![1]).toEqual({ field: 'date', direction: 'asc' })
226
+ })
227
+
228
+ it('should use desc as default sort direction', () => {
229
+ const q = query('test', 'table').sort('revenue').build()
230
+
231
+ expect(q.sort![0]?.direction).toBe('desc')
232
+ })
233
+
234
+ it('should set limit', () => {
235
+ const q = query('test', 'table').limit(100).build()
236
+
237
+ expect(q.limit).toBe(100)
238
+ })
239
+
240
+ it('should set offset', () => {
241
+ const q = query('test', 'table').offset(50).build()
242
+
243
+ expect(q.offset).toBe(50)
244
+ })
245
+
246
+ it('should set tags', () => {
247
+ const q = query('test', 'table').tags('saas', 'revenue', 'metrics').build()
248
+
249
+ expect(q.tags).toEqual(['saas', 'revenue', 'metrics'])
250
+ })
251
+
252
+ it('should set owner', () => {
253
+ const q = query('test', 'table').owner('finance-team').build()
254
+
255
+ expect(q.owner).toBe('finance-team')
256
+ })
257
+
258
+ it('should chain all builder methods', () => {
259
+ const q = query('full_query', 'revenue_events')
260
+ .describe('Full query example')
261
+ .dimensions('month', 'segment')
262
+ .measures('mrr', 'customers')
263
+ .filter('status', 'eq', 'active')
264
+ .last('12m')
265
+ .sort('mrr', 'desc')
266
+ .limit(100)
267
+ .offset(0)
268
+ .tags('test')
269
+ .owner('team')
270
+ .build()
271
+
272
+ expect(q.name).toBe('full_query')
273
+ expect(q.source).toBe('revenue_events')
274
+ expect(q.description).toBe('Full query example')
275
+ expect(q.dimensions).toEqual(['month', 'segment'])
276
+ expect(q.measures).toEqual(['mrr', 'customers'])
277
+ expect(q.filters).toHaveLength(1)
278
+ expect(q.timeRange?.start).toBe('-12m')
279
+ expect(q.sort).toHaveLength(1)
280
+ expect(q.limit).toBe(100)
281
+ expect(q.offset).toBe(0)
282
+ expect(q.tags).toEqual(['test'])
283
+ expect(q.owner).toBe('team')
284
+ })
285
+ })
286
+ })
287
+
288
+ describe('ViewBuilder', () => {
289
+ const testQuery = query('test', 'table').build()
290
+
291
+ describe('view()', () => {
292
+ it('should create a basic view', () => {
293
+ const v = view('test_view', testQuery).build()
294
+
295
+ expect(v.name).toBe('test_view')
296
+ expect(v.query).toEqual(testQuery)
297
+ })
298
+
299
+ it('should set description', () => {
300
+ const v = view('test', testQuery).describe('A test view').build()
301
+
302
+ expect(v.description).toBe('A test view')
303
+ })
304
+
305
+ it('should set materialization', () => {
306
+ const v = view('test', testQuery).materialize('5m', '30d').build()
307
+
308
+ expect(v.materialized).toBe(true)
309
+ expect(v.refreshInterval).toBe('5m')
310
+ expect(v.retention).toBe('30d')
311
+ })
312
+
313
+ it('should set public flag', () => {
314
+ const v = view('test', testQuery).public().build()
315
+
316
+ expect(v.public).toBe(true)
317
+ })
318
+
319
+ it('should set owner', () => {
320
+ const v = view('test', testQuery).owner('data-team').build()
321
+
322
+ expect(v.owner).toBe('data-team')
323
+ })
324
+
325
+ it('should set tags', () => {
326
+ const v = view('test', testQuery).tags('financial', 'metrics').build()
327
+
328
+ expect(v.tags).toEqual(['financial', 'metrics'])
329
+ })
330
+
331
+ it('should chain all builder methods', () => {
332
+ const v = view('full_view', testQuery)
333
+ .describe('Full view example')
334
+ .materialize('1h', '7d')
335
+ .public()
336
+ .owner('analytics')
337
+ .tags('test', 'example')
338
+ .build()
339
+
340
+ expect(v.name).toBe('full_view')
341
+ expect(v.description).toBe('Full view example')
342
+ expect(v.materialized).toBe(true)
343
+ expect(v.refreshInterval).toBe('1h')
344
+ expect(v.retention).toBe('7d')
345
+ expect(v.public).toBe(true)
346
+ expect(v.owner).toBe('analytics')
347
+ expect(v.tags).toEqual(['test', 'example'])
348
+ })
349
+ })
350
+ })
351
+
352
+ describe('DashboardBuilder', () => {
353
+ const testQuery = query('test', 'table').build()
354
+ const testView = view('test_view', testQuery).build()
355
+
356
+ describe('dashboard()', () => {
357
+ it('should create a basic dashboard', () => {
358
+ const d = dashboard('test_dashboard').build()
359
+
360
+ expect(d.name).toBe('test_dashboard')
361
+ expect(d.views).toEqual([])
362
+ })
363
+
364
+ it('should set description', () => {
365
+ const d = dashboard('test').describe('A test dashboard').build()
366
+
367
+ expect(d.description).toBe('A test dashboard')
368
+ })
369
+
370
+ it('should add views', () => {
371
+ const d = dashboard('test').add(testView).build()
372
+
373
+ expect(d.views).toHaveLength(1)
374
+ expect(d.views[0]).toEqual(testView)
375
+ })
376
+
377
+ it('should add multiple views', () => {
378
+ const view2 = view('test_view_2', testQuery).build()
379
+ const d = dashboard('test').add(testView).add(view2).build()
380
+
381
+ expect(d.views).toHaveLength(2)
382
+ })
383
+
384
+ it('should set layout', () => {
385
+ const d = dashboard('test').layout(4, 3).build()
386
+
387
+ expect(d.layout).toBeDefined()
388
+ expect(d.layout?.columns).toBe(4)
389
+ expect(d.layout?.rows).toBe(3)
390
+ expect(d.layout?.items).toEqual([])
391
+ })
392
+
393
+ it('should add view with layout options when layout is set', () => {
394
+ const d = dashboard('test')
395
+ .layout(4, 3)
396
+ .add(testView, { x: 0, y: 0, width: 2, height: 1, visualization: 'line' })
397
+ .build()
398
+
399
+ expect(d.views).toHaveLength(1)
400
+ expect(d.layout?.items).toHaveLength(1)
401
+ expect(d.layout?.items[0]).toEqual({
402
+ viewName: 'test_view',
403
+ x: 0,
404
+ y: 0,
405
+ width: 2,
406
+ height: 1,
407
+ visualization: 'line',
408
+ })
409
+ })
410
+
411
+ it('should set refresh interval', () => {
412
+ const d = dashboard('test').refresh('5m').build()
413
+
414
+ expect(d.refreshInterval).toBe('5m')
415
+ })
416
+
417
+ it('should set owner', () => {
418
+ const d = dashboard('test').owner('exec-team').build()
419
+
420
+ expect(d.owner).toBe('exec-team')
421
+ })
422
+
423
+ it('should set tags', () => {
424
+ const d = dashboard('test').tags('executive', 'saas').build()
425
+
426
+ expect(d.tags).toEqual(['executive', 'saas'])
427
+ })
428
+
429
+ it('should chain all builder methods', () => {
430
+ const d = dashboard('full_dashboard')
431
+ .describe('Full dashboard example')
432
+ .layout(4, 3)
433
+ .add(testView, { x: 0, y: 0, width: 2, height: 1 })
434
+ .refresh('10m')
435
+ .owner('leadership')
436
+ .tags('kpi', 'metrics')
437
+ .build()
438
+
439
+ expect(d.name).toBe('full_dashboard')
440
+ expect(d.description).toBe('Full dashboard example')
441
+ expect(d.layout?.columns).toBe(4)
442
+ expect(d.layout?.rows).toBe(3)
443
+ expect(d.views).toHaveLength(1)
444
+ expect(d.refreshInterval).toBe('10m')
445
+ expect(d.owner).toBe('leadership')
446
+ expect(d.tags).toEqual(['kpi', 'metrics'])
447
+ })
448
+ })
449
+ })
450
+
451
+ describe('Pre-built Queries', () => {
452
+ describe('MrrOverview', () => {
453
+ it('should have correct structure', () => {
454
+ expect(MrrOverview.name).toBe('mrr_overview')
455
+ expect(MrrOverview.source).toBe('revenue_events')
456
+ expect(MrrOverview.dimensions).toContain('month')
457
+ expect(MrrOverview.measures).toContain('mrr')
458
+ expect(MrrOverview.measures).toContain('newMrr')
459
+ expect(MrrOverview.measures).toContain('expansionMrr')
460
+ expect(MrrOverview.measures).toContain('contractionMrr')
461
+ expect(MrrOverview.measures).toContain('churnedMrr')
462
+ expect(MrrOverview.measures).toContain('netNewMrr')
463
+ expect(MrrOverview.timeRange?.start).toBe('-12m')
464
+ })
465
+ })
466
+
467
+ describe('ArrBySegment', () => {
468
+ it('should have correct structure', () => {
469
+ expect(ArrBySegment.name).toBe('arr_by_segment')
470
+ expect(ArrBySegment.source).toBe('revenue_events')
471
+ expect(ArrBySegment.dimensions).toContain('customerSegment')
472
+ expect(ArrBySegment.measures).toContain('arr')
473
+ expect(ArrBySegment.measures).toContain('customers')
474
+ expect(ArrBySegment.measures).toContain('arpu')
475
+ })
476
+ })
477
+
478
+ describe('CohortRetention', () => {
479
+ it('should have correct structure', () => {
480
+ expect(CohortRetention.name).toBe('cohort_retention')
481
+ expect(CohortRetention.source).toBe('customer_events')
482
+ expect(CohortRetention.dimensions).toContain('cohort')
483
+ expect(CohortRetention.dimensions).toContain('month')
484
+ expect(CohortRetention.measures).toContain('customers')
485
+ expect(CohortRetention.measures).toContain('mrr')
486
+ })
487
+ })
488
+
489
+ describe('UnitEconomics', () => {
490
+ it('should have correct structure', () => {
491
+ expect(UnitEconomics.name).toBe('unit_economics')
492
+ expect(UnitEconomics.source).toBe('financial_events')
493
+ expect(UnitEconomics.measures).toContain('cac')
494
+ expect(UnitEconomics.measures).toContain('ltv')
495
+ expect(UnitEconomics.measures).toContain('ltvCacRatio')
496
+ expect(UnitEconomics.measures).toContain('arpu')
497
+ expect(UnitEconomics.measures).toContain('customerChurnRate')
498
+ })
499
+ })
500
+
501
+ describe('RevenueByChannel', () => {
502
+ it('should have correct structure', () => {
503
+ expect(RevenueByChannel.name).toBe('revenue_by_channel')
504
+ expect(RevenueByChannel.source).toBe('revenue_events')
505
+ expect(RevenueByChannel.dimensions).toContain('channel')
506
+ expect(RevenueByChannel.measures).toContain('mrr')
507
+ expect(RevenueByChannel.measures).toContain('newCustomers')
508
+ expect(RevenueByChannel.measures).toContain('cac')
509
+ })
510
+ })
511
+
512
+ describe('GrowthMetrics', () => {
513
+ it('should have correct structure', () => {
514
+ expect(GrowthMetrics.name).toBe('growth_metrics')
515
+ expect(GrowthMetrics.source).toBe('financial_events')
516
+ expect(GrowthMetrics.dimensions).toContain('month')
517
+ expect(GrowthMetrics.measures).toContain('mrr')
518
+ expect(GrowthMetrics.measures).toContain('netNewMrr')
519
+ expect(GrowthMetrics.measures).toContain('quickRatio')
520
+ expect(GrowthMetrics.measures).toContain('nrr')
521
+ expect(GrowthMetrics.measures).toContain('magicNumber')
522
+ })
523
+ })
524
+ })
525
+
526
+ describe('Pre-built Dashboards', () => {
527
+ describe('ExecutiveDashboard', () => {
528
+ it('should have correct structure', () => {
529
+ expect(ExecutiveDashboard.name).toBe('executive')
530
+ expect(ExecutiveDashboard.description).toBe('Executive overview of key SaaS metrics')
531
+ expect(ExecutiveDashboard.views).toHaveLength(5)
532
+ expect(ExecutiveDashboard.refreshInterval).toBe('5m')
533
+ expect(ExecutiveDashboard.tags).toContain('executive')
534
+ expect(ExecutiveDashboard.tags).toContain('saas')
535
+ expect(ExecutiveDashboard.tags).toContain('metrics')
536
+ })
537
+
538
+ it('should have correct layout', () => {
539
+ expect(ExecutiveDashboard.layout).toBeDefined()
540
+ expect(ExecutiveDashboard.layout?.columns).toBe(4)
541
+ expect(ExecutiveDashboard.layout?.rows).toBe(3)
542
+ expect(ExecutiveDashboard.layout?.items).toHaveLength(5)
543
+ })
544
+
545
+ it('should have views with visualizations', () => {
546
+ const items = ExecutiveDashboard.layout?.items || []
547
+ const visualizations = items.map((item) => item.visualization)
548
+
549
+ expect(visualizations).toContain('trend')
550
+ expect(visualizations).toContain('bar')
551
+ expect(visualizations).toContain('table')
552
+ expect(visualizations).toContain('line')
553
+ expect(visualizations).toContain('cohort')
554
+ })
555
+ })
556
+ })