2222 * - re-entering sends `If-None-Match`, and a `304` keeps what is held;
2323 * - an invalidation naming a bundled item, and any metadata write through the
2424 * client, make the next bundled read ask the bundle again first;
25- * - a cache clear downloads the bundle again, with no validator;
25+ * - a bundled object carries its envelope's `sortability`, as its by-name read does;
26+ * - a cache clear, or a bundle served with no validator, downloads it again;
2627 * - a refused bundle leaves every read to its by-name route.
2728 */
2829import { describe , it , expect , vi } from 'vitest' ;
30+ import { readObjectSortability } from '@object-ui/core' ;
2931import { ObjectStackAdapter } from './index' ;
3032
3133const BASE = 'http://test.local' ;
@@ -78,19 +80,18 @@ async function drain() {
7880const contact = { name : 'b27627_contact' , label : 'Contact' , fields : { name : { type : 'text' , label : 'Name' } } } ;
7981const task = { name : 'b27627_task' , label : 'Task' , fields : { contact : { type : 'lookup' , reference : 'b27627_contact' } } } ;
8082
83+ /** The bundle's answer: bare, every member the envelope its by-name read answers. */
8184function bundle ( label = 'Contact' ) {
85+ const env = ( type : string , item : { name : string } , extra : Record < string , unknown > = { } ) => ( { type, name : item . name , item, ...extra } ) ;
8286 return {
83- success : true ,
84- data : {
85- app : { name : APP , label : 'App' } ,
86- objects : [
87- { item : { ...contact , label } , sortability : { name : { sortable : true } } } ,
88- { item : task } ,
89- ] ,
90- views : [ { name : 'b27627_contact.all' , object : 'b27627_contact' , label : 'All' } ] ,
91- pages : [ { name : 'b27627_contact_page' , label : 'Contact page' } ] ,
92- dashboards : [ { name : 'b27627_home' , label : 'Home' } ] ,
93- } ,
87+ app : env ( 'app' , { name : APP , label : 'App' } ) ,
88+ objects : [
89+ env ( 'object' , { ...contact , label } , { sortability : { fields : { name : { sortable : true } } } } ) ,
90+ env ( 'object' , task ) ,
91+ ] ,
92+ views : [ env ( 'view' , { name : 'b27627_contact.all' , object : 'b27627_contact' , label : 'All' } as { name : string } ) ] ,
93+ pages : [ env ( 'page' , { name : 'b27627_contact_page' , label : 'Contact page' } as { name : string } ) ] ,
94+ dashboards : [ env ( 'dashboard' , { name : 'b27627_home' , label : 'Home' } as { name : string } ) ] ,
9495 } ;
9596}
9697
@@ -212,7 +213,7 @@ describe('objectstack#27627 — the app metadata bundle', () => {
212213 expect ( held [ 2 ] . path ) . toBe ( BUNDLE_PATH ) ;
213214 expect ( held [ 2 ] . headers [ 'if-none-match' ] ) . toBe ( 'W/"b1"' ) ;
214215 const next = bundle ( ) ;
215- next . data . pages = [ { name : 'b27627_contact_page' , label : 'Renamed' } ] ;
216+ next . pages = [ { type : 'page' , name : 'b27627_contact_page' , item : { name : 'b27627_contact_page' , label : 'Renamed' } } ] ;
216217 held [ 2 ] . respond ( 200 , next , { ETag : 'W/"b2"' } ) ;
217218 expect ( ( await reread as any ) . item . label ) . toBe ( 'Renamed' ) ;
218219 } ) ;
@@ -233,11 +234,35 @@ describe('objectstack#27627 — the app metadata bundle', () => {
233234 expect ( ( await reread as any ) . label ) . toBe ( 'Kontakt' ) ;
234235 } ) ;
235236
237+ it ( "a bundled object carries its envelope's sortability, as its by-name read does" , async ( ) => {
238+ const { ds, held } = await heldAdapter ( ) ;
239+ const entered = ds . loadAppBundle ( APP ) ;
240+ await drain ( ) ;
241+ held [ 0 ] . respond ( 200 , bundle ( ) , { ETag : '"b1"' } ) ;
242+ await entered ;
243+ expect ( readObjectSortability ( await ds . getObjectSchema ( 'b27627_contact' ) ) ?. fields . name ?. sortable ) . toBe ( true ) ;
244+ } ) ;
245+
246+ it ( 'a bundle served with no validator (`no-store`) is downloaded again, never revalidated' , async ( ) => {
247+ const { ds, held } = await heldAdapter ( ) ;
248+ const first = ds . loadAppBundle ( APP ) ;
249+ await drain ( ) ;
250+ held [ 0 ] . respond ( 200 , bundle ( ) , { 'Cache-Control' : 'private, no-store' } ) ;
251+ await first ;
252+ const again = ds . loadAppBundle ( APP ) ;
253+ await drain ( ) ;
254+ expect ( held [ 1 ] . path ) . toBe ( BUNDLE_PATH ) ;
255+ expect ( held [ 1 ] . headers [ 'if-none-match' ] ) . toBeUndefined ( ) ;
256+ held [ 1 ] . respond ( 200 , bundle ( ) ) ;
257+ await again ;
258+ } ) ;
259+
236260 it ( 'a refused bundle leaves every read to its by-name route' , async ( ) => {
237261 const { ds, held } = await heldAdapter ( ) ;
238262 const first = ds . loadAppBundle ( APP ) ;
239263 await drain ( ) ;
240- held [ 0 ] . respond ( 404 , { success : false , error : { code : 'NOT_FOUND' , message : 'No such app' } } ) ;
264+ // An app the caller cannot read refuses the whole bundle with the app read's own answer.
265+ held [ 0 ] . respond ( 403 , { success : false , error : { code : 'PERMISSION_DENIED' , message : 'Not your app' } } ) ;
241266 await first ;
242267
243268 const read = ds . getObjectSchema ( 'b27627_contact' ) ;
0 commit comments