|
15 | 15 |
|
16 | 16 | import { describe, it, expect, vi } from 'vitest'; |
17 | 17 | import { runImport, type ImportProtocolLike } from './import-runner'; |
18 | | -import type { ExportFieldMeta } from './import-field-meta.js'; |
| 18 | +import { buildFieldMetaMap, type ExportFieldMeta } from './import-field-meta.js'; |
19 | 19 |
|
20 | 20 | type FindArgs = Parameters<ImportProtocolLike['findData']>[0]; |
21 | 21 |
|
@@ -89,3 +89,34 @@ describe('[#22739] import reference resolution asks the target its declared expo |
89 | 89 | expect(getMetaItem).toHaveBeenCalledTimes(1); |
90 | 90 | }); |
91 | 91 | }); |
| 92 | + |
| 93 | +/** |
| 94 | + * CONTROL — which fields the import treats as references is unchanged: a field |
| 95 | + * declaring a `reference` string. A `user` field written without one is NOT |
| 96 | + * resolved (its raw cell reaches the write, as on `main`), although the spec's |
| 97 | + * arbiter gives it `sys_user`; adopting that target widens the accept set and |
| 98 | + * is not this change. A non-reference type declaring `reference` names no target. |
| 99 | + */ |
| 100 | +describe('[#22739] the reference field set stays the declared-reference set', () => { |
| 101 | + it('a user field without reference passes its cell through unresolved; one declaring it is resolved', async () => { |
| 102 | + const meta = buildFieldMetaMap({ fields: { |
| 103 | + owner: { type: 'user', label: 'Owner' }, |
| 104 | + assignee: { type: 'user', label: 'Assignee', reference: 'sys_user' }, |
| 105 | + amount: { type: 'number', label: 'Amount', reference: 'rx_target' }, |
| 106 | + } }); |
| 107 | + expect([meta.get('owner')!.reference, meta.get('assignee')!.reference, meta.get('amount')!.reference]).toEqual([undefined, 'sys_user', undefined]); |
| 108 | + |
| 109 | + const findData = vi.fn(async (args: FindArgs) => (args.object === 'sys_user' && Object.values(args.query!.where!)[0] === 'Ann' ? [{ id: 'u_ann' }] : [])); |
| 110 | + const getMetaItem = vi.fn(async ({ name }: { type: string; name: string }) => ({ type: 'object', name, item: { name } })); |
| 111 | + const createData = vi.fn(async (a: { data: Record<string, unknown> }) => ({ id: 'new', ...a.data })); |
| 112 | + const p: ImportProtocolLike = { findData, getMetaItem, createData, updateData: vi.fn() }; |
| 113 | + const summary = await runImport({ |
| 114 | + p, objectName: 'rx_source', metaMap: meta, writeMode: 'insert', matchFields: [], dryRun: false, |
| 115 | + runAutomations: false, trimWhitespace: true, createMissingOptions: false, skipBlankMatchKey: false, |
| 116 | + rows: [{ owner: 'Ann', assignee: 'Ann' }], |
| 117 | + }); |
| 118 | + expect(summary.results.map(verdict)).toEqual([{ ok: true, code: undefined, field: undefined }]); |
| 119 | + expect(createData.mock.calls[0]![0].data).toMatchObject({ owner: 'Ann', assignee: 'u_ann' }); |
| 120 | + expect(getMetaItem.mock.calls.map(([r]) => r.name)).toEqual(['sys_user']); |
| 121 | + }); |
| 122 | +}); |
0 commit comments