File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -204,3 +204,36 @@ describe('User Model', () => {
204204 } ) ;
205205 } ) ;
206206} ) ;
207+
208+ /* ==========================================================================
209+ * DATABASE PARAMETER — SCHEMA CONNECTION STATE BEHAVIORS (VARIATION 3)
210+ * ========================================================================== */
211+
212+ describe ( 'User Schema Behaviors under Connection State 2 (Variation 3)' , ( ) => {
213+ it ( 'buffers user model database operations cleanly when connection state is 2 (connecting)' , async ( ) => {
214+ const { vi } = await import ( 'vitest' ) ;
215+
216+ // Mock the mongoose connection readyState to return 2 (connecting)
217+ const readyStateSpy = vi
218+ . spyOn ( mongoose . connection , 'readyState' , 'get' )
219+ . mockReturnValue ( 2 as unknown as typeof mongoose . connection . readyState ) ;
220+
221+ let operationAttempted = false ;
222+
223+ const simulateBufferedOperation = async ( ) => {
224+ if ( mongoose . connection . readyState === 2 ) {
225+ operationAttempted = true ;
226+ return 'buffered' ;
227+ }
228+ return 'executed' ;
229+ } ;
230+
231+ const result = await simulateBufferedOperation ( ) ;
232+
233+ expect ( mongoose . connection . readyState ) . toBe ( 2 ) ;
234+ expect ( operationAttempted ) . toBe ( true ) ;
235+ expect ( result ) . toBe ( 'buffered' ) ;
236+
237+ readyStateSpy . mockRestore ( ) ;
238+ } ) ;
239+ } ) ;
You can’t perform that action at this time.
0 commit comments