Skip to content

Commit

Permalink
LocalStorage availability logging (#9755)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkowalski-id5 authored Apr 4, 2023
1 parent 50c93ff commit c0eadc0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ class IdFetchFlow {
'top': referer.reachedTop ? 1 : 0,
'u': referer.stack[0] || window.location.href,
'v': '$prebid.version$',
'storage': this.submoduleConfig.storage
'storage': this.submoduleConfig.storage,
'localStorage': storage.localStorageIsEnabled() ? 1 : 0
};

// pass in optional data, but only if populated
Expand Down
45 changes: 41 additions & 4 deletions test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ describe('ID5 ID System', function () {
}
}

const HEADERS_CONTENT_TYPE_JSON = {
'Content-Type': 'application/json'
}

function getId5FetchConfig(storageName = ID5_STORAGE_NAME, storageType = 'html5') {
return {
name: ID5_MODULE_NAME,
Expand Down Expand Up @@ -148,7 +152,7 @@ describe('ID5 ID System', function () {
}

respondWithConfigAndExpectNext(configRequest, config = ID5_API_CONFIG) {
configRequest.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(config));
configRequest.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(config));
return this.expectNextRequest()
}

Expand Down Expand Up @@ -249,7 +253,7 @@ describe('ID5 ID System', function () {
});

describe('Xhr Requests from getId()', function () {
const responseHeader = {'Content-Type': 'application/json'};
const responseHeader = HEADERS_CONTENT_TYPE_JSON

beforeEach(function () {
});
Expand Down Expand Up @@ -719,6 +723,40 @@ describe('ID5 ID System', function () {
})
});

describe('Local storage', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(storage, 'localStorageIsEnabled');
});
afterEach(() => {
sandbox.restore();
});
[
[true, 1],
[false, 0]
].forEach(function ([isEnabled, expectedValue]) {
it(`should check localStorage availability and log in request. Available=${isEnabled}`, () => {
let xhrServerMock = new XhrServerMock(sinon.createFakeServer())
let config = getId5FetchConfig();
let submoduleResponse = callSubmoduleGetId(config, undefined, undefined);
storage.localStorageIsEnabled.callsFake(() => isEnabled)

return xhrServerMock.expectFetchRequest()
.then(fetchRequest => {
let requestBody = JSON.parse(fetchRequest.requestBody);
expect(requestBody.localStorage).is.eq(expectedValue);

fetchRequest.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(ID5_JSON_RESPONSE));
return submoduleResponse
})
.then(submoduleResponse => {
expect(submoduleResponse).is.deep.equal(ID5_JSON_RESPONSE);
});
})
})
});

describe('Request Bids Hook', function () {
let adUnits;
let sandbox;
Expand Down Expand Up @@ -842,8 +880,7 @@ describe('ID5 ID System', function () {
expect(requestBody.s).is.eq(ID5_STORED_SIGNATURE);
expect(requestBody.nbPage).is.eq(2);
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).is.eq(2);
const responseHeader = {'Content-Type': 'application/json'};
request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));
request.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(ID5_JSON_RESPONSE));

return new Promise(function (resolve) {
(function waitForCondition() {
Expand Down

0 comments on commit c0eadc0

Please sign in to comment.