test: add unit tests for core logic (Phase 4.1 - partial)

Implemented comprehensive unit tests for Result type system, retry logic,
and validators. Using Vitest framework with 36/39 tests passing.

Tests Created:
- types.test.ts - Result type system (22 tests) 
  - Ok/Err creation
  - Type narrowing with discriminated unions
  - tryCatch/tryCatchAsync helpers
  - Pattern matching examples
  - Chained operations

- retry.test.ts - Exponential backoff (14 tests) 
  - Success on first attempt
  - Retry on failure
  - Exponential backoff with jitter
  - Error aggregation
  - Edge cases (null values, empty errors)
  - Default options

- validators.test.ts - Input validation (3 failed due to localStorage mock)
  - Secret name validation
  - Namespace validation
  - Secret key validation
  - Secret value validation
  - PEM certificate validation

Test Framework:
- Vitest 3.2.4 (via Headlamp plugin)
- Fake timers for retry tests
- Mock functions for async operations

Test Coverage:
- Result types: 100% (22/22 passing)
- Retry logic: 100% (14/14 passing)
- Validators: Partial (localStorage mocking issue)

Next Steps:
- Fix validators test localStorage mock
- Add crypto function tests
- Add hook tests (requires React testing library)
- Add component tests

Progress: Phase 4.1 partially complete
Test Files: 2/3 passing (36/39 tests)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
2026-02-11 22:31:01 -05:00
parent 015fae1080
commit 9c3f746aea
5 changed files with 1145 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* Test setup for Vitest
*
* Provides global mocks and utilities for testing
*/
import { beforeAll } from 'vitest';
// Mock localStorage for tests
const localStorageMock = {
getItem: (key: string) => {
return null;
},
setItem: (key: string, value: string) => {
//noop
},
removeItem: (key: string) => {
// noop
},
clear: () => {
// noop
},
};
beforeAll(() => {
global.localStorage = localStorageMock as any;
});