@@ -95,4 +95,35 @@ describe('MSW Server Integration', () => {
9595 expect ( record . priority ) . toBe ( 'high' ) ;
9696 }
9797 } ) ;
98+
99+ // ── Stable seed-data IDs ──────────────────────────────────────────────
100+ // Seed records carry an explicit `_id`. After kernel bootstrap and
101+ // syncDriverIds(), `id` should equal the seed `_id`, NOT a random
102+ // driver-generated value. This ensures URLs with record IDs remain
103+ // valid across page refreshes.
104+
105+ it ( 'should preserve seed _id as canonical id (stable across refreshes)' , async ( ) => {
106+ const driver = getDriver ( ) ;
107+ const opportunities = await driver ! . find ( 'opportunity' , { object : 'opportunity' } ) ;
108+ expect ( opportunities . length ) . toBeGreaterThan ( 0 ) ;
109+
110+ // Seed data defines _id "101" for the first opportunity.
111+ // After syncDriverIds, id must equal _id (both "101").
112+ const targetOpportunity = opportunities . find ( ( r : any ) => r . _id === '101' ) ;
113+ expect ( targetOpportunity ) . toBeDefined ( ) ;
114+ expect ( targetOpportunity . id ) . toBe ( '101' ) ;
115+ expect ( targetOpportunity . _id ) . toBe ( '101' ) ;
116+ } ) ;
117+
118+ it ( 'should fetch a seed record by _id via HTTP' , async ( ) => {
119+ // GET /data/opportunity/101 — uses the stable seed _id.
120+ // Response may be wrapped in { success, data: { record } } (HttpDispatcher)
121+ // or returned as { record } (direct protocol).
122+ const res = await fetch ( 'http://localhost/api/v1/data/opportunity/101' ) ;
123+ expect ( res . ok ) . toBe ( true ) ;
124+ const body = await res . json ( ) ;
125+ const record = body . data ?. record ?? body . record ;
126+ expect ( record ) . toBeDefined ( ) ;
127+ expect ( record . name ) . toBe ( 'ObjectStack Enterprise License' ) ;
128+ } ) ;
98129} ) ;
0 commit comments