@@ -117,6 +117,46 @@ describe("FhirClient", () => {
117117 await expect ( FhirClientInstance . read ( req , "Patient/1" ) ) . rejects . toThrow ( "Connection refused" ) ;
118118 consoleSpy . mockRestore ( ) ;
119119 } ) ;
120+
121+ it ( "logs non-object response data directly" , async ( ) => {
122+ mockAxiosCall . mockResolvedValue ( { data : "plain-text-response" , status : 200 } ) ;
123+ const req = mockReq ( { "x-fhir-server-url" : "https://fhir.example.com" } ) ;
124+ const consoleSpy = jest . spyOn ( console , "log" ) . mockImplementation ( ) ;
125+ const result = await FhirClientInstance . read ( req , "Patient/1" ) ;
126+ expect ( result ) . toBe ( "plain-text-response" ) ;
127+ // Verify the non-object branch of the ternary was hit
128+ expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( "plain-text-response" ) ) ;
129+ consoleSpy . mockRestore ( ) ;
130+ } ) ;
131+
132+ it ( "handles config with undefined method in logging" , async ( ) => {
133+ mockAxiosCall . mockResolvedValue ( { data : { id : "1" } , status : 200 } ) ;
134+ const req = mockReq ( { "x-fhir-server-url" : "https://fhir.example.com" } ) ;
135+ const consoleSpy = jest . spyOn ( console , "log" ) . mockImplementation ( ) ;
136+ const result = await FhirClientInstance . read ( req , "Patient/1" ) ;
137+ expect ( result ) . toEqual ( { id : "1" } ) ;
138+ consoleSpy . mockRestore ( ) ;
139+ } ) ;
140+
141+ it ( "logs full axios error details with statusText and data" , async ( ) => {
142+ const axiosError = new Error ( "Bad Request" ) ;
143+ ( axiosError as any ) . response = {
144+ status : 400 ,
145+ statusText : "Bad Request" ,
146+ data : { issue : [ { diagnostics : "Invalid resource" } ] } ,
147+ } ;
148+ mockAxiosCall . mockRejectedValue ( axiosError ) ;
149+ mockIsAxiosError . mockReturnValue ( true ) ;
150+
151+ const req = mockReq ( { "x-fhir-server-url" : "https://fhir.example.com" } ) ;
152+ const consoleSpy = jest . spyOn ( console , "error" ) . mockImplementation ( ) ;
153+ await expect ( FhirClientInstance . read ( req , "Patient/1" ) ) . rejects . toThrow ( "Bad Request" ) ;
154+ // Verify both error log lines were called with full details
155+ expect ( consoleSpy ) . toHaveBeenCalledWith (
156+ expect . stringContaining ( "400 Bad Request" ) ,
157+ ) ;
158+ consoleSpy . mockRestore ( ) ;
159+ } ) ;
120160 } ) ;
121161
122162 describe ( "search" , ( ) => {
0 commit comments