Skip to content

Commit

Permalink
Merge pull request prebid#13 from nathan-pubx/PTOW-2-fix-linting-errors
Browse files Browse the repository at this point in the history
PTOW-2 fixing tests
  • Loading branch information
pnhegde authored May 13, 2024
2 parents 8cc7a9c + cbc15a2 commit 0425632
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions test/spec/modules/pubxaiAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import pubxaiAnalyticsAdapter, {
import { expect } from 'chai';
import adapterManager from 'src/adapterManager.js';
import * as utils from 'src/utils.js';
import { getGlobal } from '../../../src/prebidGlobal.js';
import { getGptSlotInfoForAdUnitCode } from '../../../libraries/gptUtils/gptUtils.js';
import { EVENTS } from '../../../src/constants.js';

Expand All @@ -15,6 +16,7 @@ let events = require('src/events');
describe('pubxai analytics adapter', () => {
beforeEach(() => {
sinon.stub(events, 'getEvents').returns([]);
sinon.stub()
});

afterEach(() => {
Expand All @@ -27,6 +29,9 @@ describe('pubxai analytics adapter', () => {
pubxId: '6c415fc0-8b0e-4cf5-be73-01526a4db625',
};

let originalHD;
let originalVS;

let location = utils.getWindowLocation();
let storage = window.top['sessionStorage'];

Expand Down Expand Up @@ -584,7 +589,7 @@ describe('pubxai analytics adapter', () => {
userIdTypes: [],
},
consentDetail: {
consentTypes: [],
consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}),
},
pmacDetail: JSON.parse(storage.getItem('pbx:pmac')) || {},
initOptions: {
Expand Down Expand Up @@ -677,7 +682,7 @@ describe('pubxai analytics adapter', () => {
userIdTypes: [],
},
consentDetail: {
consentTypes: [],
consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}),
},
pmacDetail: JSON.parse(storage.getItem('pbx:pmac')) || {},
initOptions: {
Expand All @@ -692,22 +697,32 @@ describe('pubxai analytics adapter', () => {
});

beforeEach(() => {
Object.defineProperty(document, 'visibilityState', {
value: 'hidden',
writable: true,
}); // prep for the document visibility state change
adapterManager.enableAnalytics({
provider: 'pubxai',
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';
});
});

afterEach(() => {
pubxaiAnalyticsAdapter.disableAnalytics();
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;
});
});

it('builds and sends auction data', async () => {
Expand Down Expand Up @@ -748,7 +763,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: 'undefined', // not configured for test case
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
Expand Down Expand Up @@ -791,7 +806,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: 'undefined', // not configured for test case
prebidVersion: getGlobal()?.version,
});

// Step 9: check that the data sent in the request is correct
Expand Down Expand Up @@ -916,7 +931,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: 'undefined', // not configured for test case
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
Expand Down Expand Up @@ -1032,7 +1047,7 @@ describe('pubxai analytics adapter', () => {
expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({
auctionTimestamp: '1616654312804',
pubxaiAnalyticsVersion: 'v2.0.0',
prebidVersion: 'undefined', // not configured for test case
prebidVersion: getGlobal()?.version,
});
expect(expectedData.type).to.equal('text/json');
expect(JSON.parse(await expectedData.text())).to.deep.equal([
Expand Down

0 comments on commit 0425632

Please sign in to comment.