Files
wehub-resource-sync 0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

114 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { getPortkeyHeaders, toKebabCase } from '../../src/providers/portkey';
describe('toKebabCase', () => {
it('should convert simple camelCase to kebab-case', () => {
expect(toKebabCase('camelCase')).toBe('camel-case');
expect(toKebabCase('thisIsSimple')).toBe('this-is-simple');
});
it('should handle empty string', () => {
expect(toKebabCase('')).toBe('');
});
it('should handle single word', () => {
expect(toKebabCase('word')).toBe('word');
expect(toKebabCase('WORD')).toBe('word');
});
it('should preserve existing kebab-case', () => {
expect(toKebabCase('already-kebab-case')).toBe('already-kebab-case');
});
it('should handle single letters', () => {
expect(toKebabCase('a')).toBe('a');
expect(toKebabCase('A')).toBe('a');
});
});
describe('getPortkeyHeaders', () => {
it('should return headers with correct format for portkey config keys', () => {
const config = {
portkeyApiKey: 'test-api-key',
portkeyCustomHost: 'custom.host.com',
portkeyMetadata: { key1: 'value1', key2: 'value2' },
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
'x-portkey-api-key': 'test-api-key',
'x-portkey-custom-host': 'custom.host.com',
'x-portkey-metadata': JSON.stringify({ key1: 'value1', key2: 'value2' }),
});
});
it('should ignore config keys with undefined or null values', () => {
const config = {
portkeyApiKey: 'test-api-key',
portkeyCustomHost: undefined,
portkeyMetadata: null,
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
'x-portkey-api-key': 'test-api-key',
});
});
it('should handle empty config object', () => {
const config = {};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({});
});
it('should handle non-portkey config keys without modification', () => {
const config = {
apiKey: 'test-api-key',
customHost: 'custom.host.com',
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
apiKey: 'test-api-key',
customHost: 'custom.host.com',
});
});
it('should handle mixed portkey and non-portkey config keys', () => {
const config = {
portkeyApiKey: 'test-portkey',
apiKey: 'test-regular',
portkeyCustomHost: 'custom.host.com',
regularSetting: 'value',
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
'x-portkey-api-key': 'test-portkey',
apiKey: 'test-regular',
'x-portkey-custom-host': 'custom.host.com',
regularSetting: 'value',
});
});
it('should handle boolean values', () => {
const config = {
portkeyFeatureFlag: true,
portkeyAnotherFlag: false,
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
'x-portkey-feature-flag': 'true',
'x-portkey-another-flag': 'false',
});
});
it('should handle numeric values', () => {
const config = {
portkeyTimeout: 1000,
portkeyRetries: 3,
};
const headers = getPortkeyHeaders(config);
expect(headers).toEqual({
'x-portkey-timeout': '1000',
'x-portkey-retries': '3',
});
});
});