- Enhanced the decodePath and isValidEncodedPath functions to handle legacy Windows format, allowing paths like "C--Users-name-project" to be correctly decoded and validated. - Updated tests to cover the new legacy format, ensuring proper functionality and validation. This commit improves compatibility with legacy path formats, enhancing the utility of the path decoder.
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
coercePageLimit,
|
|
coerceSearchMaxResults,
|
|
validateProjectId,
|
|
validateSearchQuery,
|
|
validateSessionId,
|
|
} from '../../../src/main/ipc/guards';
|
|
|
|
describe('ipc guards', () => {
|
|
it('accepts valid encoded project IDs', () => {
|
|
const result = validateProjectId('-Users-test-project');
|
|
expect(result.valid).toBe(true);
|
|
expect(result.value).toBe('-Users-test-project');
|
|
});
|
|
|
|
it('accepts valid Windows-style encoded project IDs', () => {
|
|
const result = validateProjectId('-C:-Users-test-project');
|
|
expect(result.valid).toBe(true);
|
|
expect(result.value).toBe('-C:-Users-test-project');
|
|
});
|
|
|
|
it('accepts legacy Windows-style encoded project IDs', () => {
|
|
const result = validateProjectId('C--Users-test-project');
|
|
expect(result.valid).toBe(true);
|
|
expect(result.value).toBe('C--Users-test-project');
|
|
});
|
|
|
|
it('rejects invalid project IDs', () => {
|
|
const result = validateProjectId('../escape');
|
|
expect(result.valid).toBe(false);
|
|
});
|
|
|
|
it('accepts valid session IDs', () => {
|
|
const result = validateSessionId('abc123-session_id');
|
|
expect(result.valid).toBe(true);
|
|
});
|
|
|
|
it('rejects empty search queries', () => {
|
|
const result = validateSearchQuery(' ');
|
|
expect(result.valid).toBe(false);
|
|
});
|
|
|
|
it('caps search max results', () => {
|
|
expect(coerceSearchMaxResults(9999, 50)).toBe(200);
|
|
expect(coerceSearchMaxResults(-1, 50)).toBe(50);
|
|
});
|
|
|
|
it('caps pagination limits', () => {
|
|
expect(coercePageLimit(500, 20)).toBe(200);
|
|
expect(coercePageLimit(0, 20)).toBe(20);
|
|
});
|
|
});
|