Skip to content

Commit e59a426

Browse files
fix(streak): add boundary tests for speed validation (JhaSourav07#573)
* Add boundary tests for streak speed validation * style: format streak route tests
1 parent 2d50d91 commit e59a426

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/api/streak/route.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,28 @@ describe('GET /api/streak', () => {
230230

231231
expect(body).toContain('8s');
232232
});
233+
234+
it('accepts the minimum boundary speed "2s"', async () => {
235+
const response = await GET(makeRequest({ user: 'octocat', speed: '2s' }));
236+
const body = await response.text();
237+
238+
expect(body).toContain('2s');
239+
});
240+
241+
it('accepts the maximum boundary speed "20s"', async () => {
242+
const response = await GET(makeRequest({ user: 'octocat', speed: '20s' }));
243+
const body = await response.text();
244+
245+
expect(body).toContain('20s');
246+
});
247+
248+
it('falls back to 8s when speed is a non-integer decimal like "2.0s"', async () => {
249+
const response = await GET(makeRequest({ user: 'octocat', speed: '2.0s' }));
250+
const body = await response.text();
251+
252+
expect(body).toContain('8s');
253+
expect(body).not.toContain('2.0s');
254+
});
233255
});
234256

235257
describe('scale parameter', () => {

app/api/streak/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export async function GET(request: Request) {
119119
text: isAutoTheme ? selectedTheme.text : text || selectedTheme.text,
120120
accent: isAutoTheme ? selectedTheme.accent : accent || selectedTheme.accent,
121121
radius,
122-
speed,
122+
speed: speed && /^(?:[2-9]|1\d|20)s$/.test(speed) ? speed : '8s',
123123
scale,
124124
font,
125125
autoTheme: isAutoTheme,

0 commit comments

Comments
 (0)