|
12 | 12 |
|
13 | 13 | import { beforeEach, describe, expect, it } from 'vitest'; |
14 | 14 | import { AutomationEngine } from '../engine.js'; |
| 15 | +import { InMemorySuspendedRunStore } from '../suspended-run-store.js'; |
| 16 | +import { installBuiltinNodes } from './index.js'; |
15 | 17 | import { registerNotifyNode } from './notify-node.js'; |
16 | 18 | import type { MessagingServiceSurface } from './notify-node.js'; |
17 | 19 | import { FlowTextTemplateError, renderTextSlot } from './template.js'; |
@@ -108,6 +110,57 @@ describe('notify — a no-argument currency hole formats in the run organization |
108 | 110 | }); |
109 | 111 | }); |
110 | 112 |
|
| 113 | +describe('a run parked before run setup seeded a currency resumes in the organization\'s default', () => { |
| 114 | + const PARKED = { |
| 115 | + name: 'deal_review', |
| 116 | + label: 'Deal Review', |
| 117 | + type: 'screen' as const, |
| 118 | + variables: [{ name: 'amount', type: 'number' as const, isInput: true }], |
| 119 | + nodes: [ |
| 120 | + { id: 'start', type: 'start' as const, label: 'Start' }, |
| 121 | + { id: 'ask', type: 'screen' as const, label: 'Ask', config: { waitForInput: true, title: 'Confirm', fields: [{ name: 'ok', label: 'OK', type: 'checkbox' }] } }, |
| 122 | + { id: 'notify', type: 'notify' as const, label: 'Notify', config: { recipients: ['user_1'], title: 'Won {{ amount | currency }}', message: 'x' } }, |
| 123 | + { id: 'end', type: 'end' as const, label: 'End' }, |
| 124 | + ], |
| 125 | + edges: [ |
| 126 | + { id: 'e1', source: 'start', target: 'ask' }, |
| 127 | + { id: 'e2', source: 'ask', target: 'notify' }, |
| 128 | + { id: 'e3', source: 'notify', target: 'end' }, |
| 129 | + ], |
| 130 | + }; |
| 131 | + |
| 132 | + function engineOver(store: InMemorySuspendedRunStore, messaging: ReturnType<typeof fakeMessaging>) { |
| 133 | + const engine = new AutomationEngine(createTestLogger(), store); |
| 134 | + installBuiltinNodes(engine, { |
| 135 | + logger: createTestLogger(), |
| 136 | + getService: (name: string) => (name === 'messaging' ? messaging.service : undefined), |
| 137 | + } as never); |
| 138 | + engine.registerFlow('deal_review', PARKED); |
| 139 | + return engine; |
| 140 | + } |
| 141 | + |
| 142 | + it('a cold resume seeds the default the persisted context lacks, and leaves the persisted context as it parked', async () => { |
| 143 | + const store = new InMemorySuspendedRunStore(); |
| 144 | + const before = engineOver(store, fakeMessaging()); |
| 145 | + // Parked by an engine with no resolver: the persisted context carries no currency. |
| 146 | + const paused = await before.execute('deal_review', { params: { amount: 1234.5 }, tenantId: 'org_cn' } as any); |
| 147 | + expect(paused.status).toBe('paused'); |
| 148 | + const parked = await store.load(paused.runId!); |
| 149 | + expect(parked?.context).not.toHaveProperty('currency'); |
| 150 | + |
| 151 | + const messaging = fakeMessaging(); |
| 152 | + const after = engineOver(store, messaging); |
| 153 | + const reads: Array<string | undefined> = []; |
| 154 | + after.setTenantCurrencyResolver((tenantId) => { reads.push(tenantId); return 'CNY'; }); |
| 155 | + const resumed = await after.resume(paused.runId!, { variables: { ok: true } } as never); |
| 156 | + |
| 157 | + expect(resumed.success, JSON.stringify(resumed)).toBe(true); |
| 158 | + expect(reads).toEqual(['org_cn']); |
| 159 | + expect(messaging.emitted[0]?.payload).toMatchObject({ title: 'Won CN¥1,234.50' }); |
| 160 | + expect(parked?.context).not.toHaveProperty('currency'); |
| 161 | + }); |
| 162 | +}); |
| 163 | + |
111 | 164 | describe('renderTextSlot — the tenant default on the engine\'s reserved channel', () => { |
112 | 165 | const vars = new Map<string, unknown>([['amount', 1234.5], ['currency', 'EUR']]); |
113 | 166 |
|
|
0 commit comments