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

Topics fpd module : fix for intermitent failing test #11013

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
4 changes: 3 additions & 1 deletion modules/topicsFpdModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const MODULE_NAME = 'topicsFpd';
const DEFAULT_EXPIRATION_DAYS = 21;
const DEFAULT_FETCH_RATE_IN_DAYS = 1;
let LOAD_TOPICS_INITIALISE = false;
let iframeLoadedURL = [];

export function reset() {
LOAD_TOPICS_INITIALISE = false;
iframeLoadedURL = [];
}

const bidderIframeList = {
Expand All @@ -29,11 +31,11 @@ const bidderIframeList = {
iframeURL: 'https://topics.authorizedvault.com/topicsapi.html'
}]
}

export const coreStorage = getCoreStorageManager(MODULE_NAME);
export const topicStorageName = 'prebid:topics';
export const lastUpdated = 'lastUpdated';

const iframeLoadedURL = [];
const TAXONOMIES = {
// map from topic taxonomyVersion to IAB segment taxonomy
'1': 600,
Expand Down
23 changes: 23 additions & 0 deletions test/spec/modules/topicsFpdModule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,22 @@ describe('topics', () => {
});

describe('cross-frame messages', () => {
before(() => {
config.setConfig({
userSync: {
topics: {
maxTopicCaller: 3,
bidders: [
{
bidder: 'pubmatic',
iframeURL: 'https://ads.pubmatic.com/AdServer/js/topics/topics_frame.html'
}
],
},
}
});
});

beforeEach(() => {
// init iframe logic so that the receiveMessage origin check passes
loadTopicsForBidders({
Expand All @@ -398,6 +414,10 @@ describe('topics', () => {
});
});

after(() => {
config.resetConfig();
})

it('should store segments if receiveMessage event is triggered with segment data', () => {
receiveMessage(evt);
let segments = new Map(safeJSONParse(storage.getDataFromLocalStorage(topicStorageName)));
Expand All @@ -421,11 +441,13 @@ describe('handles fetch request for topics api headers', () => {

beforeEach(() => {
stubbedFetch = sinon.stub(window, 'fetch');
reset();
});

afterEach(() => {
stubbedFetch.restore();
storage.removeDataFromLocalStorage(topicStorageName);
config.resetConfig();
});

it('should make a fetch call when a fetchUrl is present for a selected bidder', () => {
Expand All @@ -444,6 +466,7 @@ describe('handles fetch request for topics api headers', () => {
});

stubbedFetch.returns(Promise.resolve(true));

loadTopicsForBidders({
browsingTopics: true,
featurePolicy: {
Expand Down