Skip to content

Commit 841af16

Browse files
authored
Add type compiler validation tests for GitHubUserValidator (JhaSourav07#3098)
## Description Closes JhaSourav07#2962 Adds type-level compiler tests for the `GitHubUserValidator` class in `services/github/validate-user.ts`. The test file uses Vitest's `expectTypeOf` to verify the public API signatures of `validateUser`, `getInstance`, and `reset` methods, including negative type assertions that ensure non-string types are not accepted by `validateUser`. ## Pillar - [x] 🛠️ Other (Test coverage for type compiler validation) ## What changed - Added `services/github/validate-user.type-compiler.test.ts` with 5 test cases: - Parameter and return type assertions for `validateUser` - Singleton instance pattern type verification for `getInstance` - Return type verification for `reset` method (`void`) - Negative type assertions ensuring only strings are accepted - Schema validation constraints return type verification ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`npx vitest run services/github/validate-user.type-compiler.test.ts`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have made sure that I have only one commit to merge in this PR.
2 parents 74f978c + a80bfb2 commit 841af16

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import { GitHubUserValidator } from './validate-user';
3+
4+
type ValidateUserReturn = ReturnType<GitHubUserValidator['validateUser']>;
5+
6+
describe('TypeScript Compiler Validation & Schema Constraints Stability', () => {
7+
it('enforces correct parameter and return types for validateUser', () => {
8+
expectTypeOf<GitHubUserValidator['validateUser']>().parameters.toEqualTypeOf<
9+
[username: string]
10+
>();
11+
expectTypeOf<ValidateUserReturn>().toEqualTypeOf<Promise<boolean>>();
12+
});
13+
14+
it('validates singleton instance pattern returns correct type', () => {
15+
expectTypeOf<
16+
ReturnType<(typeof GitHubUserValidator)['getInstance']>
17+
>().toEqualTypeOf<GitHubUserValidator>();
18+
});
19+
20+
it('validates reset method returns void', () => {
21+
expectTypeOf<GitHubUserValidator['reset']>().returns.toBeVoid();
22+
});
23+
24+
it('blocks invalid parameter types from being accepted by validateUser parameter type', () => {
25+
expectTypeOf<GitHubUserValidator['validateUser']>().parameters.toEqualTypeOf<
26+
[username: string]
27+
>();
28+
29+
// These type assertions ensure that only string is accepted:
30+
expectTypeOf<number>().not.toMatchTypeOf<string>();
31+
expectTypeOf<object>().not.toMatchTypeOf<string>();
32+
expectTypeOf<null>().not.toMatchTypeOf<string>();
33+
expectTypeOf<undefined>().not.toMatchTypeOf<string>();
34+
});
35+
36+
it('verifies schema validation constraints return strict validation reports', () => {
37+
expectTypeOf<ValidateUserReturn>().toEqualTypeOf<Promise<boolean>>();
38+
});
39+
});

0 commit comments

Comments
 (0)