Skip to content

Commit

Permalink
Merge pull request prebid#14 from nathan-pubx/PTOW-2-fix-linting-errors
Browse files Browse the repository at this point in the history
fixing bugs, modifying blob behaviour, addressing browser compatibility
  • Loading branch information
pnhegde committed May 15, 2024
2 parents 0425632 + 902d241 commit b973cd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const sendCache = new Proxy(
{},
{
get: (target, name) => {
if (!Object.hasOwn(target, name)) {
if (!target.hasOwnProperty(name)) {
target[name] = [];
}
return target[name];
Expand All @@ -50,7 +50,7 @@ export const auctionCache = new Proxy(
{},
{
get: (target, name) => {
if (!Object.hasOwn(target, name)) {
if (!target.hasOwnProperty(name)) {
target[name] = {
bids: [],
auctionDetail: {
Expand Down Expand Up @@ -107,7 +107,7 @@ const hasSendBeaconSupport = () => {
const getAdServerDataForBid = (bid) => {
const gptSlot = getGptSlotForAdUnitCode(bid);
if (gptSlot) {
return Object.fromEntires(
return Object.fromEntries(
gptSlot
.getTargetingKeys()
.filter(
Expand Down
24 changes: 13 additions & 11 deletions test/spec/modules/pubxaiAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import { EVENTS } from '../../../src/constants.js';

let events = require('src/events');

const readBlobSafariCompat = (blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result)
reader.onerror = reject
reader.readAsText(blob)
})
}

describe('pubxai analytics adapter', () => {
beforeEach(() => {
sinon.stub(events, 'getEvents').returns([]);
Expand Down Expand Up @@ -702,11 +711,7 @@ describe('pubxai analytics adapter', () => {
options: initOptions,
});
sinon.stub(navigator, 'sendBeacon').returns(true);
originalHD = document.hidden;
originalVS = document.visibilityState;
document['__defineGetter__']('hidden', function () {
return 1;
});
document['__defineGetter__']('visibilityState', function () {
return 'hidden';
});
Expand All @@ -717,9 +722,6 @@ describe('pubxai analytics adapter', () => {
navigator.sendBeacon.restore();
delete auctionCache['bc3806e4-873e-453c-8ae5-204f35e923b4'];
delete auctionCache['auction2'];
document['__defineGetter__']('hidden', function () {
return originalHD;
});
document['__defineGetter__']('visibilityState', function () {
return originalVS;
});
Expand Down Expand Up @@ -766,7 +768,7 @@ describe('pubxai analytics adapter', () => {
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
[expectedAfterBidWon, expectedAfterBid][index],
]);
}
Expand Down Expand Up @@ -811,7 +813,7 @@ describe('pubxai analytics adapter', () => {

// Step 9: check that the data sent in the request is correct
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
{
...expectedAfterBid,
bids: [],
Expand Down Expand Up @@ -934,7 +936,7 @@ describe('pubxai analytics adapter', () => {
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
auctionIdMapFn([expectedAfterBidWon, expectedAfterBid][index % 2], [
{
field: 'auctionId',
Expand Down Expand Up @@ -1050,7 +1052,7 @@ describe('pubxai analytics adapter', () => {
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([
[expectedAfterBidWon, expectedAfterBid][index],
replaceProperty([expectedAfterBidWon, expectedAfterBid][index], [
{
Expand Down

0 comments on commit b973cd5

Please sign in to comment.