Skip to content

Commit 7db3472

Browse files
committed
Update Start.io User ID module to ensure callbacks and AJAX requests fire regardless of endpoint validity
1 parent 6ff92f8 commit 7db3472

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

modules/startioSystem.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getStorageManager, STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } fr
55
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
66

77
const MODULE_NAME = 'startioId';
8+
const DEFAULT_ENDPOINT = '';
89
export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME });
910

1011
function storeId(id, storageConfig = {}) {
@@ -33,16 +34,12 @@ export const startioIdSubmodule = {
3334
getId(config, consentData, storedId) {
3435
const configParams = (config && config.params) || {};
3536
const storageConfig = (config && config.storage) || {};
37+
const endpoint = configParams.endpoint || DEFAULT_ENDPOINT;
3638

3739
if (storedId) {
3840
return { id: storedId };
3941
}
4042

41-
if (!configParams.endpoint || typeof configParams.endpoint !== 'string') {
42-
logError(`${MODULE_NAME} module requires an endpoint parameter.`);
43-
return;
44-
}
45-
4643
const resp = function (callback) {
4744
const callbacks = {
4845
success: response => {
@@ -65,7 +62,7 @@ export const startioIdSubmodule = {
6562
callback();
6663
}
6764
};
68-
ajax(configParams.endpoint, callbacks, undefined, { method: 'GET' });
65+
ajax(endpoint, callbacks, undefined, { method: 'GET' });
6966
};
7067
return { callback: resp };
7168
},

test/spec/modules/startioSystem_spec.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,26 @@ describe('StartIO ID System', function () {
6464
});
6565

6666
describe('getId', function () {
67-
it('should log an error if no endpoint configured', function () {
67+
it('should return callback and fire ajax even if no endpoint configured', function () {
6868
const config = { params: {} };
69-
startioIdSubmodule.getId(config);
70-
expect(utils.logError.calledOnce).to.be.true;
71-
expect(utils.logError.args[0][0]).to.include('requires an endpoint');
69+
const result = startioIdSubmodule.getId(config);
70+
expect(result).to.have.property('callback');
71+
expect(typeof result.callback).to.equal('function');
72+
73+
const callbackSpy = sinon.spy();
74+
result.callback(callbackSpy);
75+
expect(server.requests.length).to.equal(1);
7276
});
7377

74-
it('should log an error if endpoint is not a string', function () {
78+
it('should return callback and fire ajax even if endpoint is not a string', function () {
7579
const config = { params: { endpoint: 123 } };
76-
startioIdSubmodule.getId(config);
77-
expect(utils.logError.calledOnce).to.be.true;
80+
const result = startioIdSubmodule.getId(config);
81+
expect(result).to.have.property('callback');
82+
expect(typeof result.callback).to.equal('function');
83+
84+
const callbackSpy = sinon.spy();
85+
result.callback(callbackSpy);
86+
expect(server.requests.length).to.equal(1);
7887
});
7988

8089
it('should return existing storedId immediately if provided', function () {

0 commit comments

Comments
 (0)