Skip to content

Commit fa5b177

Browse files
committed
test: add githubParamsSchema validation tests
1 parent b5c4b83 commit fa5b177

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

lib/validations.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { githubParamsSchema } from './validations';
3+
4+
describe('githubParamsSchema', () => {
5+
it('should pass when username is valid', () => {
6+
const result = githubParamsSchema.safeParse({
7+
username: 'octocat',
8+
});
9+
10+
expect(result.success).toBe(true);
11+
});
12+
13+
it('should fail when username is omitted', () => {
14+
const result = githubParamsSchema.safeParse({});
15+
16+
expect(result.success).toBe(false);
17+
if (!result.success) {
18+
expect(result.error.issues[0]?.message).toBe('Missing "username" parameter');
19+
}
20+
});
21+
22+
it('should fail when username is empty', () => {
23+
const result = githubParamsSchema.safeParse({
24+
username: '',
25+
});
26+
27+
expect(result.success).toBe(false);
28+
});
29+
30+
it('should transform refresh true string to boolean true', () => {
31+
const result = githubParamsSchema.safeParse({
32+
username: 'octocat',
33+
refresh: 'true',
34+
});
35+
36+
expect(result.success).toBe(true);
37+
if (result.success) {
38+
expect(result.data.refresh).toBe(true);
39+
}
40+
});
41+
42+
it('should transform refresh false string to boolean false', () => {
43+
const result = githubParamsSchema.safeParse({
44+
username: 'octocat',
45+
refresh: 'false',
46+
});
47+
48+
expect(result.success).toBe(true);
49+
if (result.success) {
50+
expect(result.data.refresh).toBe(false);
51+
}
52+
});
53+
});

0 commit comments

Comments
 (0)