@critical-path/core 0.36.0 → 0.37.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 (214) hide show
  1. package/README.md +1 -1
  2. package/dist/domain/authorization.d.ts.map +1 -1
  3. package/dist/domain/authorization.js +10 -7
  4. package/dist/domain/authorization.js.map +1 -1
  5. package/dist/engine/index.d.ts +6 -0
  6. package/dist/engine/index.d.ts.map +1 -1
  7. package/dist/engine/index.js +28 -2
  8. package/dist/engine/index.js.map +1 -1
  9. package/dist/schemas/index.d.ts +42 -12
  10. package/dist/schemas/index.d.ts.map +1 -1
  11. package/dist/schemas/index.js +4 -1
  12. package/dist/schemas/index.js.map +1 -1
  13. package/dist/store/firebase.d.ts +2 -2
  14. package/dist/store/firebase.d.ts.map +1 -1
  15. package/dist/store/firebase.js +4 -2
  16. package/dist/store/firebase.js.map +1 -1
  17. package/dist/store/index.d.ts +7 -2
  18. package/dist/store/index.d.ts.map +1 -1
  19. package/dist/store/index.js +3 -2
  20. package/dist/store/index.js.map +1 -1
  21. package/dist/store/sqlite.d.ts +2 -2
  22. package/dist/store/sqlite.d.ts.map +1 -1
  23. package/dist/store/sqlite.js +5 -3
  24. package/dist/store/sqlite.js.map +1 -1
  25. package/dist/testing/conformance.d.ts.map +1 -1
  26. package/dist/testing/conformance.js +9 -0
  27. package/dist/testing/conformance.js.map +1 -1
  28. package/dist/types/index.d.ts +13 -2
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/package.json +5 -1
  31. package/CHANGELOG.md +0 -593
  32. package/dist/deliverables.test.d.ts +0 -2
  33. package/dist/deliverables.test.d.ts.map +0 -1
  34. package/dist/deliverables.test.js +0 -232
  35. package/dist/deliverables.test.js.map +0 -1
  36. package/dist/domain/calendar.test.d.ts +0 -2
  37. package/dist/domain/calendar.test.d.ts.map +0 -1
  38. package/dist/domain/calendar.test.js +0 -181
  39. package/dist/domain/calendar.test.js.map +0 -1
  40. package/dist/domain/cpm.test.d.ts +0 -2
  41. package/dist/domain/cpm.test.d.ts.map +0 -1
  42. package/dist/domain/cpm.test.js +0 -166
  43. package/dist/domain/cpm.test.js.map +0 -1
  44. package/dist/domain/ddd.test.d.ts +0 -2
  45. package/dist/domain/ddd.test.d.ts.map +0 -1
  46. package/dist/domain/ddd.test.js +0 -349
  47. package/dist/domain/ddd.test.js.map +0 -1
  48. package/dist/domain/ladder.test.d.ts +0 -2
  49. package/dist/domain/ladder.test.d.ts.map +0 -1
  50. package/dist/domain/ladder.test.js +0 -213
  51. package/dist/domain/ladder.test.js.map +0 -1
  52. package/dist/domain/metrics.test.d.ts +0 -2
  53. package/dist/domain/metrics.test.d.ts.map +0 -1
  54. package/dist/domain/metrics.test.js +0 -252
  55. package/dist/domain/metrics.test.js.map +0 -1
  56. package/dist/domain/task-duration.test.d.ts +0 -2
  57. package/dist/domain/task-duration.test.d.ts.map +0 -1
  58. package/dist/domain/task-duration.test.js +0 -307
  59. package/dist/domain/task-duration.test.js.map +0 -1
  60. package/dist/domain/workload.test.d.ts +0 -2
  61. package/dist/domain/workload.test.d.ts.map +0 -1
  62. package/dist/domain/workload.test.js +0 -261
  63. package/dist/domain/workload.test.js.map +0 -1
  64. package/dist/engine/actor.test.d.ts +0 -2
  65. package/dist/engine/actor.test.d.ts.map +0 -1
  66. package/dist/engine/actor.test.js +0 -54
  67. package/dist/engine/actor.test.js.map +0 -1
  68. package/dist/engine/authorization.test.d.ts +0 -2
  69. package/dist/engine/authorization.test.d.ts.map +0 -1
  70. package/dist/engine/authorization.test.js +0 -154
  71. package/dist/engine/authorization.test.js.map +0 -1
  72. package/dist/engine/cascade.test.d.ts +0 -2
  73. package/dist/engine/cascade.test.d.ts.map +0 -1
  74. package/dist/engine/cascade.test.js +0 -99
  75. package/dist/engine/cascade.test.js.map +0 -1
  76. package/dist/engine/config.test.d.ts +0 -2
  77. package/dist/engine/config.test.d.ts.map +0 -1
  78. package/dist/engine/config.test.js +0 -46
  79. package/dist/engine/config.test.js.map +0 -1
  80. package/dist/engine/entity-events.test.d.ts +0 -2
  81. package/dist/engine/entity-events.test.d.ts.map +0 -1
  82. package/dist/engine/entity-events.test.js +0 -61
  83. package/dist/engine/entity-events.test.js.map +0 -1
  84. package/dist/index.test.d.ts +0 -2
  85. package/dist/index.test.d.ts.map +0 -1
  86. package/dist/index.test.js +0 -429
  87. package/dist/index.test.js.map +0 -1
  88. package/dist/plugins/plugins.test.d.ts +0 -2
  89. package/dist/plugins/plugins.test.d.ts.map +0 -1
  90. package/dist/plugins/plugins.test.js +0 -137
  91. package/dist/plugins/plugins.test.js.map +0 -1
  92. package/dist/schemas/schemas.test.d.ts +0 -2
  93. package/dist/schemas/schemas.test.d.ts.map +0 -1
  94. package/dist/schemas/schemas.test.js +0 -58
  95. package/dist/schemas/schemas.test.js.map +0 -1
  96. package/dist/status.test.d.ts +0 -2
  97. package/dist/status.test.d.ts.map +0 -1
  98. package/dist/status.test.js +0 -295
  99. package/dist/status.test.js.map +0 -1
  100. package/dist/storage/storage.test.d.ts +0 -2
  101. package/dist/storage/storage.test.d.ts.map +0 -1
  102. package/dist/storage/storage.test.js +0 -236
  103. package/dist/storage/storage.test.js.map +0 -1
  104. package/dist/storage/upload-limits.test.d.ts +0 -2
  105. package/dist/storage/upload-limits.test.d.ts.map +0 -1
  106. package/dist/storage/upload-limits.test.js +0 -31
  107. package/dist/storage/upload-limits.test.js.map +0 -1
  108. package/dist/store/conformance.test.d.ts +0 -2
  109. package/dist/store/conformance.test.d.ts.map +0 -1
  110. package/dist/store/conformance.test.js +0 -15
  111. package/dist/store/conformance.test.js.map +0 -1
  112. package/dist/store/firebase.test.d.ts +0 -2
  113. package/dist/store/firebase.test.d.ts.map +0 -1
  114. package/dist/store/firebase.test.js +0 -103
  115. package/dist/store/firebase.test.js.map +0 -1
  116. package/dist/store/query.test.d.ts +0 -2
  117. package/dist/store/query.test.d.ts.map +0 -1
  118. package/dist/store/query.test.js +0 -89
  119. package/dist/store/query.test.js.map +0 -1
  120. package/dist/store/sqlite.test.d.ts +0 -2
  121. package/dist/store/sqlite.test.d.ts.map +0 -1
  122. package/dist/store/sqlite.test.js +0 -177
  123. package/dist/store/sqlite.test.js.map +0 -1
  124. package/dist/task-state.test.d.ts +0 -2
  125. package/dist/task-state.test.d.ts.map +0 -1
  126. package/dist/task-state.test.js +0 -423
  127. package/dist/task-state.test.js.map +0 -1
  128. package/dist/use-case-validation.test.d.ts +0 -2
  129. package/dist/use-case-validation.test.d.ts.map +0 -1
  130. package/dist/use-case-validation.test.js +0 -281
  131. package/dist/use-case-validation.test.js.map +0 -1
  132. package/dist/utils/fractional-index.test.d.ts +0 -2
  133. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  134. package/dist/utils/fractional-index.test.js +0 -182
  135. package/dist/utils/fractional-index.test.js.map +0 -1
  136. package/dist/utils/key.test.d.ts +0 -2
  137. package/dist/utils/key.test.d.ts.map +0 -1
  138. package/dist/utils/key.test.js +0 -65
  139. package/dist/utils/key.test.js.map +0 -1
  140. package/dist/utils/mentions.test.d.ts +0 -2
  141. package/dist/utils/mentions.test.d.ts.map +0 -1
  142. package/dist/utils/mentions.test.js +0 -114
  143. package/dist/utils/mentions.test.js.map +0 -1
  144. package/dist/webhooks/webhooks.test.d.ts +0 -2
  145. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  146. package/dist/webhooks/webhooks.test.js +0 -154
  147. package/dist/webhooks/webhooks.test.js.map +0 -1
  148. package/src/deliverables.test.ts +0 -284
  149. package/src/domain/authorization.ts +0 -82
  150. package/src/domain/calendar.test.ts +0 -216
  151. package/src/domain/calendar.ts +0 -502
  152. package/src/domain/cpm.test.ts +0 -189
  153. package/src/domain/cpm.ts +0 -258
  154. package/src/domain/custom-fields.ts +0 -172
  155. package/src/domain/ddd.test.ts +0 -442
  156. package/src/domain/entities.ts +0 -798
  157. package/src/domain/errors.ts +0 -38
  158. package/src/domain/events.ts +0 -369
  159. package/src/domain/graph.ts +0 -70
  160. package/src/domain/index.ts +0 -12
  161. package/src/domain/ladder.test.ts +0 -251
  162. package/src/domain/ladder.ts +0 -474
  163. package/src/domain/metrics.test.ts +0 -288
  164. package/src/domain/metrics.ts +0 -497
  165. package/src/domain/task-duration.test.ts +0 -354
  166. package/src/domain/workload.test.ts +0 -311
  167. package/src/domain/workload.ts +0 -457
  168. package/src/engine/actor.test.ts +0 -63
  169. package/src/engine/authorization.test.ts +0 -199
  170. package/src/engine/cascade.test.ts +0 -121
  171. package/src/engine/config.test.ts +0 -51
  172. package/src/engine/entity-events.test.ts +0 -67
  173. package/src/engine/index.ts +0 -2495
  174. package/src/index.test.ts +0 -514
  175. package/src/index.ts +0 -9
  176. package/src/plugins/index.ts +0 -103
  177. package/src/plugins/plugins.test.ts +0 -161
  178. package/src/schemas/index.ts +0 -402
  179. package/src/schemas/schemas.test.ts +0 -116
  180. package/src/status.test.ts +0 -354
  181. package/src/storage/file-storage.ts +0 -200
  182. package/src/storage/firebase-storage.ts +0 -209
  183. package/src/storage/index.ts +0 -3
  184. package/src/storage/s3.ts +0 -151
  185. package/src/storage/storage.test.ts +0 -274
  186. package/src/storage/upload-limits.test.ts +0 -41
  187. package/src/store/conformance.test.ts +0 -15
  188. package/src/store/firebase.test.ts +0 -131
  189. package/src/store/firebase.ts +0 -658
  190. package/src/store/index.ts +0 -623
  191. package/src/store/query.test.ts +0 -110
  192. package/src/store/query.ts +0 -113
  193. package/src/store/sqlite.test.ts +0 -218
  194. package/src/store/sqlite.ts +0 -1480
  195. package/src/task-state.test.ts +0 -506
  196. package/src/testing/conformance.ts +0 -319
  197. package/src/testing/index.ts +0 -1
  198. package/src/types/index.ts +0 -871
  199. package/src/use-case-validation.test.ts +0 -324
  200. package/src/utils/fractional-index.test.ts +0 -228
  201. package/src/utils/fractional-index.ts +0 -254
  202. package/src/utils/index.ts +0 -7
  203. package/src/utils/key.test.ts +0 -76
  204. package/src/utils/key.ts +0 -62
  205. package/src/utils/mentions.test.ts +0 -132
  206. package/src/utils/mentions.ts +0 -131
  207. package/src/utils/status.ts +0 -419
  208. package/src/utils/workflow.ts +0 -306
  209. package/src/webhooks/dispatcher.ts +0 -190
  210. package/src/webhooks/index.ts +0 -2
  211. package/src/webhooks/signature.ts +0 -57
  212. package/src/webhooks/webhooks.test.ts +0 -201
  213. package/tsconfig.json +0 -8
  214. package/tsconfig.tsbuildinfo +0 -1
