@@ -28,13 +28,28 @@ describe('GatewayFetchMetadata', () => {
28
28
const mockModelEntry = {
29
29
id : 'model-1' ,
30
30
name : 'Model One' ,
31
+ description : 'A test model' ,
32
+ pricing : {
33
+ input : '0.000001' ,
34
+ output : '0.000002' ,
35
+ } ,
31
36
specification : {
32
- specificationVersion : 'v2' ,
37
+ specificationVersion : 'v2' as const ,
33
38
provider : 'test-provider' ,
34
39
modelId : 'model-1' ,
35
40
} ,
36
41
} ;
37
42
43
+ const mockModelEntryWithoutPricing = {
44
+ id : 'model-2' ,
45
+ name : 'Model Two' ,
46
+ specification : {
47
+ specificationVersion : 'v2' as const ,
48
+ provider : 'test-provider' ,
49
+ modelId : 'model-2' ,
50
+ } ,
51
+ } ;
52
+
38
53
const server = createTestServer ( {
39
54
'https://api.example.com/*' : {
40
55
response : {
@@ -59,6 +74,77 @@ describe('GatewayFetchMetadata', () => {
59
74
} ) ;
60
75
} ) ;
61
76
77
+ it ( 'should handle models with pricing information' , async ( ) => {
78
+ server . urls [ 'https://api.example.com/*' ] . response = {
79
+ type : 'json-value' ,
80
+ body : {
81
+ models : [ mockModelEntry ] ,
82
+ } ,
83
+ } ;
84
+
85
+ const metadata = createBasicMetadataFetcher ( ) ;
86
+ const result = await metadata . getAvailableModels ( ) ;
87
+
88
+ expect ( result . models [ 0 ] ) . toEqual ( mockModelEntry ) ;
89
+ expect ( result . models [ 0 ] . pricing ) . toEqual ( {
90
+ input : '0.000001' ,
91
+ output : '0.000002' ,
92
+ } ) ;
93
+ } ) ;
94
+
95
+ it ( 'should handle models without pricing information' , async ( ) => {
96
+ server . urls [ 'https://api.example.com/*' ] . response = {
97
+ type : 'json-value' ,
98
+ body : {
99
+ models : [ mockModelEntryWithoutPricing ] ,
100
+ } ,
101
+ } ;
102
+
103
+ const metadata = createBasicMetadataFetcher ( ) ;
104
+ const result = await metadata . getAvailableModels ( ) ;
105
+
106
+ expect ( result . models [ 0 ] ) . toEqual ( mockModelEntryWithoutPricing ) ;
107
+ expect ( result . models [ 0 ] . pricing ) . toBeUndefined ( ) ;
108
+ } ) ;
109
+
110
+ it ( 'should handle mixed models with and without pricing' , async ( ) => {
111
+ server . urls [ 'https://api.example.com/*' ] . response = {
112
+ type : 'json-value' ,
113
+ body : {
114
+ models : [ mockModelEntry , mockModelEntryWithoutPricing ] ,
115
+ } ,
116
+ } ;
117
+
118
+ const metadata = createBasicMetadataFetcher ( ) ;
119
+ const result = await metadata . getAvailableModels ( ) ;
120
+
121
+ expect ( result . models ) . toHaveLength ( 2 ) ;
122
+ expect ( result . models [ 0 ] . pricing ) . toEqual ( {
123
+ input : '0.000001' ,
124
+ output : '0.000002' ,
125
+ } ) ;
126
+ expect ( result . models [ 1 ] . pricing ) . toBeUndefined ( ) ;
127
+ } ) ;
128
+
129
+ it ( 'should handle models with description' , async ( ) => {
130
+ const modelWithDescription = {
131
+ ...mockModelEntry ,
132
+ description : 'A powerful language model' ,
133
+ } ;
134
+
135
+ server . urls [ 'https://api.example.com/*' ] . response = {
136
+ type : 'json-value' ,
137
+ body : {
138
+ models : [ modelWithDescription ] ,
139
+ } ,
140
+ } ;
141
+
142
+ const metadata = createBasicMetadataFetcher ( ) ;
143
+ const result = await metadata . getAvailableModels ( ) ;
144
+
145
+ expect ( result . models [ 0 ] . description ) . toBe ( 'A powerful language model' ) ;
146
+ } ) ;
147
+
62
148
it ( 'should pass headers correctly' , async ( ) => {
63
149
const metadata = createBasicMetadataFetcher ( {
64
150
headers : ( ) => ( {
@@ -159,6 +245,34 @@ describe('GatewayFetchMetadata', () => {
159
245
160
246
await expect ( metadata . getAvailableModels ( ) ) . rejects . toThrow ( ) ;
161
247
} ) ;
248
+
249
+ it ( 'should reject models with invalid pricing format' , async ( ) => {
250
+ server . urls [ 'https://api.example.com/*' ] . response = {
251
+ type : 'json-value' ,
252
+ body : {
253
+ models : [
254
+ {
255
+ id : 'model-1' ,
256
+ name : 'Model One' ,
257
+ pricing : {
258
+ input : 123 , // Should be string, not number
259
+ output : '0.000002' ,
260
+ } ,
261
+ specification : {
262
+ specificationVersion : 'v2' ,
263
+ provider : 'test-provider' ,
264
+ modelId : 'model-1' ,
265
+ } ,
266
+ } ,
267
+ ] ,
268
+ } ,
269
+ } ;
270
+
271
+ const metadata = createBasicMetadataFetcher ( ) ;
272
+
273
+ await expect ( metadata . getAvailableModels ( ) ) . rejects . toThrow ( ) ;
274
+ } ) ;
275
+
162
276
it ( 'should not double-wrap existing Gateway errors' , async ( ) => {
163
277
// Create a Gateway error and verify it doesn't get wrapped
164
278
const existingError = new GatewayAuthenticationError ( {
@@ -260,8 +374,13 @@ describe('GatewayFetchMetadata', () => {
260
374
const customModelEntry = {
261
375
id : 'custom-model-1' ,
262
376
name : 'Custom Model One' ,
377
+ description : 'Custom model description' ,
378
+ pricing : {
379
+ input : '0.000005' ,
380
+ output : '0.000010' ,
381
+ } ,
263
382
specification : {
264
- specificationVersion : 'v2' ,
383
+ specificationVersion : 'v2' as const ,
265
384
provider : 'custom-provider' ,
266
385
modelId : 'custom-model-1' ,
267
386
} ,
0 commit comments