Skip to content

Commit 7b52f2c

Browse files
author
tamilr0727-ux
committed
test(track-user): add uppercase username normalization test
1 parent 292db5e commit 7b52f2c

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)