Skip to content

Commit 31e8372

Browse files
committed
fix2: fixed clamping of grace pramas
1 parent b7a215b commit 31e8372

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

lib/validations.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@ describe('streakParamsSchema — grace fallback behavior', () => {
1010
expect(parse({ grace: '7' }).grace).toBe(7);
1111
});
1212

13-
it('clamps "8" to 7', () => {
14-
expect(parse({ grace: '8' }).grace).toBe(7);
13+
it('rejects "8" as out-of-range', () => {
14+
const result = streakParamsSchema.safeParse({ user: 'octocat', grace: '8' });
15+
expect(result.success).toBe(false);
1516
});
1617

17-
it('clamps "-1" to 0', () => {
18-
expect(parse({ grace: '-1' }).grace).toBe(0);
18+
it('rejects "-1" and returns correct error message', () => {
19+
const result = streakParamsSchema.safeParse({ user: 'octocat', grace: '-1' });
20+
expect(result.success).toBe(false);
21+
if (!result.success) {
22+
expect(result.error.flatten().fieldErrors.grace?.[0]).toBe(
23+
'grace must be an integer between 0 and 7'
24+
);
25+
}
1926
});
2027

21-
it('falls back or clamps a negative non-integer grace input safely', () => {
22-
const result = streakParamsSchema.safeParse({
23-
user: 'octocat',
24-
grace: '-1.5',
25-
});
26-
27-
expect(result.success).toBe(true);
28-
if (result.success) {
29-
expect(result.data.grace).toBe(0);
30-
}
28+
it('rejects a negative non-integer grace input', () => {
29+
const result = streakParamsSchema.safeParse({ user: 'octocat', grace: '-1.5' });
30+
expect(result.success).toBe(false);
3131
});
3232

33-
it('falls back to 1 for non-numeric grace value', () => {
34-
expect(parse({ grace: 'abc' }).grace).toBe(1);
33+
it('rejects non-numeric grace value', () => {
34+
const result = streakParamsSchema.safeParse({ user: 'octocat', grace: 'abc' });
35+
expect(result.success).toBe(false);
3536
});
3637

3738
it('defaults to 1 when grace is omitted', () => {

0 commit comments

Comments
 (0)