@@ -14,31 +14,26 @@ afterAll(() => {
1414beforeEach ( ( ) => resetMock ( ) ) ;
1515
1616describe ( 'S17 — Upstream API failure handling' , ( ) => {
17- test ( 'upstream 500 returns airnode 502' , async ( ) => {
18- await setMockResponse ( '/current.json' , '__STATUS_500__' ) ;
19- // The mock returns JSON — but processResponse will fail because the shape is wrong
20- // Actually we need the mock to return a 500 status. Let me use the default mock
21- // which returns valid JSON — instead set a response that breaks encoding.
22- await setMockResponse ( '/current.json' , { error : 'internal server error' } ) ;
17+ test ( 'upstream returning wrong shape returns 502' , async ( ) => {
18+ await setMockResponse ( '/current.json' , { completely : { wrong : 'shape' } } ) ;
2319
2420 const endpointId = findEndpointId ( ctx . endpointMap , 'WeatherAPI' , 'currentTemp' ) ;
2521 const response = await post ( ctx . baseUrl , endpointId , { q : 'London' } ) ;
2622 const body = ( await response . json ( ) ) as { error : string } ;
2723
28- // processResponse fails because $.current.temp_c doesn't exist → 502
2924 expect ( response . status ) . toBe ( 502 ) ;
30- expect ( body . error ) . not . toContain ( 'temp_c' ) ; // error details not leaked
25+ expect ( body . error ) . toBe ( 'Internal processing error' ) ;
3126 } ) ;
3227
33- test ( 'upstream returning wrong shape returns 502' , async ( ) => {
34- await setMockResponse ( '/current.json' , { completely : { wrong : 'shape' } } ) ;
28+ test ( 'upstream returning non-JSON returns 502' , async ( ) => {
29+ // The mock always returns JSON, but we can set a response that the Airnode
30+ // treats as an error because the encoded data fails processing
31+ await setMockResponse ( '/current.json' , 'not json' , 200 ) ;
3532
3633 const endpointId = findEndpointId ( ctx . endpointMap , 'WeatherAPI' , 'currentTemp' ) ;
3734 const response = await post ( ctx . baseUrl , endpointId , { q : 'Berlin' } ) ;
38- const body = ( await response . json ( ) ) as { error : string } ;
3935
4036 expect ( response . status ) . toBe ( 502 ) ;
41- expect ( body . error ) . toBe ( 'Internal processing error' ) ;
4237 } ) ;
4338
4439 test ( 'error details are not leaked to the client' , async ( ) => {
@@ -49,8 +44,8 @@ describe('S17 — Upstream API failure handling', () => {
4944 const body = ( await response . json ( ) ) as { error : string } ;
5045
5146 expect ( response . status ) . toBe ( 502 ) ;
52- // Should be a generic message, not the JSONPath error or stack trace
5347 expect ( body . error ) . not . toContain ( '$.' ) ;
5448 expect ( body . error ) . not . toContain ( 'stack' ) ;
49+ expect ( body . error ) . not . toContain ( 'temp_c' ) ;
5550 } ) ;
5651} ) ;
0 commit comments