@critical-path/core 0.36.0 → 0.36.1
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/package.json +5 -1
- package/CHANGELOG.md +0 -593
- package/dist/deliverables.test.d.ts +0 -2
- package/dist/deliverables.test.d.ts.map +0 -1
- package/dist/deliverables.test.js +0 -232
- package/dist/deliverables.test.js.map +0 -1
- package/dist/domain/calendar.test.d.ts +0 -2
- package/dist/domain/calendar.test.d.ts.map +0 -1
- package/dist/domain/calendar.test.js +0 -181
- package/dist/domain/calendar.test.js.map +0 -1
- package/dist/domain/cpm.test.d.ts +0 -2
- package/dist/domain/cpm.test.d.ts.map +0 -1
- package/dist/domain/cpm.test.js +0 -166
- package/dist/domain/cpm.test.js.map +0 -1
- package/dist/domain/ddd.test.d.ts +0 -2
- package/dist/domain/ddd.test.d.ts.map +0 -1
- package/dist/domain/ddd.test.js +0 -349
- package/dist/domain/ddd.test.js.map +0 -1
- package/dist/domain/ladder.test.d.ts +0 -2
- package/dist/domain/ladder.test.d.ts.map +0 -1
- package/dist/domain/ladder.test.js +0 -213
- package/dist/domain/ladder.test.js.map +0 -1
- package/dist/domain/metrics.test.d.ts +0 -2
- package/dist/domain/metrics.test.d.ts.map +0 -1
- package/dist/domain/metrics.test.js +0 -252
- package/dist/domain/metrics.test.js.map +0 -1
- package/dist/domain/task-duration.test.d.ts +0 -2
- package/dist/domain/task-duration.test.d.ts.map +0 -1
- package/dist/domain/task-duration.test.js +0 -307
- package/dist/domain/task-duration.test.js.map +0 -1
- package/dist/domain/workload.test.d.ts +0 -2
- package/dist/domain/workload.test.d.ts.map +0 -1
- package/dist/domain/workload.test.js +0 -261
- package/dist/domain/workload.test.js.map +0 -1
- package/dist/engine/actor.test.d.ts +0 -2
- package/dist/engine/actor.test.d.ts.map +0 -1
- package/dist/engine/actor.test.js +0 -54
- package/dist/engine/actor.test.js.map +0 -1
- package/dist/engine/authorization.test.d.ts +0 -2
- package/dist/engine/authorization.test.d.ts.map +0 -1
- package/dist/engine/authorization.test.js +0 -154
- package/dist/engine/authorization.test.js.map +0 -1
- package/dist/engine/cascade.test.d.ts +0 -2
- package/dist/engine/cascade.test.d.ts.map +0 -1
- package/dist/engine/cascade.test.js +0 -99
- package/dist/engine/cascade.test.js.map +0 -1
- package/dist/engine/config.test.d.ts +0 -2
- package/dist/engine/config.test.d.ts.map +0 -1
- package/dist/engine/config.test.js +0 -46
- package/dist/engine/config.test.js.map +0 -1
- package/dist/engine/entity-events.test.d.ts +0 -2
- package/dist/engine/entity-events.test.d.ts.map +0 -1
- package/dist/engine/entity-events.test.js +0 -61
- package/dist/engine/entity-events.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -429
- package/dist/index.test.js.map +0 -1
- package/dist/plugins/plugins.test.d.ts +0 -2
- package/dist/plugins/plugins.test.d.ts.map +0 -1
- package/dist/plugins/plugins.test.js +0 -137
- package/dist/plugins/plugins.test.js.map +0 -1
- package/dist/schemas/schemas.test.d.ts +0 -2
- package/dist/schemas/schemas.test.d.ts.map +0 -1
- package/dist/schemas/schemas.test.js +0 -58
- package/dist/schemas/schemas.test.js.map +0 -1
- package/dist/status.test.d.ts +0 -2
- package/dist/status.test.d.ts.map +0 -1
- package/dist/status.test.js +0 -295
- package/dist/status.test.js.map +0 -1
- package/dist/storage/storage.test.d.ts +0 -2
- package/dist/storage/storage.test.d.ts.map +0 -1
- package/dist/storage/storage.test.js +0 -236
- package/dist/storage/storage.test.js.map +0 -1
- package/dist/storage/upload-limits.test.d.ts +0 -2
- package/dist/storage/upload-limits.test.d.ts.map +0 -1
- package/dist/storage/upload-limits.test.js +0 -31
- package/dist/storage/upload-limits.test.js.map +0 -1
- package/dist/store/conformance.test.d.ts +0 -2
- package/dist/store/conformance.test.d.ts.map +0 -1
- package/dist/store/conformance.test.js +0 -15
- package/dist/store/conformance.test.js.map +0 -1
- package/dist/store/firebase.test.d.ts +0 -2
- package/dist/store/firebase.test.d.ts.map +0 -1
- package/dist/store/firebase.test.js +0 -103
- package/dist/store/firebase.test.js.map +0 -1
- package/dist/store/query.test.d.ts +0 -2
- package/dist/store/query.test.d.ts.map +0 -1
- package/dist/store/query.test.js +0 -89
- package/dist/store/query.test.js.map +0 -1
- package/dist/store/sqlite.test.d.ts +0 -2
- package/dist/store/sqlite.test.d.ts.map +0 -1
- package/dist/store/sqlite.test.js +0 -177
- package/dist/store/sqlite.test.js.map +0 -1
- package/dist/task-state.test.d.ts +0 -2
- package/dist/task-state.test.d.ts.map +0 -1
- package/dist/task-state.test.js +0 -423
- package/dist/task-state.test.js.map +0 -1
- package/dist/use-case-validation.test.d.ts +0 -2
- package/dist/use-case-validation.test.d.ts.map +0 -1
- package/dist/use-case-validation.test.js +0 -281
- package/dist/use-case-validation.test.js.map +0 -1
- package/dist/utils/fractional-index.test.d.ts +0 -2
- package/dist/utils/fractional-index.test.d.ts.map +0 -1
- package/dist/utils/fractional-index.test.js +0 -182
- package/dist/utils/fractional-index.test.js.map +0 -1
- package/dist/utils/key.test.d.ts +0 -2
- package/dist/utils/key.test.d.ts.map +0 -1
- package/dist/utils/key.test.js +0 -65
- package/dist/utils/key.test.js.map +0 -1
- package/dist/utils/mentions.test.d.ts +0 -2
- package/dist/utils/mentions.test.d.ts.map +0 -1
- package/dist/utils/mentions.test.js +0 -114
- package/dist/utils/mentions.test.js.map +0 -1
- package/dist/webhooks/webhooks.test.d.ts +0 -2
- package/dist/webhooks/webhooks.test.d.ts.map +0 -1
- package/dist/webhooks/webhooks.test.js +0 -154
- package/dist/webhooks/webhooks.test.js.map +0 -1
- package/src/deliverables.test.ts +0 -284
- package/src/domain/authorization.ts +0 -82
- package/src/domain/calendar.test.ts +0 -216
- package/src/domain/calendar.ts +0 -502
- package/src/domain/cpm.test.ts +0 -189
- package/src/domain/cpm.ts +0 -258
- package/src/domain/custom-fields.ts +0 -172
- package/src/domain/ddd.test.ts +0 -442
- package/src/domain/entities.ts +0 -798
- package/src/domain/errors.ts +0 -38
- package/src/domain/events.ts +0 -369
- package/src/domain/graph.ts +0 -70
- package/src/domain/index.ts +0 -12
- package/src/domain/ladder.test.ts +0 -251
- package/src/domain/ladder.ts +0 -474
- package/src/domain/metrics.test.ts +0 -288
- package/src/domain/metrics.ts +0 -497
- package/src/domain/task-duration.test.ts +0 -354
- package/src/domain/workload.test.ts +0 -311
- package/src/domain/workload.ts +0 -457
- package/src/engine/actor.test.ts +0 -63
- package/src/engine/authorization.test.ts +0 -199
- package/src/engine/cascade.test.ts +0 -121
- package/src/engine/config.test.ts +0 -51
- package/src/engine/entity-events.test.ts +0 -67
- package/src/engine/index.ts +0 -2495
- package/src/index.test.ts +0 -514
- package/src/index.ts +0 -9
- package/src/plugins/index.ts +0 -103
- package/src/plugins/plugins.test.ts +0 -161
- package/src/schemas/index.ts +0 -402
- package/src/schemas/schemas.test.ts +0 -116
- package/src/status.test.ts +0 -354
- package/src/storage/file-storage.ts +0 -200
- package/src/storage/firebase-storage.ts +0 -209
- package/src/storage/index.ts +0 -3
- package/src/storage/s3.ts +0 -151
- package/src/storage/storage.test.ts +0 -274
- package/src/storage/upload-limits.test.ts +0 -41
- package/src/store/conformance.test.ts +0 -15
- package/src/store/firebase.test.ts +0 -131
- package/src/store/firebase.ts +0 -658
- package/src/store/index.ts +0 -623
- package/src/store/query.test.ts +0 -110
- package/src/store/query.ts +0 -113
- package/src/store/sqlite.test.ts +0 -218
- package/src/store/sqlite.ts +0 -1480
- package/src/task-state.test.ts +0 -506
- package/src/testing/conformance.ts +0 -319
- package/src/testing/index.ts +0 -1
- package/src/types/index.ts +0 -871
- package/src/use-case-validation.test.ts +0 -324
- package/src/utils/fractional-index.test.ts +0 -228
- package/src/utils/fractional-index.ts +0 -254
- package/src/utils/index.ts +0 -7
- package/src/utils/key.test.ts +0 -76
- package/src/utils/key.ts +0 -62
- package/src/utils/mentions.test.ts +0 -132
- package/src/utils/mentions.ts +0 -131
- package/src/utils/status.ts +0 -419
- package/src/utils/workflow.ts +0 -306
- package/src/webhooks/dispatcher.ts +0 -190
- package/src/webhooks/index.ts +0 -2
- package/src/webhooks/signature.ts +0 -57
- package/src/webhooks/webhooks.test.ts +0 -201
- package/tsconfig.json +0 -8
- 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
|
-
});
|