Skip to content

Commit 5d0f7d7

Browse files
test(mongodb): verify dbConnect passes exact MONGODB_URI to mongoose.connect
1 parent 9b64cab commit 5d0f7d7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/mongodb.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,18 @@ describe('dbConnect', () => {
5858
// The promise should be cleared so it can try again
5959
expect(global.mongoose.promise).toBeNull();
6060
});
61+
62+
it('calls mongoose.connect with the exact URI set in MONGODB_URI', async () => {
63+
const specificUri = 'mongodb://specific-host:27017/mydb';
64+
process.env.MONGODB_URI = specificUri;
65+
66+
const mockMongoose = { connection: 'mock' };
67+
vi.mocked(mongoose.connect).mockResolvedValue(mockMongoose as unknown as typeof mongoose);
68+
69+
await dbConnect();
70+
71+
expect(mongoose.connect).toHaveBeenCalledWith(specificUri, {
72+
bufferCommands: false,
73+
});
74+
});
6175
});

0 commit comments

Comments
 (0)