Skip to content

Commit

Permalink
OIL-295 error while loading cpc because of POI Group List beeing loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Waschnick committed Jan 18, 2019
1 parent 05e2dcb commit d369bbf
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/scripts/poi-list/oil.list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export function renderOilGroupListTemplate(renderMethod) {
export function renderOilThirdPartyListTemplate(renderMethod) {
loadVendorList()
.then(() => {
// HINT: The GroupList is needed if POI is enabled, because it contains the BLACKLIST/WHITELIST of vendors
// it will load nothing, if POI is disabled
getGroupList().then(() => {
renderMethod(oilThirdPartyListTemplate(getVendorsToDisplay()))
})
Expand Down
23 changes: 15 additions & 8 deletions src/scripts/poi-list/poi.group.list.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { fetchJsonData } from '../core/core_utils';
import { fetchJsonData, getGlobalOilObject, setGlobalOilObject } from '../core/core_utils';
import { logError } from '../core/core_log';
import { getPoiGroupName, setIabVendorWhitelist, setIabVendorBlacklist } from '../core/core_config';

let cachedGroupList;
import { getPoiGroupName, setIabVendorWhitelist, setIabVendorBlacklist, isPoiActive } from '../core/core_config';

/**
* IF POI is enabled: Gets the group list and sets IAB Vendor Whitelist/Blacklist
*
* @returns {Promise<Object>} A promise with the group list object as result, undefined if POI is disabled
*/
export function getGroupList() {
let groupName = getPoiGroupName();

let cachedGroupList = getGlobalOilObject('oilCachedGroupList')

return new Promise(function (resolve) {
if (cachedGroupList) {
if (cachedGroupList || !isPoiActive()) {
resolve(cachedGroupList);
} else {
fetchJsonData(__webpack_public_path__ + 'poi-lists/' + groupName + '.json')
.then(response => {
cachedGroupList = response.companyList;

if(response.iabVendorWhitelist && response.iabVendorWhitelist.length) {
setGlobalOilObject('oilCachedGroupList', cachedGroupList);

if (response.iabVendorWhitelist && response.iabVendorWhitelist.length) {
setIabVendorWhitelist(response.iabVendorWhitelist);
}

if(response.iabVendorBlacklist && response.iabVendorBlacklist.length) {
if (response.iabVendorBlacklist && response.iabVendorBlacklist.length) {
setIabVendorBlacklist(response.iabVendorBlacklist);
}

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/config/given.config.poi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script id="oil-configuration" type="application/configuration">
{
"config_version": 1,
"poi_activate_poi": true,
"poi_group_name": "axelSpringerSe_01",
}
</script>
15 changes: 0 additions & 15 deletions test/specs/company-list/oil.company.list.spec.js

This file was deleted.

63 changes: 63 additions & 0 deletions test/specs/poi-list/oil.company.list.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { loadFixture, readFixture } from '../../test-utils/utils_fixtures';
import { oilGroupListTemplate } from '../../../src/scripts/poi-list/oil.list';
import { resetOil } from '../../test-utils/utils_reset';
import { getGroupList } from '../../../src/scripts/poi-list/poi.group.list';
import * as CoreUtils from '../../../src/scripts/core/core_utils';
import * as CoreConfig from '../../../src/scripts/core/core_config';

require('jasmine-ajax');

describe('the company list', () => {

beforeEach(() => {
resetOil();
});

describe('template', () => {
it('should be loaded with the given elements', () => {
loadFixture('config/given.config.example.labels.html');
let result = oilGroupListTemplate(['a', 'b']);
expect(result).toEqualWithDiff(readFixture('gold-master/company-list.html'));
});
});

describe('with POI-Blacklist/Whitelist stored in GroupList', () => {

const testResponse = {
companyList: [
"Supercompany 1",
"Boring Co. 2",
"Ultra Inc.",
"Special Tech Ltd."
],
"iabVendorBlacklist": [1, 2, 3]
};

it('should be loaded with POI enabled', (done) => {
loadFixture('config/given.config.poi.html');

let fetchSpy = spyOn(CoreUtils, 'fetchJsonData').and.returnValue(new Promise((resolve) => resolve(testResponse)));
let configSpy = spyOn(CoreConfig, 'isPoiActive').and.returnValue(true);
getGroupList()
.then((result) => {
expect(result).toBe(testResponse.companyList);
})
.finally(() => {
fetchSpy.calls.reset();
configSpy.calls.reset();
done();
});
});

it('should not be loaded if POI is disabled', (done) => {
loadFixture('config/given.config.example.labels.html');
getGroupList()
.then((result) => {
expect(result).toBeUndefined();
done();
});
});
});


});

0 comments on commit d369bbf

Please sign in to comment.