Skip to content

Commit

Permalink
Topics fpd module : fix for intermitent failing test (prebid#11013)
Browse files Browse the repository at this point in the history
* test pr for circleci

* fix for failing topicsFpdModule tests

* formatting fix

* minor refactor

* triggered another circle ci build
  • Loading branch information
jlquaccia authored and Kevin Siow committed Mar 1, 2024
1 parent 8022117 commit dfd56a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit dfd56a5

Please sign in to comment.