diff --git a/cli/src/lib/proxy.js b/cli/src/lib/proxy.js index 6dc9c18c7..b659f5d35 100644 --- a/cli/src/lib/proxy.js +++ b/cli/src/lib/proxy.js @@ -54,6 +54,9 @@ const transformJsonResponse = (res, { target, baseUrl }) => { transformJsonResponse(r, { target, baseUrl }) ) } + if (res === null) { + return res + } return _.transform( res, (result, value, key) => { diff --git a/cli/src/lib/proxy.test.js b/cli/src/lib/proxy.test.js index eb34ecec4..b6510f357 100644 --- a/cli/src/lib/proxy.test.js +++ b/cli/src/lib/proxy.test.js @@ -20,6 +20,28 @@ describe('transformJsonResponse', () => { 'http://localhost:8080/api/endpoint' ) }) + + it('should not convert nulls to {}', () => { + const transformedResponse = transformJsonResponse( + { + a: { + b: { + c: 'https://play.dhis2.org/dev/api/endpoint', + }, + d: null, + }, + }, + { + target: 'https://play.dhis2.org/dev', + baseUrl: 'http://localhost:8080', + } + ) + + expect(transformedResponse.a.b.c).toBe( + 'http://localhost:8080/api/endpoint' + ) + expect(transformedResponse.a.d).toBe(null) + }) }) describe('rewriteLocation', () => {