mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-08-30 17:56:18 +08:00
8faaa39534
- Implemented 'weighted-round-robin' as a new routing strategy in DashboardPage. - Introduced weight input fields in ApiKeyEntriesEditor, BaseProviderForm, and SponsorProviderForm. - Added validation for credential weights, including integer checks and maximum limits. - Updated localization files to include new weight-related labels and hints. - Created utility functions for credential weight validation and parsing. - Added tests for credential weight handling and visual config routing strategy.
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import {
|
|
MAX_CREDENTIAL_WEIGHT,
|
|
parseCredentialWeightText,
|
|
readCredentialWeight,
|
|
validateCredentialWeightText,
|
|
} from '../src/utils/credentialWeight';
|
|
|
|
describe('credential weight validation', () => {
|
|
test('accepts the default range and non-positive scheduling exclusions', () => {
|
|
expect(parseCredentialWeightText('')).toBeUndefined();
|
|
expect(parseCredentialWeightText('1')).toBe(1);
|
|
expect(parseCredentialWeightText('0')).toBe(0);
|
|
expect(parseCredentialWeightText('-2')).toBe(-2);
|
|
expect(parseCredentialWeightText(String(MAX_CREDENTIAL_WEIGHT))).toBe(MAX_CREDENTIAL_WEIGHT);
|
|
});
|
|
|
|
test('rejects non-integers and values above the backend maximum', () => {
|
|
expect(validateCredentialWeightText('1.5')).toBe('integer');
|
|
expect(validateCredentialWeightText('1e3')).toBe('integer');
|
|
expect(validateCredentialWeightText(String(MAX_CREDENTIAL_WEIGHT + 1))).toBe('max');
|
|
expect(parseCredentialWeightText('1.5')).toBeUndefined();
|
|
});
|
|
|
|
test('reads only valid numeric response fields', () => {
|
|
expect(readCredentialWeight(7)).toBe(7);
|
|
expect(readCredentialWeight(0)).toBe(0);
|
|
expect(readCredentialWeight(' 7 ')).toBe(7);
|
|
expect(readCredentialWeight('7.5')).toBeUndefined();
|
|
expect(readCredentialWeight(MAX_CREDENTIAL_WEIGHT + 1)).toBeUndefined();
|
|
});
|
|
});
|