55 AstrologyClient ,
66 AstrologyError ,
77 DEFAULT_BASE_URL ,
8- DEFAULT_RAPIDAPI_HOST ,
98 DEFAULT_RETRY_STATUS_CODES ,
109} from '../../src' ;
1110import {
@@ -68,8 +67,7 @@ const buildAxiosError = (status: number, message: string, config?: AxiosRequestC
6867 ) ;
6968} ;
7069
71- const ORIGINAL_ENV_API_KEY = process . env . RAPIDAPI_KEY ;
72- const ORIGINAL_ENV_HOST = process . env . RAPIDAPI_HOST ;
70+ const ORIGINAL_ENV_API_KEY = process . env . ASTROLOGY_API_KEY ;
7371const ORIGINAL_DEBUG_ENV = process . env . ASTROLOGY_DEBUG ;
7472
7573describe ( 'AstrologyClient' , ( ) => {
@@ -78,14 +76,9 @@ describe('AstrologyClient', () => {
7876
7977 beforeEach ( ( ) => {
8078 if ( ORIGINAL_ENV_API_KEY === undefined ) {
81- delete process . env . RAPIDAPI_KEY ;
79+ delete process . env . ASTROLOGY_API_KEY ;
8280 } else {
83- process . env . RAPIDAPI_KEY = ORIGINAL_ENV_API_KEY ;
84- }
85- if ( ORIGINAL_ENV_HOST === undefined ) {
86- delete process . env . RAPIDAPI_HOST ;
87- } else {
88- process . env . RAPIDAPI_HOST = ORIGINAL_ENV_HOST ;
81+ process . env . ASTROLOGY_API_KEY = ORIGINAL_ENV_API_KEY ;
8982 }
9083 if ( ORIGINAL_DEBUG_ENV === undefined ) {
9184 delete process . env . ASTROLOGY_DEBUG ;
@@ -105,14 +98,9 @@ describe('AstrologyClient', () => {
10598 afterEach ( ( ) => {
10699 mock . reset ( ) ;
107100 if ( ORIGINAL_ENV_API_KEY === undefined ) {
108- delete process . env . RAPIDAPI_KEY ;
109- } else {
110- process . env . RAPIDAPI_KEY = ORIGINAL_ENV_API_KEY ;
111- }
112- if ( ORIGINAL_ENV_HOST === undefined ) {
113- delete process . env . RAPIDAPI_HOST ;
101+ delete process . env . ASTROLOGY_API_KEY ;
114102 } else {
115- process . env . RAPIDAPI_HOST = ORIGINAL_ENV_HOST ;
103+ process . env . ASTROLOGY_API_KEY = ORIGINAL_ENV_API_KEY ;
116104 }
117105 if ( ORIGINAL_DEBUG_ENV === undefined ) {
118106 delete process . env . ASTROLOGY_DEBUG ;
@@ -123,14 +111,9 @@ describe('AstrologyClient', () => {
123111
124112 afterAll ( ( ) => {
125113 if ( ORIGINAL_ENV_API_KEY === undefined ) {
126- delete process . env . RAPIDAPI_KEY ;
114+ delete process . env . ASTROLOGY_API_KEY ;
127115 } else {
128- process . env . RAPIDAPI_KEY = ORIGINAL_ENV_API_KEY ;
129- }
130- if ( ORIGINAL_ENV_HOST === undefined ) {
131- delete process . env . RAPIDAPI_HOST ;
132- } else {
133- process . env . RAPIDAPI_HOST = ORIGINAL_ENV_HOST ;
116+ process . env . ASTROLOGY_API_KEY = ORIGINAL_ENV_API_KEY ;
134117 }
135118 if ( ORIGINAL_DEBUG_ENV === undefined ) {
136119 delete process . env . ASTROLOGY_DEBUG ;
@@ -146,10 +129,9 @@ describe('AstrologyClient', () => {
146129 } ,
147130 } ) ;
148131
149- it ( 'sends RapidAPI headers and returns planetary positions' , async ( ) => {
132+ it ( 'sends Authorization Bearer header and returns planetary positions' , async ( ) => {
150133 mock . onPost ( '/api/v3/data/positions' ) . reply ( ( config ) => {
151- expect ( config . headers ?. [ 'x-rapidapi-key' ] ) . toBe ( 'test-key' ) ;
152- expect ( config . headers ?. [ 'x-rapidapi-host' ] ) . toBeDefined ( ) ;
134+ expect ( config . headers ?. [ 'Authorization' ] ) . toBe ( 'Bearer test-key' ) ;
153135 const payload = JSON . parse ( config . data ) as PlanetaryPositionsRequest ;
154136 expect ( payload . subject . birth_data . year ) . toBe ( 1990 ) ;
155137 return [ 200 , mockPlanetaryPositionsResponse ] ;
@@ -400,7 +382,7 @@ describe('AstrologyClient', () => {
400382 } ,
401383 axiosOptions : {
402384 headers : {
403- 'x-rapidapi-key' : 'pre-set' ,
385+ Authorization : 'Bearer pre-set' ,
404386 'X-Custom-Header' : 'value' ,
405387 } ,
406388 } ,
@@ -410,7 +392,7 @@ describe('AstrologyClient', () => {
410392 customMock . onPost ( '/api/v3/data/positions' ) . reply ( ( config ) => {
411393 expect ( config . baseURL ) . toBe ( 'https://custom.example.com' ) ;
412394 expect ( config . timeout ) . toBe ( 5000 ) ;
413- expect ( config . headers ?. [ 'x-rapidapi-key ' ] ) . toBe ( 'pre-set' ) ;
395+ expect ( config . headers ?. [ 'Authorization ' ] ) . toBe ( 'Bearer pre-set' ) ;
414396 expect ( config . headers ?. [ 'X-Custom-Header' ] ) . toBe ( 'value' ) ;
415397 return [ 200 , mockPlanetaryPositionsResponse ] ;
416398 } ) ;
@@ -419,34 +401,34 @@ describe('AstrologyClient', () => {
419401 } ) ;
420402
421403 it ( 'uses environment API key when config omits one' , async ( ) => {
422- const original = process . env . RAPIDAPI_KEY ;
423- process . env . RAPIDAPI_KEY = 'env-key' ;
404+ const original = process . env . ASTROLOGY_API_KEY ;
405+ process . env . ASTROLOGY_API_KEY = 'env-key' ;
424406 const envClient = new AstrologyClient ( {
425407 retry : { attempts : 0 } ,
426408 } ) ;
427409 const envMock = new MockAdapter ( envClient . httpClient ) ;
428410 envMock . onPost ( '/api/v3/data/positions' ) . reply ( ( config ) => {
429- expect ( config . headers ?. [ 'x-rapidapi-key ' ] ) . toBe ( 'env-key' ) ;
411+ expect ( config . headers ?. [ 'Authorization ' ] ) . toBe ( 'Bearer env-key' ) ;
430412 return [ 200 , mockPlanetaryPositionsResponse ] ;
431413 } ) ;
432414
433415 await envClient . data . getPositions ( createPositionsRequest ( ) ) ;
434416 envMock . reset ( ) ;
435417 if ( original === undefined ) {
436- delete process . env . RAPIDAPI_KEY ;
418+ delete process . env . ASTROLOGY_API_KEY ;
437419 } else {
438- process . env . RAPIDAPI_KEY = original ;
420+ process . env . ASTROLOGY_API_KEY = original ;
439421 }
440422 } ) ;
441423
442- it ( 'does not set API key header when no key provided' , async ( ) => {
443- delete process . env . RAPIDAPI_KEY ;
424+ it ( 'does not set Authorization header when no key provided' , async ( ) => {
425+ delete process . env . ASTROLOGY_API_KEY ;
444426 const anonymousClient = new AstrologyClient ( {
445427 retry : { attempts : 0 } ,
446428 } ) ;
447429 const anonymousMock = new MockAdapter ( anonymousClient . httpClient ) ;
448430 anonymousMock . onPost ( '/api/v3/data/positions' ) . reply ( ( config ) => {
449- expect ( config . headers ?. [ 'x-rapidapi-key ' ] ) . toBeUndefined ( ) ;
431+ expect ( config . headers ?. [ 'Authorization ' ] ) . toBeUndefined ( ) ;
450432 return [ 200 , mockPlanetaryPositionsResponse ] ;
451433 } ) ;
452434
@@ -559,26 +541,6 @@ describe('AstrologyClient', () => {
559541 }
560542 } ) ;
561543
562- it ( 'uses custom rapidApiHost when provided in config' , async ( ) => {
563- const customHostClient = new AstrologyClient ( {
564- apiKey : 'test-key' ,
565- rapidApiHost : 'custom-host.example.com' ,
566- retry : { attempts : 0 } ,
567- } ) ;
568- const customHostMock = new MockAdapter ( customHostClient . httpClient ) ;
569- customHostMock . onPost ( '/api/v3/data/positions' ) . reply ( ( config ) => {
570- expect ( config . headers ?. [ 'x-rapidapi-host' ] ) . toBe ( 'custom-host.example.com' ) ;
571- return [ 200 , mockPlanetaryPositionsResponse ] ;
572- } ) ;
573-
574- await customHostClient . data . getPositions ( createPositionsRequest ( ) ) ;
575- } ) ;
576-
577- it ( 'falls back to default RapidAPI host when not provided' , ( ) => {
578- const host = ( client as any ) . resolveRapidApiHost ( undefined ) ;
579- expect ( host ) . toBe ( DEFAULT_RAPIDAPI_HOST ) ;
580- } ) ;
581-
582544 it ( 'clamps retry values to non-negative numbers' , ( ) => {
583545 expect ( ( client as any ) . clampToNonNegative ( undefined , 5 ) ) . toBe ( 5 ) ;
584546 expect ( ( client as any ) . clampToNonNegative ( NaN , 5 ) ) . toBe ( 5 ) ;
@@ -595,17 +557,15 @@ describe('AstrologyClient', () => {
595557 it ( 'initializes missing headers inside request interceptor' , ( ) => {
596558 const interceptor = client . httpClient . interceptors . request . handlers [ 0 ] . fulfilled ! ;
597559 const result = interceptor ( { } as any ) ;
598- expect ( result . headers [ 'x-rapidapi-key' ] ) . toBe ( 'test-key' ) ;
599- expect ( result . headers [ 'x-rapidapi-host' ] ) . toBeDefined ( ) ;
560+ expect ( result . headers [ 'Authorization' ] ) . toBe ( 'Bearer test-key' ) ;
600561 } ) ;
601562
602563 it ( 'delegates to headers.set when available' , ( ) => {
603564 const set = vi . fn ( ) ;
604565 const has = vi . fn ( ) . mockReturnValue ( false ) ;
605566 const interceptor = client . httpClient . interceptors . request . handlers [ 0 ] . fulfilled ! ;
606567 interceptor ( { headers : { set, has } } as any ) ;
607- expect ( set ) . toHaveBeenCalledWith ( 'x-rapidapi-host' , expect . any ( String ) ) ;
608- expect ( set ) . toHaveBeenCalledWith ( 'x-rapidapi-key' , 'test-key' ) ;
568+ expect ( set ) . toHaveBeenCalledWith ( 'Authorization' , 'Bearer test-key' ) ;
609569 } ) ;
610570} ) ;
611571
0 commit comments