Skip to content

Commit a7ee991

Browse files
authored
test(mongodb): verify dbConnect uses the MONGODB_URI environment variable exactly as set (JhaSourav07#947)
## Description Fixes JhaSourav07#695 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — test-only change, no SVG output. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. (N/A) - [x] I have starred the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). (N/A) - [x] (Recommended) I joined the CommitPulse Discord server for faster collaboration, mentorship, and PR support.
2 parents 917f293 + 5d0f7d7 commit a7ee991

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)