@@ -58,7 +58,7 @@ function makeStubDriver() {
5858const OBJECT = 'fx_invoice' ;
5959const HOME_AMOUNT = { field : 'amount_home' , rateDate : 'invoice_date' , rateField : 'amount_rate' } ;
6060const FIELDS = {
61- code : { name : 'code ' , type : 'text' } ,
61+ ref : { name : 'ref ' , type : 'text' } ,
6262 currency_code : { name : 'currency_code' , type : 'text' , valueDomain : 'iso_4217_currency' } ,
6363 invoice_date : { name : 'invoice_date' , type : 'date' } ,
6464 amount : { name : 'amount' , type : 'currency' , currencyConfig : { currencyMode : 'record' , currencyField : 'currency_code' , homeAmount : HOME_AMOUNT } } ,
@@ -115,9 +115,9 @@ describe('import and REST writes convert through the same engine path', () => {
115115 if ( kernel ?. getState ( ) === 'running' ) await kernel . shutdown ( ) ;
116116 } ) ;
117117
118- const storedByCode = ( code : string ) => {
119- const hits = Array . from ( stub . storeFor ( OBJECT ) . values ( ) ) . filter ( ( r ) => r . code === code ) ;
120- expect ( hits . length , `one stored row for ${ code } ` ) . toBe ( 1 ) ;
118+ const storedByRef = ( ref : string ) => {
119+ const hits = Array . from ( stub . storeFor ( OBJECT ) . values ( ) ) . filter ( ( r ) => r . ref === ref ) ;
120+ expect ( hits . length , `one stored row for ${ ref } ` ) . toBe ( 1 ) ;
121121 return hits [ 0 ] ! ;
122122 } ;
123123 const protocol = ( ) => new ObjectStackProtocolImplementation ( objectql as never ) as unknown as ImportProtocolLike & {
@@ -129,7 +129,7 @@ describe('import and REST writes convert through the same engine path', () => {
129129 } ;
130130 const metaMap = new Map < string , any > ( Object . entries ( FIELDS ) ) ;
131131 const importRows = ( p : ImportProtocolLike , rows : Array < Record < string , unknown > > , over : Record < string , unknown > = { } ) => runImport ( {
132- p, objectName : OBJECT , metaMap, writeMode : 'insert' , matchFields : [ 'code ' ] , dryRun : false , runAutomations : false ,
132+ p, objectName : OBJECT , metaMap, writeMode : 'insert' , matchFields : [ 'ref ' ] , dryRun : false , runAutomations : false ,
133133 trimWhitespace : true , skipBlankMatchKey : false , context : { userId : 'usr_importer' , tenantId : 'org_a' } , rows, ...over ,
134134 } as any ) ;
135135
@@ -138,41 +138,41 @@ describe('import and REST writes convert through the same engine path', () => {
138138
139139 it ( 'the REST door (protocol createData / updateData) converts on create and on an amount change' , async ( ) => {
140140 const p = protocol ( ) ;
141- await p . createData ( { object : OBJECT , data : { code : 'rest' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : 10000 } , context : { userId : 'u1' , tenantId : 'org_a' } } ) ;
142- expect ( storedByCode ( 'rest' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
143- await p . updateData ( { object : OBJECT , id : storedByCode ( 'rest' ) . id , data : { amount : 1389 } , context : { userId : 'u1' , tenantId : 'org_a' } } ) ;
144- expect ( storedByCode ( 'rest' ) ) . toMatchObject ( { amount_home : 10000 , amount_rate : 0.1389 } ) ;
141+ await p . createData ( { object : OBJECT , data : { ref : 'rest' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : 10000 } , context : { userId : 'u1' , tenantId : 'org_a' } } ) ;
142+ expect ( storedByRef ( 'rest' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
143+ await p . updateData ( { object : OBJECT , id : storedByRef ( 'rest' ) . id , data : { amount : 1389 } , context : { userId : 'u1' , tenantId : 'org_a' } } ) ;
144+ expect ( storedByRef ( 'rest' ) ) . toMatchObject ( { amount_home : 10000 , amount_rate : 0.1389 } ) ;
145145 // The home currency was asked of the settings service, for the row's organization.
146146 expect ( settingsAsked ) . toContainEqual ( { ns : 'localization' , key : 'currency' , tenantId : 'org_a' } ) ;
147147 } ) ;
148148
149149 for ( const [ label , p ] of [ [ 'batched (insertManyData)' , protocol ] , [ 'per-row (createData)' , perRow ] ] as const ) {
150150 it ( `an import, ${ label } , converts each row and refuses a row with no rate in force` , async ( ) => {
151151 const summary = await importRows ( p ( ) , [
152- { code : 'a' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : '10000' } ,
153- { code : 'b' , currency_code : 'CNY' , amount : '12.345' } ,
154- { code : 'c' , currency_code : 'USD' , invoice_date : '2025-06-30' , amount : '1' } ,
152+ { ref : 'a' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : '10000' } ,
153+ { ref : 'b' , currency_code : 'CNY' , amount : '12.345' } ,
154+ { ref : 'c' , currency_code : 'USD' , invoice_date : '2025-06-30' , amount : '1' } ,
155155 ] ) ;
156156 expect ( summary . results . map ( ( r : any ) => r . ok ) ) . toEqual ( [ true , true , false ] ) ;
157157 expect ( JSON . stringify ( summary . results [ 2 ] ) ) . toContain ( 'ERR_EXCHANGE_RATE_MISSING' ) ;
158- expect ( storedByCode ( 'a' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
159- expect ( storedByCode ( 'b' ) ) . toMatchObject ( { amount_home : 12.35 , amount_rate : 1 } ) ;
160- expect ( Array . from ( stub . storeFor ( OBJECT ) . values ( ) ) . some ( ( r ) => r . code === 'c' ) ) . toBe ( false ) ;
158+ expect ( storedByRef ( 'a' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
159+ expect ( storedByRef ( 'b' ) ) . toMatchObject ( { amount_home : 12.35 , amount_rate : 1 } ) ;
160+ expect ( Array . from ( stub . storeFor ( OBJECT ) . values ( ) ) . some ( ( r ) => r . ref === 'c' ) ) . toBe ( false ) ;
161161 } ) ;
162162 }
163163
164164 it ( 'a historical (preserveAudit) update-mode import of the home column is recomputed over, not kept' , async ( ) => {
165- await importRows ( protocol ( ) , [ { code : 'h' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : '10000' } ] ) ;
166- const summary = await importRows ( perRow ( ) , [ { code : 'h' , amount_home : '1' , amount_rate : '9' } ] , {
165+ await importRows ( protocol ( ) , [ { ref : 'h' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : '10000' } ] ) ;
166+ const summary = await importRows ( perRow ( ) , [ { ref : 'h' , amount_home : '1' , amount_rate : '9' } ] , {
167167 writeMode : 'update' , treatAsHistorical : true ,
168168 } ) ;
169169 expect ( summary . results . map ( ( r : any ) => r . ok ) ) . toEqual ( [ true ] ) ;
170- expect ( storedByCode ( 'h' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
170+ expect ( storedByRef ( 'h' ) ) . toMatchObject ( { amount_home : 71994.24 , amount_rate : 0.1389 } ) ;
171171 } ) ;
172172
173173 it ( 'an unset localization.currency refuses the REST write ERR_HOME_CURRENCY_UNSET' , async ( ) => {
174174 home = undefined ;
175- const err = await protocol ( ) . createData ( { object : OBJECT , data : { code : 'x' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : 1 } , context : { userId : 'u1' } } )
175+ const err = await protocol ( ) . createData ( { object : OBJECT , data : { ref : 'x' , currency_code : 'USD' , invoice_date : '2026-03-15' , amount : 1 } , context : { userId : 'u1' } } )
176176 . then ( ( ) => null , ( e : { code ?: string } ) => e ) ;
177177 expect ( err ?. code ) . toBe ( 'ERR_HOME_CURRENCY_UNSET' ) ;
178178 expect ( stub . storeFor ( OBJECT ) . size ) . toBe ( 0 ) ;
@@ -181,7 +181,7 @@ describe('import and REST writes convert through the same engine path', () => {
181181
182182 it ( 'with no settings service composed, the home currency is unset — refused, never defaulted' , async ( ) => {
183183 await bootKernel ( false ) ;
184- const err = await protocol ( ) . createData ( { object : OBJECT , data : { code : 'x' , currency_code : 'CNY' , amount : 1 } , context : { userId : 'u1' } } )
184+ const err = await protocol ( ) . createData ( { object : OBJECT , data : { ref : 'x' , currency_code : 'CNY' , amount : 1 } , context : { userId : 'u1' } } )
185185 . then ( ( ) => null , ( e : { code ?: string } ) => e ) ;
186186 expect ( err ?. code ) . toBe ( 'ERR_HOME_CURRENCY_UNSET' ) ;
187187 } ) ;
0 commit comments