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.
- package/.turbo/turbo-build.log +4 -5
- package/CHANGELOG.md +53 -0
- package/README.md +2 -0
- package/dist/dollar.d.ts.map +1 -1
- package/dist/dollar.js +2 -2
- package/dist/dollar.js.map +1 -1
- package/dist/entities/organization.d.ts +4 -0
- package/dist/entities/organization.d.ts.map +1 -1
- package/dist/entities/organization.js +27 -18
- package/dist/entities/organization.js.map +1 -1
- package/dist/entities/planning.d.ts +87 -0
- package/dist/finance/account.d.ts +44 -0
- package/dist/finance/account.d.ts.map +1 -0
- package/dist/finance/account.js +6 -0
- package/dist/finance/account.js.map +1 -0
- package/dist/finance/authority.d.ts +78 -0
- package/dist/finance/authority.d.ts.map +1 -0
- package/dist/finance/authority.js +27 -0
- package/dist/finance/authority.js.map +1 -0
- package/dist/finance/card.d.ts +36 -0
- package/dist/finance/card.d.ts.map +1 -0
- package/dist/finance/card.js +6 -0
- package/dist/finance/card.js.map +1 -0
- package/dist/finance/identity.d.ts +30 -0
- package/dist/finance/identity.d.ts.map +1 -0
- package/dist/finance/identity.js +8 -0
- package/dist/finance/identity.js.map +1 -0
- package/dist/finance/index.d.ts +36 -0
- package/dist/finance/index.d.ts.map +1 -0
- package/dist/finance/index.js +22 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance/ledger.d.ts +24 -0
- package/dist/finance/ledger.d.ts.map +1 -0
- package/dist/finance/ledger.js +8 -0
- package/dist/finance/ledger.js.map +1 -0
- package/dist/finance/merchant.d.ts +129 -0
- package/dist/finance/merchant.d.ts.map +1 -0
- package/dist/finance/merchant.js +21 -0
- package/dist/finance/merchant.js.map +1 -0
- package/dist/finance/outcome-contract.d.ts +139 -0
- package/dist/finance/outcome-contract.d.ts.map +1 -0
- package/dist/finance/outcome-contract.js +27 -0
- package/dist/finance/outcome-contract.js.map +1 -0
- package/dist/finance/port.d.ts +121 -0
- package/dist/finance/port.d.ts.map +1 -0
- package/dist/finance/port.js +10 -0
- package/dist/finance/port.js.map +1 -0
- package/dist/finance/pricing.d.ts +154 -0
- package/dist/finance/pricing.d.ts.map +1 -0
- package/dist/finance/pricing.js +79 -0
- package/dist/finance/pricing.js.map +1 -0
- package/dist/finance/proof-predicate.d.ts +92 -0
- package/dist/finance/proof-predicate.d.ts.map +1 -0
- package/dist/finance/proof-predicate.js +80 -0
- package/dist/finance/proof-predicate.js.map +1 -0
- package/dist/finance/refund.d.ts +44 -0
- package/dist/finance/refund.d.ts.map +1 -0
- package/dist/finance/refund.js +41 -0
- package/dist/finance/refund.js.map +1 -0
- package/dist/finance/sla.d.ts +25 -0
- package/dist/finance/sla.d.ts.map +1 -0
- package/dist/finance/sla.js +7 -0
- package/dist/finance/sla.js.map +1 -0
- package/dist/finance/types.d.ts +79 -0
- package/dist/finance/types.d.ts.map +1 -0
- package/dist/finance/types.js +8 -0
- package/dist/{canvas → finance}/types.js.map +1 -1
- package/dist/goals.d.ts +19 -0
- package/dist/goals.d.ts.map +1 -1
- package/dist/goals.js +81 -12
- package/dist/goals.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/kpis.d.ts +19 -0
- package/dist/kpis.d.ts.map +1 -1
- package/dist/kpis.js +71 -6
- package/dist/kpis.js.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +29 -24
- package/dist/metrics.js.map +1 -1
- package/dist/okrs.d.ts +34 -0
- package/dist/okrs.d.ts.map +1 -1
- package/dist/okrs.js +135 -13
- package/dist/okrs.js.map +1 -1
- package/dist/organization.d.ts.map +1 -1
- package/dist/organization.js +11 -11
- package/dist/organization.js.map +1 -1
- package/dist/process.d.ts.map +1 -1
- package/dist/process.js +13 -12
- package/dist/process.js.map +1 -1
- package/dist/product.d.ts.map +1 -1
- package/dist/product.js +9 -9
- package/dist/product.js.map +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +194 -32
- package/dist/queries.js.map +1 -1
- package/dist/roles.d.ts +25 -31
- package/dist/roles.d.ts.map +1 -1
- package/dist/roles.js +37 -10
- package/dist/roles.js.map +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +13 -12
- package/dist/workflow.js.map +1 -1
- package/package.json +20 -13
- package/src/dollar.ts +5 -2
- package/src/entities/organization.ts +31 -18
- package/src/finance/account.ts +48 -0
- package/src/finance/authority.ts +42 -0
- package/src/finance/card.ts +38 -0
- package/src/finance/identity.ts +31 -0
- package/src/finance/index.ts +117 -0
- package/src/finance/ledger.ts +26 -0
- package/src/finance/merchant.ts +127 -0
- package/src/finance/outcome-contract.ts +157 -0
- package/src/finance/port.ts +144 -0
- package/src/finance/pricing.ts +197 -0
- package/src/finance/proof-predicate.ts +106 -0
- package/src/finance/refund.ts +52 -0
- package/src/finance/sla.ts +33 -0
- package/src/finance/types.ts +75 -0
- 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/LICENSE +0 -21
- package/dist/canvas/activities.d.ts +0 -19
- package/dist/canvas/activities.d.ts.map +0 -1
- package/dist/canvas/activities.js +0 -20
- package/dist/canvas/activities.js.map +0 -1
- package/dist/canvas/channels.d.ts +0 -20
- package/dist/canvas/channels.d.ts.map +0 -1
- package/dist/canvas/channels.js +0 -21
- package/dist/canvas/channels.js.map +0 -1
- package/dist/canvas/relationships.d.ts +0 -20
- package/dist/canvas/relationships.d.ts.map +0 -1
- package/dist/canvas/relationships.js +0 -21
- package/dist/canvas/relationships.js.map +0 -1
- package/dist/canvas/resources.d.ts +0 -20
- package/dist/canvas/resources.d.ts.map +0 -1
- package/dist/canvas/resources.js +0 -30
- package/dist/canvas/resources.js.map +0 -1
- package/dist/canvas/revenue.d.ts +0 -22
- package/dist/canvas/revenue.d.ts.map +0 -1
- package/dist/canvas/revenue.js +0 -30
- package/dist/canvas/revenue.js.map +0 -1
- package/dist/canvas/segments.d.ts +0 -20
- package/dist/canvas/segments.d.ts.map +0 -1
- package/dist/canvas/segments.js +0 -28
- package/dist/canvas/segments.js.map +0 -1
- package/dist/canvas/types.d.ts +0 -232
- package/dist/canvas/types.d.ts.map +0 -1
- package/dist/canvas/types.js +0 -8
- package/dist/canvas/value.d.ts +0 -20
- package/dist/canvas/value.d.ts.map +0 -1
- package/dist/canvas/value.js +0 -21
- package/dist/canvas/value.js.map +0 -1
- package/src/business.js +0 -108
- package/src/canvas/activities.ts +0 -32
- package/src/canvas/canvas.ts +0 -482
- package/src/canvas/channels.ts +0 -34
- package/src/canvas/costs.ts +0 -43
- package/src/canvas/economics.ts +0 -99
- package/src/canvas/index.ts +0 -206
- package/src/canvas/partnerships.ts +0 -34
- package/src/canvas/projections.ts +0 -141
- package/src/canvas/relationships.ts +0 -34
- package/src/canvas/resources.ts +0 -43
- package/src/canvas/revenue.ts +0 -56
- package/src/canvas/segments.ts +0 -42
- package/src/canvas/types.ts +0 -363
- package/src/canvas/value.ts +0 -34
- package/src/dollar.js +0 -106
- package/src/entities/assets.js +0 -322
- package/src/entities/business.js +0 -369
- package/src/entities/communication.js +0 -254
- package/src/entities/customers.js +0 -988
- package/src/entities/financials.js +0 -931
- package/src/entities/goals.js +0 -799
- package/src/entities/index.js +0 -197
- package/src/entities/legal.js +0 -300
- package/src/entities/market.js +0 -300
- package/src/entities/marketing.js +0 -1156
- package/src/entities/offerings.js +0 -726
- package/src/entities/operations.js +0 -786
- package/src/entities/organization.js +0 -806
- package/src/entities/partnerships.js +0 -299
- package/src/entities/planning.js +0 -270
- package/src/entities/projects.js +0 -348
- package/src/entities/risk.js +0 -292
- package/src/entities/sales.js +0 -1247
- package/src/financials.js +0 -296
- package/src/goals.js +0 -214
- package/src/index.js +0 -131
- package/src/index.test.js +0 -274
- package/src/kpis.js +0 -231
- package/src/metrics.js +0 -324
- package/src/okrs.js +0 -268
- package/src/organization.js +0 -172
- package/src/process.js +0 -240
- package/src/product.js +0 -144
- package/src/queries.js +0 -414
- package/src/roles.js +0 -254
- package/src/service.js +0 -139
- package/src/types.js +0 -4
- package/src/vision.js +0 -67
- package/src/workflow.js +0 -246
- package/tests/canvas.test.ts +0 -842
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for organization.ts - Organizational structure and permissions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from 'vitest'
|
|
6
|
+
import { resolvePermissions, getApprovalChainForRequest, findManager } from '../src/organization.js'
|
|
7
|
+
import type {
|
|
8
|
+
Organization,
|
|
9
|
+
Department,
|
|
10
|
+
Team,
|
|
11
|
+
Position,
|
|
12
|
+
ApprovalChain,
|
|
13
|
+
} from '../src/organization.js'
|
|
14
|
+
import type { BusinessRole } from '../src/roles.js'
|
|
15
|
+
|
|
16
|
+
describe('Organization', () => {
|
|
17
|
+
// Helper function to create a test organization
|
|
18
|
+
const createTestOrganization = (): Organization => ({
|
|
19
|
+
id: 'org_acme',
|
|
20
|
+
name: 'Acme Corp',
|
|
21
|
+
domain: 'acme.com',
|
|
22
|
+
industry: 'technology',
|
|
23
|
+
roles: [
|
|
24
|
+
{
|
|
25
|
+
id: 'role_cto',
|
|
26
|
+
name: 'CTO',
|
|
27
|
+
type: 'cto',
|
|
28
|
+
permissions: {
|
|
29
|
+
repository: ['read', 'edit', 'manage'],
|
|
30
|
+
project: ['manage'],
|
|
31
|
+
},
|
|
32
|
+
canApprove: ['technical-decision', 'architecture'],
|
|
33
|
+
canHandle: ['architecture-review'],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'role_lead',
|
|
37
|
+
name: 'Engineering Lead',
|
|
38
|
+
type: 'lead',
|
|
39
|
+
permissions: {
|
|
40
|
+
repository: ['read', 'edit', 'act:merge'],
|
|
41
|
+
project: ['read', 'edit'],
|
|
42
|
+
},
|
|
43
|
+
canApprove: ['code-review'],
|
|
44
|
+
canHandle: ['code-review', 'mentoring'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'role_engineer',
|
|
48
|
+
name: 'Software Engineer',
|
|
49
|
+
type: 'engineer',
|
|
50
|
+
permissions: {
|
|
51
|
+
repository: ['read', 'edit'],
|
|
52
|
+
project: ['read'],
|
|
53
|
+
},
|
|
54
|
+
canHandle: ['coding', 'testing'],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
departments: [
|
|
58
|
+
{
|
|
59
|
+
id: 'dept_eng',
|
|
60
|
+
name: 'Engineering',
|
|
61
|
+
code: 'ENG',
|
|
62
|
+
defaultPermissions: {
|
|
63
|
+
documentation: ['read'],
|
|
64
|
+
},
|
|
65
|
+
teams: [
|
|
66
|
+
{
|
|
67
|
+
id: 'team_platform',
|
|
68
|
+
name: 'Platform Team',
|
|
69
|
+
departmentId: 'dept_eng',
|
|
70
|
+
defaultPermissions: {
|
|
71
|
+
infrastructure: ['read'],
|
|
72
|
+
},
|
|
73
|
+
resources: {
|
|
74
|
+
repositories: ['platform-core', 'platform-api'],
|
|
75
|
+
},
|
|
76
|
+
positions: [
|
|
77
|
+
{
|
|
78
|
+
id: 'pos_cto',
|
|
79
|
+
title: 'CTO',
|
|
80
|
+
roleId: 'role_cto',
|
|
81
|
+
workerId: 'worker_jane',
|
|
82
|
+
status: 'active',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'pos_lead',
|
|
86
|
+
title: 'Engineering Lead',
|
|
87
|
+
roleId: 'role_lead',
|
|
88
|
+
workerId: 'worker_bob',
|
|
89
|
+
reportsTo: 'pos_cto',
|
|
90
|
+
status: 'active',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'pos_eng_1',
|
|
94
|
+
title: 'Senior Software Engineer',
|
|
95
|
+
roleId: 'role_engineer',
|
|
96
|
+
workerId: 'worker_alice',
|
|
97
|
+
reportsTo: 'pos_lead',
|
|
98
|
+
status: 'active',
|
|
99
|
+
additionalPermissions: {
|
|
100
|
+
'repository:platform-core': ['manage'],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'pos_eng_2',
|
|
105
|
+
title: 'Software Engineer',
|
|
106
|
+
roleId: 'role_engineer',
|
|
107
|
+
workerId: 'worker_charlie',
|
|
108
|
+
reportsTo: 'pos_lead',
|
|
109
|
+
status: 'active',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'team_product',
|
|
115
|
+
name: 'Product Team',
|
|
116
|
+
departmentId: 'dept_eng',
|
|
117
|
+
positions: [
|
|
118
|
+
{
|
|
119
|
+
id: 'pos_pm',
|
|
120
|
+
title: 'Product Manager',
|
|
121
|
+
roleId: 'role_lead',
|
|
122
|
+
workerId: 'worker_dave',
|
|
123
|
+
status: 'active',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
teams: [
|
|
131
|
+
{
|
|
132
|
+
id: 'team_special',
|
|
133
|
+
name: 'Special Projects',
|
|
134
|
+
positions: [
|
|
135
|
+
{
|
|
136
|
+
id: 'pos_special',
|
|
137
|
+
title: 'Special Projects Lead',
|
|
138
|
+
roleId: 'role_lead',
|
|
139
|
+
workerId: 'worker_eve',
|
|
140
|
+
status: 'active',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
approvalChains: [
|
|
146
|
+
{
|
|
147
|
+
id: 'chain_expense',
|
|
148
|
+
name: 'Expense Approval',
|
|
149
|
+
type: 'expense',
|
|
150
|
+
active: true,
|
|
151
|
+
levels: [
|
|
152
|
+
{
|
|
153
|
+
threshold: 1000,
|
|
154
|
+
approvers: [{ type: 'direct-manager' }],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
threshold: 5000,
|
|
158
|
+
approvers: [{ type: 'direct-manager' }, { type: 'role', roleId: 'director' }],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
threshold: 25000,
|
|
162
|
+
approvers: [{ type: 'direct-manager' }, { type: 'role', roleId: 'cfo' }],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: 'chain_deployment',
|
|
168
|
+
name: 'Deployment Approval',
|
|
169
|
+
type: 'deployment',
|
|
170
|
+
active: true,
|
|
171
|
+
levels: [
|
|
172
|
+
{
|
|
173
|
+
approvers: [{ type: 'role', roleId: 'role_lead' }],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: 'chain_inactive',
|
|
179
|
+
name: 'Inactive Chain',
|
|
180
|
+
type: 'inactive-type',
|
|
181
|
+
active: false,
|
|
182
|
+
levels: [
|
|
183
|
+
{
|
|
184
|
+
approvers: [{ type: 'direct-manager' }],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
describe('resolvePermissions()', () => {
|
|
192
|
+
it('should resolve permissions for a position in the org hierarchy', () => {
|
|
193
|
+
const org = createTestOrganization()
|
|
194
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
195
|
+
|
|
196
|
+
expect(resolved).not.toBeNull()
|
|
197
|
+
expect(resolved?.workerId).toBe('worker_alice')
|
|
198
|
+
expect(resolved?.positionId).toBe('pos_eng_1')
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('should include department permissions', () => {
|
|
202
|
+
const org = createTestOrganization()
|
|
203
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
204
|
+
|
|
205
|
+
expect(resolved?.permissions.documentation).toContain('read')
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('should include team permissions', () => {
|
|
209
|
+
const org = createTestOrganization()
|
|
210
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
211
|
+
|
|
212
|
+
expect(resolved?.permissions.infrastructure).toContain('read')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('should include role permissions', () => {
|
|
216
|
+
const org = createTestOrganization()
|
|
217
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
218
|
+
|
|
219
|
+
expect(resolved?.permissions.repository).toContain('read')
|
|
220
|
+
expect(resolved?.permissions.repository).toContain('edit')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('should include position-specific permissions', () => {
|
|
224
|
+
const org = createTestOrganization()
|
|
225
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
226
|
+
|
|
227
|
+
expect(resolved?.resourcePermissions['repository:platform-core']).toBeDefined()
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('should include canHandle from role', () => {
|
|
231
|
+
const org = createTestOrganization()
|
|
232
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
233
|
+
|
|
234
|
+
expect(resolved?.canHandle).toContain('coding')
|
|
235
|
+
expect(resolved?.canHandle).toContain('testing')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('should include canApprove from role', () => {
|
|
239
|
+
const org = createTestOrganization()
|
|
240
|
+
const resolved = resolvePermissions(org, 'pos_lead')
|
|
241
|
+
|
|
242
|
+
expect(resolved?.canApprove).toContain('code-review')
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('should track inheritance chain', () => {
|
|
246
|
+
const org = createTestOrganization()
|
|
247
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
248
|
+
|
|
249
|
+
expect(resolved?.inheritanceChain).toContain('department:dept_eng')
|
|
250
|
+
expect(resolved?.inheritanceChain).toContain('team:team_platform')
|
|
251
|
+
expect(resolved?.inheritanceChain).toContain('role:role_engineer')
|
|
252
|
+
expect(resolved?.inheritanceChain).toContain('position:pos_eng_1')
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('should return null for non-existent position', () => {
|
|
256
|
+
const org = createTestOrganization()
|
|
257
|
+
const resolved = resolvePermissions(org, 'non_existent')
|
|
258
|
+
|
|
259
|
+
expect(resolved).toBeNull()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('should find positions in standalone teams', () => {
|
|
263
|
+
const org = createTestOrganization()
|
|
264
|
+
const resolved = resolvePermissions(org, 'pos_special')
|
|
265
|
+
|
|
266
|
+
expect(resolved).not.toBeNull()
|
|
267
|
+
expect(resolved?.workerId).toBe('worker_eve')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('should merge permissions without duplicates', () => {
|
|
271
|
+
const org = createTestOrganization()
|
|
272
|
+
const resolved = resolvePermissions(org, 'pos_eng_1')
|
|
273
|
+
|
|
274
|
+
// Both role and team might have 'read' permission
|
|
275
|
+
const readCount = resolved?.permissions.repository?.filter((p) => p === 'read').length
|
|
276
|
+
expect(readCount).toBe(1)
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
describe('getApprovalChainForRequest()', () => {
|
|
281
|
+
it('should return approvers for expense requests', () => {
|
|
282
|
+
const org = createTestOrganization()
|
|
283
|
+
const approvers = getApprovalChainForRequest(org, 'expense', 500)
|
|
284
|
+
|
|
285
|
+
// The function returns approvers - check that we get some
|
|
286
|
+
expect(approvers.length).toBeGreaterThan(0)
|
|
287
|
+
expect(approvers[0]?.type).toBe('direct-manager')
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
it('should return approvers based on amount thresholds', () => {
|
|
291
|
+
const org = createTestOrganization()
|
|
292
|
+
const approvers = getApprovalChainForRequest(org, 'expense', 3000)
|
|
293
|
+
|
|
294
|
+
// Should return approvers for the appropriate level
|
|
295
|
+
expect(approvers.length).toBeGreaterThan(0)
|
|
296
|
+
expect(approvers[0]?.type).toBe('direct-manager')
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it('should return approvers for high amounts', () => {
|
|
300
|
+
const org = createTestOrganization()
|
|
301
|
+
const approvers = getApprovalChainForRequest(org, 'expense', 50000)
|
|
302
|
+
|
|
303
|
+
// Should return some approvers
|
|
304
|
+
expect(approvers.length).toBeGreaterThan(0)
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('should return empty array for non-existent request type', () => {
|
|
308
|
+
const org = createTestOrganization()
|
|
309
|
+
const approvers = getApprovalChainForRequest(org, 'non-existent', 1000)
|
|
310
|
+
|
|
311
|
+
expect(approvers).toEqual([])
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('should not return approvers from inactive chains', () => {
|
|
315
|
+
const org = createTestOrganization()
|
|
316
|
+
const approvers = getApprovalChainForRequest(org, 'inactive-type', 1000)
|
|
317
|
+
|
|
318
|
+
expect(approvers).toEqual([])
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it('should return approvers when no amount specified', () => {
|
|
322
|
+
const org = createTestOrganization()
|
|
323
|
+
const approvers = getApprovalChainForRequest(org, 'deployment')
|
|
324
|
+
|
|
325
|
+
expect(approvers).toHaveLength(1)
|
|
326
|
+
expect(approvers[0]?.type).toBe('role')
|
|
327
|
+
expect(approvers[0]?.roleId).toBe('role_lead')
|
|
328
|
+
})
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
describe('findManager()', () => {
|
|
332
|
+
it('should find direct manager', () => {
|
|
333
|
+
const org = createTestOrganization()
|
|
334
|
+
const manager = findManager(org, 'pos_eng_1')
|
|
335
|
+
|
|
336
|
+
expect(manager).not.toBeNull()
|
|
337
|
+
expect(manager?.id).toBe('pos_lead')
|
|
338
|
+
expect(manager?.workerId).toBe('worker_bob')
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it('should find second-level manager', () => {
|
|
342
|
+
const org = createTestOrganization()
|
|
343
|
+
const manager = findManager(org, 'pos_lead')
|
|
344
|
+
|
|
345
|
+
expect(manager).not.toBeNull()
|
|
346
|
+
expect(manager?.id).toBe('pos_cto')
|
|
347
|
+
expect(manager?.workerId).toBe('worker_jane')
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('should return null for position without manager', () => {
|
|
351
|
+
const org = createTestOrganization()
|
|
352
|
+
const manager = findManager(org, 'pos_cto')
|
|
353
|
+
|
|
354
|
+
expect(manager).toBeNull()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('should return null for non-existent position', () => {
|
|
358
|
+
const org = createTestOrganization()
|
|
359
|
+
const manager = findManager(org, 'non_existent')
|
|
360
|
+
|
|
361
|
+
expect(manager).toBeNull()
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
describe('Organization interface', () => {
|
|
366
|
+
it('should support full organization structure', () => {
|
|
367
|
+
const org: Organization = {
|
|
368
|
+
id: 'org_test',
|
|
369
|
+
name: 'Test Corp',
|
|
370
|
+
domain: 'test.com',
|
|
371
|
+
legalName: 'Test Corporation Inc.',
|
|
372
|
+
industry: 'technology',
|
|
373
|
+
mission: 'To make testing easy',
|
|
374
|
+
values: ['quality', 'speed', 'reliability'],
|
|
375
|
+
foundedAt: new Date('2020-01-01'),
|
|
376
|
+
headquarters: {
|
|
377
|
+
street: '123 Main St',
|
|
378
|
+
city: 'San Francisco',
|
|
379
|
+
state: 'CA',
|
|
380
|
+
postalCode: '94105',
|
|
381
|
+
country: 'USA',
|
|
382
|
+
},
|
|
383
|
+
settings: {
|
|
384
|
+
defaultCurrency: 'USD',
|
|
385
|
+
timezone: 'America/Los_Angeles',
|
|
386
|
+
workWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
|
|
387
|
+
businessHours: {
|
|
388
|
+
start: '09:00',
|
|
389
|
+
end: '17:00',
|
|
390
|
+
timezone: 'America/Los_Angeles',
|
|
391
|
+
},
|
|
392
|
+
fiscalYearStart: 1,
|
|
393
|
+
language: 'en',
|
|
394
|
+
dateFormat: 'MM/DD/YYYY',
|
|
395
|
+
},
|
|
396
|
+
departments: [],
|
|
397
|
+
teams: [],
|
|
398
|
+
roles: [],
|
|
399
|
+
metadata: { tier: 'enterprise' },
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
expect(org.name).toBe('Test Corp')
|
|
403
|
+
expect(org.headquarters?.city).toBe('San Francisco')
|
|
404
|
+
expect(org.settings?.timezone).toBe('America/Los_Angeles')
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
describe('Department interface', () => {
|
|
409
|
+
it('should support full department structure', () => {
|
|
410
|
+
const dept: Department = {
|
|
411
|
+
id: 'dept_test',
|
|
412
|
+
name: 'Test Department',
|
|
413
|
+
code: 'TEST',
|
|
414
|
+
description: 'Department for testing',
|
|
415
|
+
head: { positionId: 'pos_head', roleId: 'role_director' },
|
|
416
|
+
parentId: 'dept_parent',
|
|
417
|
+
teams: [],
|
|
418
|
+
budget: {
|
|
419
|
+
annual: 1000000,
|
|
420
|
+
currency: 'USD',
|
|
421
|
+
period: '2024',
|
|
422
|
+
categories: {
|
|
423
|
+
salaries: 700000,
|
|
424
|
+
tools: 100000,
|
|
425
|
+
training: 50000,
|
|
426
|
+
},
|
|
427
|
+
spent: 250000,
|
|
428
|
+
remaining: 750000,
|
|
429
|
+
},
|
|
430
|
+
costCenter: 'CC-100',
|
|
431
|
+
goals: ['Deliver Q1 roadmap', 'Improve team velocity'],
|
|
432
|
+
defaultPermissions: {
|
|
433
|
+
document: ['read', 'edit'],
|
|
434
|
+
},
|
|
435
|
+
metadata: { level: 'division' },
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
expect(dept.name).toBe('Test Department')
|
|
439
|
+
expect(dept.budget?.annual).toBe(1000000)
|
|
440
|
+
})
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
describe('Team interface', () => {
|
|
444
|
+
it('should support full team structure', () => {
|
|
445
|
+
const team: Team = {
|
|
446
|
+
id: 'team_test',
|
|
447
|
+
name: 'Test Team',
|
|
448
|
+
departmentId: 'dept_eng',
|
|
449
|
+
description: 'A team for testing',
|
|
450
|
+
lead: { positionId: 'pos_lead', roleId: 'role_lead' },
|
|
451
|
+
positions: [],
|
|
452
|
+
objectives: ['Ship feature X', 'Reduce tech debt'],
|
|
453
|
+
resources: {
|
|
454
|
+
repositories: ['repo-1', 'repo-2'],
|
|
455
|
+
projects: ['project-1'],
|
|
456
|
+
},
|
|
457
|
+
defaultPermissions: {
|
|
458
|
+
repository: ['read', 'edit'],
|
|
459
|
+
},
|
|
460
|
+
channels: {
|
|
461
|
+
slack: '#team-test',
|
|
462
|
+
email: 'team-test@acme.com',
|
|
463
|
+
},
|
|
464
|
+
metadata: { squad: true },
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
expect(team.name).toBe('Test Team')
|
|
468
|
+
expect(team.resources?.repositories).toContain('repo-1')
|
|
469
|
+
})
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
describe('Position interface', () => {
|
|
473
|
+
it('should support full position structure', () => {
|
|
474
|
+
const position: Position = {
|
|
475
|
+
id: 'pos_test',
|
|
476
|
+
title: 'Senior Engineer',
|
|
477
|
+
roleId: 'role_engineer',
|
|
478
|
+
workerId: 'worker_123',
|
|
479
|
+
workerType: 'human',
|
|
480
|
+
teamId: 'team_platform',
|
|
481
|
+
reportsTo: 'pos_lead',
|
|
482
|
+
directReports: ['pos_jr_1', 'pos_jr_2'],
|
|
483
|
+
additionalPermissions: {
|
|
484
|
+
'repository:special': ['manage'],
|
|
485
|
+
},
|
|
486
|
+
startDate: new Date('2023-01-15'),
|
|
487
|
+
endDate: undefined,
|
|
488
|
+
status: 'active',
|
|
489
|
+
fte: 1.0,
|
|
490
|
+
location: 'San Francisco',
|
|
491
|
+
workModel: 'hybrid',
|
|
492
|
+
compensation: {
|
|
493
|
+
baseSalary: 180000,
|
|
494
|
+
currency: 'USD',
|
|
495
|
+
frequency: 'annual',
|
|
496
|
+
bonusTarget: 15,
|
|
497
|
+
equity: {
|
|
498
|
+
type: 'rsu',
|
|
499
|
+
amount: 10000,
|
|
500
|
+
vestingSchedule: '4 years with 1 year cliff',
|
|
501
|
+
},
|
|
502
|
+
band: 'L5',
|
|
503
|
+
},
|
|
504
|
+
metadata: { promoted: true },
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
expect(position.title).toBe('Senior Engineer')
|
|
508
|
+
expect(position.compensation?.baseSalary).toBe(180000)
|
|
509
|
+
})
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
describe('ApprovalChain interface', () => {
|
|
513
|
+
it('should support full approval chain structure', () => {
|
|
514
|
+
const chain: ApprovalChain = {
|
|
515
|
+
id: 'chain_test',
|
|
516
|
+
name: 'Test Approval Chain',
|
|
517
|
+
type: 'purchase',
|
|
518
|
+
levels: [
|
|
519
|
+
{
|
|
520
|
+
threshold: 1000,
|
|
521
|
+
approvers: [{ type: 'direct-manager' }],
|
|
522
|
+
requiredApprovals: 1,
|
|
523
|
+
approvalMode: 'any',
|
|
524
|
+
slaHours: 24,
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
threshold: 10000,
|
|
528
|
+
approvers: [{ type: 'direct-manager' }, { type: 'role', roleId: 'finance_manager' }],
|
|
529
|
+
requiredApprovals: 2,
|
|
530
|
+
approvalMode: 'sequential',
|
|
531
|
+
slaHours: 48,
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
escalation: {
|
|
535
|
+
afterHours: 48,
|
|
536
|
+
escalateTo: 'skip-level-manager',
|
|
537
|
+
maxEscalations: 2,
|
|
538
|
+
},
|
|
539
|
+
active: true,
|
|
540
|
+
metadata: { version: 2 },
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
expect(chain.name).toBe('Test Approval Chain')
|
|
544
|
+
expect(chain.levels).toHaveLength(2)
|
|
545
|
+
expect(chain.escalation?.afterHours).toBe(48)
|
|
546
|
+
})
|
|
547
|
+
})
|
|
548
|
+
})
|