Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { TimePeriodSuggester } from '../src/lib/timePeriodSuggester';
|
|
import type { ITimePeriod, ITimePeriodSettings } from '@alga-psa/types';
|
|
|
|
function makeSettings(overrides: Partial<ITimePeriodSettings>): ITimePeriodSettings {
|
|
return {
|
|
time_period_settings_id: 'settings-1',
|
|
frequency: 1,
|
|
frequency_unit: 'week',
|
|
is_active: true,
|
|
effective_from: '2026-01-01T00:00:00.000Z',
|
|
effective_to: undefined,
|
|
created_at: '2026-01-01T00:00:00.000Z',
|
|
updated_at: '2026-01-01T00:00:00.000Z',
|
|
tenant: 'tenant-1',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('TimePeriodSuggester', () => {
|
|
test('suggests next weekly period from latest end_date', () => {
|
|
const settings = [makeSettings({ frequency_unit: 'week', frequency: 1, start_day: 1 })];
|
|
|
|
const existingPeriods: ITimePeriod[] = [
|
|
{
|
|
tenant: 'tenant-1',
|
|
period_id: 'p1',
|
|
start_date: '2025-12-25',
|
|
end_date: '2026-01-01',
|
|
},
|
|
];
|
|
|
|
const result = TimePeriodSuggester.suggestNewTimePeriod(settings, existingPeriods);
|
|
expect(result.success).toBe(true);
|
|
expect(result.data?.start_date).toBe('2026-01-01');
|
|
expect(result.data?.end_date).toBe('2026-01-08');
|
|
});
|
|
|
|
test('supports semi-monthly month settings using start_day/end_day', () => {
|
|
const settings = [makeSettings({ frequency_unit: 'month', frequency: 1, start_day: 1, end_day: 16 })];
|
|
|
|
const existingPeriods: ITimePeriod[] = [
|
|
{
|
|
tenant: 'tenant-1',
|
|
period_id: 'p1',
|
|
start_date: '2026-01-01',
|
|
end_date: '2026-02-01',
|
|
},
|
|
];
|
|
|
|
const result = TimePeriodSuggester.suggestNewTimePeriod(settings, existingPeriods);
|
|
expect(result.success).toBe(true);
|
|
expect(result.data?.start_date).toBe('2026-02-01');
|
|
// Code uses half-open intervals; first period ends at end_day + 1 day.
|
|
expect(result.data?.end_date).toBe('2026-02-17');
|
|
});
|
|
|
|
test('returns an error when no applicable setting matches', () => {
|
|
const settings = [makeSettings({ frequency_unit: 'week', frequency: 1, start_day: 7, end_day: 7 })];
|
|
|
|
const existingPeriods: ITimePeriod[] = [
|
|
{
|
|
tenant: 'tenant-1',
|
|
period_id: 'p1',
|
|
start_date: '2026-01-05', // Monday
|
|
end_date: '2026-01-12', // Monday
|
|
},
|
|
];
|
|
|
|
const result = TimePeriodSuggester.suggestNewTimePeriod(settings, existingPeriods);
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('No applicable time period settings found');
|
|
});
|
|
});
|
|
|