Skip to content

Commit fe9fd43

Browse files
authored
test(track-user): add uppercase username normalization test (JhaSourav07#949)
## Description Added a new test case for uppercase username normalization in `app/api/track-user/route.test.ts`. ### Changes made * Added test for `GITHUB` username normalization * Set `MONGODB_URI` environment variable in test setup * Verified `User.findOneAndUpdate` is called with `{ username: 'github' }` * Ensured existing track-user tests continue to pass * No functional changes Fixes JhaSourav07#693 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1102" height="683" alt="image" src="https://github.com/user-attachments/assets/5c4e6d27-a1e1-43d8-bdf9-77bc6f63c94a" /> ## 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): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents b7ceb2c + 7b52f2c commit fe9fd43

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

app/api/track-user/route.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ describe('POST /api/track-user', () => {
122122
expect(data.bypassed).toBeUndefined();
123123
});
124124

125+
it('normalizes purely uppercase usernames to lowercase', async () => {
126+
const response = await POST(makeRequest({ username: 'GITHUB' }));
127+
128+
expect(dbConnect).toHaveBeenCalled();
129+
130+
expect(User.updateOne).toHaveBeenCalledWith(
131+
{ username: 'github' },
132+
{ $setOnInsert: { username: 'github' } },
133+
{ upsert: true }
134+
);
135+
136+
expect(response.status).toBe(200);
137+
138+
const data = await response.json();
139+
140+
expect(data.success).toBe(true);
141+
});
142+
125143
it('returns 500 when database connection fails', async () => {
126144
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
127145
vi.mocked(dbConnect).mockRejectedValueOnce(new Error('DB Down'));

0 commit comments

Comments
 (0)