Skip to content

Commit

Permalink
Merge pull request #29 from Brightspace/cpang/US127307-added-null-end…
Browse files Browse the repository at this point in the history
…point-check

US127307 Added null endpoint check for logUserEvent
  • Loading branch information
dustxd committed May 13, 2021
2 parents 87b85ec + e6c403f commit 142d69f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export class Client {
}

logUserEvent(event) {
if (!this.options.endpoint) {
return;
}

var requestObject = {
method: 'POST'
};
Expand Down
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

0 comments on commit 142d69f

Please sign in to comment.