@@ -1342,3 +1342,67 @@ describe('a single-object save is refused a `dynamic` roll-up over a child field
13421342 expect ( ( ) => save ( valid . engine , project ( 'ext_home' ) ) ) . not . toThrow ( ) ;
13431343 } ) ;
13441344} ) ;
1345+
1346+ // ── [ADR-0144 D2, amended] A followed parent code field the parent no longer serves ──
1347+ //
1348+ // The fixture is the package-lifecycle measurement's shape: `billing` owns
1349+ // `suite_invoice` and `suite_line`, `supplier` extends `suite_invoice` with the
1350+ // code field, and `suite_line.amount` follows `invoice.currency_code`. After the
1351+ // supplier leaves, the next child write is still refused ERR_CURRENCY_CODE_REQUIRED
1352+ // / 400, and the message says the field is not served instead of asking for a
1353+ // code to be written into a field that is not there.
1354+
1355+ describe ( 'a following amount whose parent code field is no longer served is refused, and the message says so (ADR-0144 D2, amended)' , ( ) => {
1356+ const BILLING = 'com.test.billing' ;
1357+ const SUPPLIER = 'com.test.supplier' ;
1358+ const NOT_SERVED = "and 'suite_invoice' does not serve a field 'currency_code' (" ;
1359+ const NO_CODE_TO_FOLLOW = "; the amount has no code to follow until that field is served again, or leave 'amount' empty. The row was not written." ;
1360+
1361+ async function bootSuite ( ) {
1362+ const booted = await bootEngine ( ) ;
1363+ booted . engine . registerApp ( {
1364+ id : BILLING , name : 'billing' ,
1365+ objects : [
1366+ { name : 'suite_invoice' , fields : { title : { type : 'text' } } } ,
1367+ { name : 'suite_line' , fields : { title : { type : 'text' } , invoice : { type : 'master_detail' , reference : 'suite_invoice' } , amount : { type : 'currency' , currencyConfig : FOLLOWS } } } ,
1368+ ] ,
1369+ } as any ) ;
1370+ booted . engine . registerApp ( { id : SUPPLIER , name : 'supplier' , objectExtensions : [ { extend : 'suite_invoice' , fields : { currency_code : CODE_FIELD } } ] } as any ) ;
1371+ await booted . engine . insert ( 'suite_invoice' , { id : 'inv_usd' , title : 'usd' , currency_code : 'USD' } ) ;
1372+ await booted . engine . insert ( 'suite_invoice' , { id : 'inv_blank' , title : 'blank' } ) ;
1373+ // CONTROL: while the supplier serves the field, a line under a parent holding a code is written.
1374+ await booted . engine . insert ( 'suite_line' , { title : 'before' , invoice : 'inv_usd' , amount : 100 } ) ;
1375+ return booted ;
1376+ }
1377+
1378+ it ( 'disable: the supplier disabled, a line with an amount is refused naming the field as not served and the disabled package' , async ( ) => {
1379+ const { engine, storeFor } = await bootSuite ( ) ;
1380+ engine . registry . disablePackage ( SUPPLIER ) ;
1381+ expect ( ( engine . registry . getObject ( 'suite_invoice' ) ?. fields as any ) ?. currency_code ) . toBeUndefined ( ) ;
1382+ const err = await refusalOf ( engine . insert ( 'suite_line' , { title : 'after' , invoice : 'inv_usd' , amount : 100 } ) ) ;
1383+ expect ( envelopeOf ( err ) ) . toEqual ( CODE_REQUIRED ) ;
1384+ expect ( err ?. field ) . toBe ( 'invoice.currency_code' ) ;
1385+ expect ( err ?. message ) . toContain ( `${ NOT_SERVED } the package '${ SUPPLIER } ' that contributed it is disabled)${ NO_CODE_TO_FOLLOW } ` ) ;
1386+ expect ( err ?. message ) . not . toContain ( 'has a blank' ) ;
1387+ expect ( storeFor ( 'suite_line' ) . size ) . toBe ( 1 ) ;
1388+ // Uninstalled, the registry no longer holds the contribution: the package clause is the generic one.
1389+ engine . registry . uninstallPackage ( SUPPLIER ) ;
1390+ const gone = await refusalOf ( engine . insert ( 'suite_line' , { title : 'gone' , invoice : 'inv_usd' , amount : 100 } ) ) ;
1391+ expect ( envelopeOf ( gone ) ) . toEqual ( CODE_REQUIRED ) ;
1392+ expect ( gone ?. message ) . toContain ( `${ NOT_SERVED } a package that contributed it may be disabled or uninstalled)${ NO_CODE_TO_FOLLOW } ` ) ;
1393+ } ) ;
1394+
1395+ it ( 'CONTROL: a served code field that is blank on the parent keeps the blank-code text' , async ( ) => {
1396+ const { engine } = await bootSuite ( ) ;
1397+ const err = await refusalOf ( engine . insert ( 'suite_line' , { title : 'blank' , invoice : 'inv_blank' , amount : 100 } ) ) ;
1398+ expect ( envelopeOf ( err ) ) . toEqual ( CODE_REQUIRED ) ;
1399+ expect ( err ?. message ) . toBe (
1400+ "Insert on 'suite_line' was REFUSED: 'amount' holds an amount in its parent record's currency (currencyMode: 'record', "
1401+ + "following 'invoice.currency_code' through the master_detail 'invoice'), and the 'suite_invoice' record it names "
1402+ + "has a blank 'currency_code', or it names none. The row was not written. Write the parent's ISO 4217 code (for "
1403+ + "example 'USD') into 'suite_invoice.currency_code' first, and name that parent in 'invoice', or leave 'amount' "
1404+ + 'empty. A child stores no code of its own: it follows its parent\'s. The server never fills a currency in: a '
1405+ + 'form pre-fills the organization\'s currency, and the stored code is always the one submitted.' ,
1406+ ) ;
1407+ } ) ;
1408+ } ) ;
0 commit comments