|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import type { WorkflowRun } from '@workflow/world'; |
| 3 | +import { formatTableValue, hasExpiredData } from './output.js'; |
| 4 | + |
| 5 | +const makeRun = (overrides: Partial<WorkflowRun> = {}): WorkflowRun => |
| 6 | + ({ |
| 7 | + runId: 'run-1', |
| 8 | + status: 'running', |
| 9 | + deploymentId: 'dep-1', |
| 10 | + workflowName: 'workflow//./src/workflows/test//myWorkflow', |
| 11 | + input: undefined, |
| 12 | + output: undefined, |
| 13 | + error: undefined, |
| 14 | + createdAt: new Date('2025-01-01'), |
| 15 | + updatedAt: new Date('2025-01-01'), |
| 16 | + completedAt: undefined, |
| 17 | + startedAt: undefined, |
| 18 | + expiredAt: undefined, |
| 19 | + specVersion: 2, |
| 20 | + executionContext: {}, |
| 21 | + ...overrides, |
| 22 | + }) as unknown as WorkflowRun; |
| 23 | + |
| 24 | +describe('hasExpiredData', () => { |
| 25 | + it('returns false when expiredAt is undefined', () => { |
| 26 | + expect(hasExpiredData(makeRun({ expiredAt: undefined }))).toBe(false); |
| 27 | + }); |
| 28 | + |
| 29 | + it('returns false when expiredAt is in the future', () => { |
| 30 | + const future = new Date(Date.now() + 24 * 60 * 60 * 1000); |
| 31 | + expect(hasExpiredData(makeRun({ expiredAt: future }))).toBe(false); |
| 32 | + }); |
| 33 | + |
| 34 | + it('returns true when expiredAt is in the past', () => { |
| 35 | + const past = new Date(Date.now() - 24 * 60 * 60 * 1000); |
| 36 | + expect(hasExpiredData(makeRun({ expiredAt: past }))).toBe(true); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('formatTableValue expired data handling', () => { |
| 41 | + it('returns input value when expiredAt is in the future', () => { |
| 42 | + const future = new Date(Date.now() + 24 * 60 * 60 * 1000); |
| 43 | + const item = { expiredAt: future.toISOString(), input: 'hello' }; |
| 44 | + const result = formatTableValue('input', 'hello', {}, undefined, item); |
| 45 | + expect(result).not.toContain('expired'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('returns expired message when expiredAt is in the past', () => { |
| 49 | + const past = new Date(Date.now() - 24 * 60 * 60 * 1000); |
| 50 | + const item = { expiredAt: past.toISOString(), output: 'hello' }; |
| 51 | + const result = formatTableValue('output', 'hello', {}, undefined, item); |
| 52 | + expect(String(result)).toContain('data expired'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('returns input value when expiredAt is not present', () => { |
| 56 | + const item = { input: 'hello' }; |
| 57 | + const result = formatTableValue('input', 'hello', {}, undefined, item); |
| 58 | + expect(String(result)).not.toContain('expired'); |
| 59 | + }); |
| 60 | +}); |
0 commit comments