From e89e8289342fd3f2d3c8df10ef2be941905ec776 Mon Sep 17 00:00:00 2001 From: Candice Pang Date: Wed, 12 May 2021 09:52:56 -0700 Subject: [PATCH 1/2] US127307 Added check for null endpoint before firing request to log telemetry event --- src/client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client.js b/src/client.js index 6694db7..64c0227 100644 --- a/src/client.js +++ b/src/client.js @@ -4,6 +4,10 @@ export class Client { } logUserEvent(event) { + if (!this.options.endpoint) { + return; + } + var requestObject = { method: 'POST' }; From e6c403f416656e1b45408bde9bf9daf9b21f278f Mon Sep 17 00:00:00 2001 From: Candice Pang Date: Wed, 12 May 2021 09:53:29 -0700 Subject: [PATCH 2/2] US127307 Added test to check that no requests are fired for null endpoints --- test/index.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/index.js b/test/index.js index 0bfdbf7..2d1521a 100644 --- a/test/index.js +++ b/test/index.js @@ -68,4 +68,36 @@ describe('test suite', () => { }); }); }); + + describe('logUserEvent - with null endpoint', () => { + var fetch, client, event; + + before(() => { + client = new Client({ + endpoint: null + }); + + event = new TelemetryEvent(); + const eventBody = new EventBody(); + event.setBody(eventBody); + + fetch = sinon.stub(window.d2lfetch, 'fetch'); + var promise = Promise.resolve({ + ok: true, + json: function() { + return Promise.resolve(); + } + }); + fetch.returns(promise); + }); + + after(() => { + fetch && fetch.restore(); + }); + + it ('POSTs an event', () => { + client.logUserEvent(event); + expect(fetch.calledWith(sinon.match.has('method', 'POST'))).to.be.false; + }); + }); });