Skip to content

Commit 5be45a2

Browse files
authored
test: add githubParamsSchema validation tests (JhaSourav07#816)
## Description Added unit tests for `githubParamsSchema` in `lib/validations.test.ts`. ### Changes Made - Added success test for valid username - Added failure test for omitted username - Added failure test for empty username - Added refresh=true boolean transform test - Added refresh=false boolean transform test Closes JhaSourav07#663 --- ## Pillar - [x] Tests - [ ] Bug Fix - [ ] Feature - [ ] Documentation - [ ] Refactor --- ## Checklist - [x] My code follows the project style guidelines - [x] I have tested my changes locally - [x] All tests are passing - [x] I have linked the related issue - [x] This PR is ready for review
2 parents b5c4b83 + fa5b177 commit 5be45a2

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)