@@ -151,6 +151,116 @@ describe('webex-core', () => {
151151
152152 assert . isTrue ( homeClusterUrls . every ( ( host ) => ! host . failed ) ) ;
153153 } ) ;
154+
155+ describe ( 'when hosts have negative priorities' , ( ) => {
156+ it ( 'should return defaultUrl when all hosts have negative priorities' , ( ) => {
157+ const negativeServiceUrl = new ServiceUrl ( {
158+ defaultUrl : 'https://default.example.com/api/v1' ,
159+ hosts : [
160+ {
161+ host : 'example-host-neg1.com' ,
162+ priority : - 1 ,
163+ ttl : - 1 ,
164+ id : '1' ,
165+ homeCluster : true ,
166+ } ,
167+ {
168+ host : 'example-host-neg2.com' ,
169+ priority : - 1 ,
170+ ttl : - 1 ,
171+ id : '2' ,
172+ homeCluster : true ,
173+ } ,
174+ ] ,
175+ name : 'negative-priority-test' ,
176+ } ) ;
177+
178+ assert . equal (
179+ negativeServiceUrl . _getPriorityHostUrl ( ) ,
180+ 'https://default.example.com/api/v1'
181+ ) ;
182+ } ) ;
183+
184+ it ( 'should return defaultUrl when all hosts have zero priority' , ( ) => {
185+ const zeroServiceUrl = new ServiceUrl ( {
186+ defaultUrl : 'https://default.example.com/api/v1' ,
187+ hosts : [
188+ {
189+ host : 'example-host-zero.com' ,
190+ priority : 0 ,
191+ ttl : - 1 ,
192+ id : '1' ,
193+ homeCluster : true ,
194+ } ,
195+ ] ,
196+ name : 'zero-priority-test' ,
197+ } ) ;
198+
199+ assert . equal ( zeroServiceUrl . _getPriorityHostUrl ( ) , 'https://default.example.com/api/v1' ) ;
200+ } ) ;
201+
202+ it ( 'should ignore hosts with negative priorities and return valid host' , ( ) => {
203+ const mixedServiceUrl = new ServiceUrl ( {
204+ defaultUrl : 'https://default.example.com/api/v1' ,
205+ hosts : [
206+ {
207+ host : 'example-host-neg.com' ,
208+ priority : - 1 ,
209+ ttl : - 1 ,
210+ id : '1' ,
211+ homeCluster : true ,
212+ } ,
213+ {
214+ host : 'example-host-valid.com' ,
215+ priority : 5 ,
216+ ttl : - 1 ,
217+ id : '2' ,
218+ homeCluster : true ,
219+ } ,
220+ ] ,
221+ name : 'mixed-priority-test' ,
222+ } ) ;
223+
224+ const result = mixedServiceUrl . _getPriorityHostUrl ( ) ;
225+
226+ assert . include ( result , 'example-host-valid.com' ) ;
227+ assert . notInclude ( result , 'example-host-neg.com' ) ;
228+ } ) ;
229+
230+ it ( 'should select lowest positive priority host when mixed with negative priorities' , ( ) => {
231+ const mixedServiceUrl = new ServiceUrl ( {
232+ defaultUrl : 'https://default.example.com/api/v1' ,
233+ hosts : [
234+ {
235+ host : 'example-host-neg.com' ,
236+ priority : - 1 ,
237+ ttl : - 1 ,
238+ id : '1' ,
239+ homeCluster : true ,
240+ } ,
241+ {
242+ host : 'example-host-p5.com' ,
243+ priority : 5 ,
244+ ttl : - 1 ,
245+ id : '2' ,
246+ homeCluster : true ,
247+ } ,
248+ {
249+ host : 'example-host-p2.com' ,
250+ priority : 2 ,
251+ ttl : - 1 ,
252+ id : '3' ,
253+ homeCluster : true ,
254+ } ,
255+ ] ,
256+ name : 'mixed-priority-test' ,
257+ } ) ;
258+
259+ const result = mixedServiceUrl . _getPriorityHostUrl ( ) ;
260+
261+ assert . include ( result , 'example-host-p2.com' ) ;
262+ } ) ;
263+ } ) ;
154264 } ) ;
155265
156266 describe ( '#failHost()' , ( ) => {
0 commit comments