Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id5Id: Add localStorage availability to id5id fetch request #9755

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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