@@ -1,82 +0,0 @@
1
- import type {
2
- Actor,
3
- AuthorizationAction,
4
- AuthorizationPolicy,
5
- AuthorizationRequest,
6
- ProjectRole
7
- } from '../types/index.js';
8
-
9
- const VIEWER: AuthorizationAction[] = ['project.read'];
10
- const CONTRIBUTOR: AuthorizationAction[] = [
11
- ...VIEWER,
12
- 'task.create',
13
- 'task.update',
14
- 'comment.create',
15
- 'attachment.create',
16
- 'time.log'
17
- ];
18
- const PROJECT_MANAGER: AuthorizationAction[] = [
19
- ...CONTRIBUTOR,
20
- 'task.delete',
21
- 'plan.manage',
22
- 'project.update',
23
- 'project.manage_members',
24
- 'comment.moderate',
25
- 'attachment.delete'
26
- ];
27
- const PROJECT_ADMIN: AuthorizationAction[] = [...PROJECT_MANAGER, 'project.delete'];
28
-
29
- /** Actions each project role grants by default. */
30
- export const DEFAULT_ROLE_PERMISSIONS: Record<ProjectRole, readonly AuthorizationAction[]> = {
31
- viewer: VIEWER,
32
- contributor: CONTRIBUTOR,
33
- project_manager: PROJECT_MANAGER,
34
- admin: PROJECT_ADMIN
35
- };
36
-
37
- export interface RolePolicyOptions {
38
- /** Override or extend the actions granted to each project role. */
39
- rolePermissions?: Partial<Record<ProjectRole, readonly AuthorizationAction[]>>;
40
- /** Workspace roles (from `actor.roles`) that may do anything within their tenant. Default `['admin']`. */
41
- superuserRoles?: string[];
42
- /**
43
- * Who may create projects (they become the project's `admin`). Default: any actor except the
44
- * anonymous one (`userId === 'anonymous'`).
45
- */
46
- canCreateProjects?: (actor: Actor) => boolean;
47
- /** Who may manage workflows, teams and webhooks. Default: superusers only. */
48
- canManageWorkspace?: (actor: Actor) => boolean;
49
- }
50
-
51
- /**
52
- * Role-based policy driven by `project.members`. Members get their role's actions on that project;
53
- * authors may edit and delete their own comments and attachments; workspace superusers may do
54
- * everything. Everyone else is denied.
55
- */
56
- export function createRolePolicy(options: RolePolicyOptions = {}): AuthorizationPolicy {
57
- const permissions = { ...DEFAULT_ROLE_PERMISSIONS, ...options.rolePermissions };
58
- const superuserRoles = options.superuserRoles ?? ['admin'];
59
- const isSuperuser = (actor: Actor) => (actor.roles ?? []).some((r) => superuserRoles.includes(r));
60
- const canCreateProjects = options.canCreateProjects ?? ((actor: Actor) => actor.userId !== 'anonymous');
61
- const canManageWorkspace = options.canManageWorkspace ?? isSuperuser;
62
-
63
- return ({ actor, action, project, resource }: AuthorizationRequest): boolean => {
64
- if (isSuperuser(actor)) return true;
65
- if (action === 'project.create') return canCreateProjects(actor);
66
- if (action === 'workspace.manage') return canManageWorkspace(actor);
67
- if (!project) return false;
68
-
69
- const role = project.members?.find((m) => m.userId === actor.userId)?.role;
70
- if (!role) return false;
71
-
72
- const granted = permissions[role] ?? [];
73
- if (granted.includes(action)) return true;
74
-
75
- // Authors manage their own comments and attachments without moderator rights.
76
- const ownsResource = resource?.ownerId !== undefined && resource.ownerId === actor.userId;
77
- if (action === 'comment.moderate' && ownsResource && granted.includes('comment.create')) return true;
78
- if (action === 'attachment.delete' && ownsResource && granted.includes('attachment.create')) return true;
79
-
80
- return false;
81
- };
82
- }
@@ -1,216 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import {
3
- DEFAULT_WORK_SCHEDULE,
4
- resolveEffectiveSchedule,
5
- isWorkingDay,
6
- getWorkingHoursInDay,
7
- addWorkingHours,
8
- subtractWorkingHours,
9
- getWorkingHoursBetween,
10
- getWorkingDaysBetween,
11
- getWorkingDaysList,
12
- getNetAvailableCapacity,
13
- formatTaskDuration
14
- } from './calendar.js';
15
- import type { WorkSchedule } from '../types/index.js';
16
-
17
- describe('Calendar and Work Schedule Domain', () => {
18
- describe('resolveEffectiveSchedule', () => {
19
- const customUserSchedule: WorkSchedule = {
20
- name: 'User 30h',
21
- defaultHoursPerDay: 6,
22
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
23
- };
24
- const customTeamSchedule: WorkSchedule = {
25
- name: 'Team 35h',
26
- defaultHoursPerDay: 7,
27
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
28
- };
29
- const customProjectSchedule: WorkSchedule = {
30
- name: 'Project 4-Day',
31
- defaultHoursPerDay: 10,
32
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
33
- };
34
-
35
- it('prioritizes user schedule when present', () => {
36
- const resolved = resolveEffectiveSchedule({
37
- user: { id: 'u1', name: 'Alice', email: 'alice@test.com', role: 'contributor', schedule: customUserSchedule, createdAt: '' },
38
- team: { id: 't1', name: 'Dev', memberIds: [], schedule: customTeamSchedule, createdAt: '', updatedAt: '' },
39
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
40
- });
41
- expect(resolved.name).toBe('User 30h');
42
- });
43
-
44
- it('falls back to team schedule when user has no custom schedule', () => {
45
- const resolved = resolveEffectiveSchedule({
46
- user: { id: 'u1', name: 'Alice', email: 'alice@test.com', role: 'contributor', createdAt: '' },
47
- team: { id: 't1', name: 'Dev', memberIds: [], schedule: customTeamSchedule, createdAt: '', updatedAt: '' },
48
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
49
- });
50
- expect(resolved.name).toBe('Team 35h');
51
- });
52
-
53
- it('falls back to project schedule when user and team have no schedule', () => {
54
- const resolved = resolveEffectiveSchedule({
55
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
56
- });
57
- expect(resolved.name).toBe('Project 4-Day');
58
- });
59
-
60
- it('falls back to engine default or DEFAULT_WORK_SCHEDULE', () => {
61
- const resolved = resolveEffectiveSchedule();
62
- expect(resolved.name).toBe(DEFAULT_WORK_SCHEDULE.name);
63
- expect(resolved.defaultHoursPerDay).toBe(8);
64
- });
65
- });
66
-
67
- describe('isWorkingDay and getWorkingHoursInDay', () => {
68
- // 2026-09-18 is Friday, 2026-09-19 is Saturday, 2026-09-20 is Sunday, 2026-09-21 is Monday
69
- it('identifies weekdays as working days and weekends as non-working days by default', () => {
70
- expect(isWorkingDay('2026-09-18')).toBe(true); // Friday
71
- expect(isWorkingDay('2026-09-19')).toBe(false); // Saturday
72
- expect(isWorkingDay('2026-09-20')).toBe(false); // Sunday
73
- expect(isWorkingDay('2026-09-21')).toBe(true); // Monday
74
-
75
- expect(getWorkingHoursInDay('2026-09-18')).toBe(8);
76
- expect(getWorkingHoursInDay('2026-09-19')).toBe(0);
77
- expect(getWorkingHoursInDay('2026-09-20')).toBe(0);
78
- });
79
-
80
- it('accounts for full and half-day holidays', () => {
81
- const holidaySchedule: WorkSchedule = {
82
- ...DEFAULT_WORK_SCHEDULE,
83
- holidays: [
84
- { date: '2026-09-21', name: 'Labor Day' },
85
- { date: '2026-09-22', name: 'Eve', halfDay: true }
86
- ]
87
- };
88
-
89
- expect(isWorkingDay('2026-09-21', holidaySchedule)).toBe(false);
90
- expect(getWorkingHoursInDay('2026-09-21', holidaySchedule)).toBe(0);
91
-
92
- expect(isWorkingDay('2026-09-22', holidaySchedule)).toBe(true);
93
- expect(getWorkingHoursInDay('2026-09-22', holidaySchedule)).toBe(4);
94
- });
95
- });
96
-
97
- describe('addWorkingHours', () => {
98
- it('advances hours within the same working day', () => {
99
- // Monday 2026-09-21 at 09:00 + 4 hours -> 13:00
100
- const start = '2026-09-21T09:00:00Z';
101
- const finish = addWorkingHours(start, 4);
102
- expect(finish.toISOString()).toBe('2026-09-21T13:00:00.000Z');
103
- });
104
-
105
- it('rolls over weekends seamlessly', () => {
106
- // Friday 2026-09-18 at 15:00 + 4 hours
107
- // 15:00-17:00 is 2h on Friday. Sat & Sun skipped.
108
- // Remaining 2h starts Monday 2026-09-21 at 09:00 -> finishes 11:00!
109
- const start = '2026-09-18T15:00:00Z';
110
- const finish = addWorkingHours(start, 4);
111
- expect(finish.toISOString()).toBe('2026-09-21T11:00:00.000Z');
112
- });
113
-
114
- it('skips holidays when rolling over', () => {
115
- const scheduleWithMondayHoliday: WorkSchedule = {
116
- ...DEFAULT_WORK_SCHEDULE,
117
- holidays: [{ date: '2026-09-21', name: 'Bank Holiday' }]
118
- };
119
- // Friday 2026-09-18 at 15:00 + 4 hours -> 2h Friday, Sat/Sun skipped, Mon skipped -> finishes Tuesday 11:00!
120
- const start = '2026-09-18T15:00:00Z';
121
- const finish = addWorkingHours(start, 4, scheduleWithMondayHoliday);
122
- expect(finish.toISOString()).toBe('2026-09-22T11:00:00.000Z');
123
- });
124
- });
125
-
126
- describe('subtractWorkingHours', () => {
127
- it('moves backward within the same working day', () => {
128
- // Monday 2026-09-21 at 15:00 - 4 hours -> 11:00
129
- const end = '2026-09-21T15:00:00Z';
130
- const start = subtractWorkingHours(end, 4);
131
- expect(start.toISOString()).toBe('2026-09-21T11:00:00.000Z');
132
- });
133
-
134
- it('moves backward across weekends', () => {
135
- // Monday 2026-09-21 at 11:00 - 4 hours
136
- // 2h backwards to 09:00 on Monday. Sunday & Saturday skipped.
137
- // Remaining 2h backwards from Friday 17:00 -> 15:00!
138
- const end = '2026-09-21T11:00:00Z';
139
- const start = subtractWorkingHours(end, 4);
140
- expect(start.toISOString()).toBe('2026-09-18T15:00:00.000Z');
141
- });
142
- });
143
-
144
- describe('getWorkingHoursBetween and getWorkingDaysBetween', () => {
145
- it('calculates working hours between two dates excluding weekends', () => {
146
- // Friday 09:00 to Monday 17:00 = 8h (Friday) + 0h (weekend) + 8h (Monday) = 16h
147
- const start = '2026-09-18T09:00:00Z';
148
- const end = '2026-09-21T17:00:00Z';
149
- expect(getWorkingHoursBetween(start, end)).toBe(16);
150
- expect(getWorkingDaysBetween('2026-09-18', '2026-09-21')).toBe(2);
151
- expect(getWorkingDaysList('2026-09-18', '2026-09-21')).toEqual(['2026-09-18', '2026-09-21']);
152
- });
153
-
154
- it('calculates net capacity deducting holidays', () => {
155
- const scheduleWithHoliday: WorkSchedule = {
156
- ...DEFAULT_WORK_SCHEDULE,
157
- holidays: [{ date: '2026-09-21', name: 'Holiday' }]
158
- };
159
- // Friday 2026-09-18 to Tuesday 2026-09-22:
160
- // Friday (8) + Sat (0) + Sun (0) + Mon (0, holiday) + Tue (8) = 16h
161
- const cap = getNetAvailableCapacity('2026-09-18', '2026-09-22', scheduleWithHoliday);
162
- expect(cap).toBe(16);
163
- });
164
- });
165
-
166
- describe('formatTaskDuration', () => {
167
- it('handles null, undefined, NaN, and negative values', () => {
168
- expect(formatTaskDuration(null)).toBe('0s');
169
- expect(formatTaskDuration(undefined)).toBe('0s');
170
- expect(formatTaskDuration(NaN)).toBe('0s');
171
- expect(formatTaskDuration(-5)).toBe('0s');
172
- expect(formatTaskDuration(0)).toBe('0s');
173
- });
174
-
175
- it('formats short durations under 120s with seconds', () => {
176
- expect(formatTaskDuration(45)).toBe('45s');
177
- expect(formatTaskDuration(110.3)).toBe('110.3s');
178
- expect(formatTaskDuration(119.9)).toBe('119.9s');
179
- expect(formatTaskDuration(1.5)).toBe('1.5s');
180
- });
181
-
182
- it('formats sub-day durations with hours and minutes', () => {
183
- // 44 minutes = 2640s
184
- expect(formatTaskDuration(2640)).toBe('0h 44m');
185
- // 2h 15m = 8100s
186
- expect(formatTaskDuration(8100)).toBe('2h 15m');
187
- // 7h 59m = 28740s (< 8h working day)
188
- expect(formatTaskDuration(28740)).toBe('7h 59m');
189
- });
190
-
191
- it('formats multi-day durations using default 8h working days', () => {
192
- // 8 hours = 28800s -> 1 day
193
- expect(formatTaskDuration(28800)).toBe('1 day');
194
- // 12 hours = 43200s -> 1.5 days
195
- expect(formatTaskDuration(43200)).toBe('1.5 days');
196
- // 25.6 hours = 92160s -> 3.2 days
197
- expect(formatTaskDuration(92160)).toBe('3.2 days');
198
- });
199
-
200
- it('supports calendar_days basis (24h per day)', () => {
201
- // 12 hours on calendar days basis -> 12h 0m (< 24h)
202
- expect(formatTaskDuration(43200, { dayBasis: 'calendar_days' })).toBe('12h 0m');
203
- // 36 hours on calendar days basis -> 1.5 days
204
- expect(formatTaskDuration(129600, { dayBasis: 'calendar_days' })).toBe('1.5 days');
205
- });
206
-
207
- it('supports custom work schedules', () => {
208
- const fourHourDaySchedule: WorkSchedule = {
209
- ...DEFAULT_WORK_SCHEDULE,
210
- defaultHoursPerDay: 4
211
- };
212
- // 6 hours with 4h/day schedule = 1.5 days
213
- expect(formatTaskDuration(21600, { schedule: fourHourDaySchedule })).toBe('1.5 days');
214
- });
215
- });
216
- });