Skip to content

Commit dd94d7c

Browse files
committed
test(mongodb): verify User schema behaviors under connection state 2 (connecting) (Variation 3)
1 parent a4dcf09 commit dd94d7c

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

models/User.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
});

0 commit comments

Comments
 (0)