Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

portkey.test.ts 3.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  1. import { getPortkeyHeaders, toKebabCase } from '../../src/providers/portkey';
  2. describe('toKebabCase', () => {
  3. it('should convert simple camelCase to kebab-case', () => {
  4. expect(toKebabCase('camelCase')).toBe('camel-case');
  5. expect(toKebabCase('thisIsSimple')).toBe('this-is-simple');
  6. });
  7. it('should handle empty string', () => {
  8. expect(toKebabCase('')).toBe('');
  9. });
  10. it('should handle single word', () => {
  11. expect(toKebabCase('word')).toBe('word');
  12. expect(toKebabCase('WORD')).toBe('word');
  13. });
  14. it('should preserve existing kebab-case', () => {
  15. expect(toKebabCase('already-kebab-case')).toBe('already-kebab-case');
  16. });
  17. it('should handle single letters', () => {
  18. expect(toKebabCase('a')).toBe('a');
  19. expect(toKebabCase('A')).toBe('a');
  20. });
  21. });
  22. describe('getPortkeyHeaders', () => {
  23. it('should return headers with correct format for portkey config keys', () => {
  24. const config = {
  25. portkeyApiKey: 'test-api-key',
  26. portkeyCustomHost: 'custom.host.com',
  27. portkeyMetadata: { key1: 'value1', key2: 'value2' },
  28. };
  29. const headers = getPortkeyHeaders(config);
  30. expect(headers).toEqual({
  31. 'x-portkey-api-key': 'test-api-key',
  32. 'x-portkey-custom-host': 'custom.host.com',
  33. 'x-portkey-metadata': JSON.stringify({ key1: 'value1', key2: 'value2' }),
  34. });
  35. });
  36. it('should ignore config keys with undefined or null values', () => {
  37. const config = {
  38. portkeyApiKey: 'test-api-key',
  39. portkeyCustomHost: undefined,
  40. portkeyMetadata: null,
  41. };
  42. const headers = getPortkeyHeaders(config);
  43. expect(headers).toEqual({
  44. 'x-portkey-api-key': 'test-api-key',
  45. });
  46. });
  47. it('should handle empty config object', () => {
  48. const config = {};
  49. const headers = getPortkeyHeaders(config);
  50. expect(headers).toEqual({});
  51. });
  52. it('should handle non-portkey config keys without modification', () => {
  53. const config = {
  54. apiKey: 'test-api-key',
  55. customHost: 'custom.host.com',
  56. };
  57. const headers = getPortkeyHeaders(config);
  58. expect(headers).toEqual({
  59. apiKey: 'test-api-key',
  60. customHost: 'custom.host.com',
  61. });
  62. });
  63. it('should handle mixed portkey and non-portkey config keys', () => {
  64. const config = {
  65. portkeyApiKey: 'test-portkey',
  66. apiKey: 'test-regular',
  67. portkeyCustomHost: 'custom.host.com',
  68. regularSetting: 'value',
  69. };
  70. const headers = getPortkeyHeaders(config);
  71. expect(headers).toEqual({
  72. 'x-portkey-api-key': 'test-portkey',
  73. apiKey: 'test-regular',
  74. 'x-portkey-custom-host': 'custom.host.com',
  75. regularSetting: 'value',
  76. });
  77. });
  78. it('should handle boolean values', () => {
  79. const config = {
  80. portkeyFeatureFlag: true,
  81. portkeyAnotherFlag: false,
  82. };
  83. const headers = getPortkeyHeaders(config);
  84. expect(headers).toEqual({
  85. 'x-portkey-feature-flag': 'true',
  86. 'x-portkey-another-flag': 'false',
  87. });
  88. });
  89. it('should handle numeric values', () => {
  90. const config = {
  91. portkeyTimeout: 1000,
  92. portkeyRetries: 3,
  93. };
  94. const headers = getPortkeyHeaders(config);
  95. expect(headers).toEqual({
  96. 'x-portkey-timeout': '1000',
  97. 'x-portkey-retries': '3',
  98. });
  99. });
  100. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...