diff --git a/packages/api-axios/src/resources/dma-cloud.js b/packages/api-axios/src/resources/dma-cloud.js index 3ce1ac14..b5fe2652 100644 --- a/packages/api-axios/src/resources/dma-cloud.js +++ b/packages/api-axios/src/resources/dma-cloud.js @@ -21,6 +21,7 @@ export default class AvLogMessagesApiV3 extends AvMicroserviceApi { flattened.X_XSRF_TOKEN = document.cookie.replace(/(?:(?:^|.*;\s*)XSRF-TOKEN\s*=\s*([^;]*).*$)|^.*$/, '$1'); const fields = Object.keys(flattened) + .filter((key) => flattened[key] != null) .map((key) => { const name = key.replaceAll(/\[\d+]/g, '[]'); const value = flattened[key]; diff --git a/packages/api-axios/src/resources/dma.js b/packages/api-axios/src/resources/dma.js index 6dc77ad4..042560ef 100644 --- a/packages/api-axios/src/resources/dma.js +++ b/packages/api-axios/src/resources/dma.js @@ -20,6 +20,7 @@ export default class AvLogMessagesApiV2 extends AvMicroserviceApi { flattened.X_XSRF_TOKEN = document.cookie.replace(/(?:(?:^|.*;\s*)XSRF-TOKEN\s*=\s*([^;]*).*$)|^.*$/, '$1'); const fields = Object.keys(flattened) + .filter((key) => flattened[key] != null) .map((key) => { const name = key.replaceAll(/\[\d+]/g, '[]'); const value = flattened[key]; diff --git a/packages/api-axios/src/resources/tests/dma-cloud.test.js b/packages/api-axios/src/resources/tests/dma-cloud.test.js index d762b5fb..f80d6b6a 100644 --- a/packages/api-axios/src/resources/tests/dma-cloud.test.js +++ b/packages/api-axios/src/resources/tests/dma-cloud.test.js @@ -15,11 +15,28 @@ describe('AvLogMessagesApiV3', () => { test('send should generate fields correctly', () => { const fields = api.send('info', { testField1: 'test1', testField2: 'test2'}); - expect(fields).toContain('level=info&entries.testField1=test1&entries.testField2=test2'); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&entries.testField2=test2&X_XSRF_TOKEN='); }); test('send should generate optional overrides fields correctly', () => { const fields = api.send('info', { testField1: 'test1', testField2: 'test2', overrides: { akaName: 'override1', transactionId: 'override2' } }); - expect(fields).toContain('level=info&entries.testField1=test1&entries.testField2=test2&overrides.akaName=override1&overrides.transactionId=override2'); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&entries.testField2=test2&overrides.akaName=override1&overrides.transactionId=override2&X_XSRF_TOKEN='); + }); + + test('send should not include undefined values in fields', () => { + const fields = api.send('info', { testField1: 'test1', testField2: undefined }); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&X_XSRF_TOKEN='); + expect(fields).not.toContain('testField2'); + }); + + test('send should not include null values in fields', () => { + const fields = api.send('info', { testField1: 'test1', testField2: null }); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&X_XSRF_TOKEN='); + expect(fields).not.toContain('testField2'); + }); + + test('send should not include overrides=undefined when overrides is not provided', () => { + const fields = api.send('info', { testField1: 'test1' }); + expect(fields).not.toContain('overrides'); }); }); diff --git a/packages/api-axios/src/resources/tests/dma.test.js b/packages/api-axios/src/resources/tests/dma.test.js index 2781e867..70c896e8 100644 --- a/packages/api-axios/src/resources/tests/dma.test.js +++ b/packages/api-axios/src/resources/tests/dma.test.js @@ -15,11 +15,28 @@ describe('AvLogMessagesApiV2', () => { test('send should generate fields correctly', () => { const fields = api.send('info', { testField1: 'test1', testField2: 'test2'}); - expect(fields).toContain('level=info&entries.testField1=test1&entries.testField2=test2'); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&entries.testField2=test2&X_XSRF_TOKEN='); }); test('send should generate optional overrides fields correctly', () => { const fields = api.send('info', { testField1: 'test1', testField2: 'test2', overrides: { akaName: 'override1', transactionId: 'override2' } }); - expect(fields).toContain('level=info&entries.testField1=test1&entries.testField2=test2&overrides.akaName=override1&overrides.transactionId=override2'); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&entries.testField2=test2&overrides.akaName=override1&overrides.transactionId=override2&X_XSRF_TOKEN='); + }); + + test('send should not include undefined values in fields', () => { + const fields = api.send('info', { testField1: 'test1', testField2: undefined }); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&X_XSRF_TOKEN='); + expect(fields).not.toContain('testField2'); + }); + + test('send should not include null values in fields', () => { + const fields = api.send('info', { testField1: 'test1', testField2: null }); + expect(fields).toStrictEqual('level=info&entries.testField1=test1&X_XSRF_TOKEN='); + expect(fields).not.toContain('testField2'); + }); + + test('send should not include overrides=undefined when overrides is not provided', () => { + const fields = api.send('info', { testField1: 'test1' }); + expect(fields).not.toContain('overrides'); }); });