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

OIL-325: change poi list base #252

Merged
merged 3 commits into from
May 7, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/docs/03-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To instantiate oil.js with POI activated, make up a name for your company group

* Setup a server where the consent cookie is stored. For example `any.domain.com`.
* Upload `hub.html` from the `./release` folder, resulting in `https://any.domain.com/hub.html`
* Create a `MyGroupName.json` and upload it in a subfolder named `poi-lists` to your server, resulting in `https://any.domain.com/poi-lists/MyGroupName.json`. Note the file name must be the same as the value passed in poi_group_name. For an example see <<poi-list, POI-List section>>.
* Create a `MyGroupName.json` and upload it in a subfolder named `poi-lists` to your server, resulting in `https://any.domain.com/poi-lists/MyGroupName.json`. Note: The file name must be the same as the value passed in `poi_group_name`. For an example see <<poi-list, POI-List section>>. Note: Enable CORS for the `poi-lists` directory and its contained files.
* Make sure the `MyGroupName.json` is served with the right CORS-headers so that your websites are allowed to read it.
* Add the required parameters to each website configuration that should share the consent cookie:

Expand Down
1 change: 1 addition & 0 deletions http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ app.use(compression());
// Serve directory indexes folder (with icons)
app.use('/release', cors(), serveIndex('release', {'icons': true}));
app.use('/demos', cors(), serveIndex('dist/demos', {'icons': true}));
app.use('/poi-lists', cors(), serveIndex('dist/poi-lists', {'icons': true}));

// static with cache headers
app.use(serveStatic(DOCUMENT_ROOT, {maxAge: CACHE_DURATION, cacheControl: true}));
Expand Down
2 changes: 2 additions & 0 deletions src/demos/direct-integration.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"config_version": 1,
"poi_activate_poi": true,
"poi_group_name": "axelSpringerSe_01",
"poi_hub_origin": "/",
"poi_hub_path": "demos/complete-integration-mypass.html",
"timeout": -1
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/demos/poi-group-blacklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"poi_activate_poi": true,
"theme": "dark",
"poi_group_name": "withBlacklist",
"poi_hub_origin": "https://oil.axelspringer.com",
"poi_hub_path": "/demos/complete-integration-mypass.html",
"poi_hub_origin": "/",
"poi_hub_path": "demos/complete-integration-mypass.html",
"iabVendorBlacklist": [2,8],
"show_limited_vendors_only": true
}
Expand Down
4 changes: 2 additions & 2 deletions src/demos/poi-group-whitelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"advanced_settings": true,
"poi_activate_poi": true,
"poi_group_name": "withWhitelist",
"poi_hub_origin": "https://oil.axelspringer.com",
"poi_hub_path": "/demos/complete-integration-mypass.html",
"poi_hub_origin": "/",
"poi_hub_path": "demos/complete-integration-mypass.html",
"iabVendorWhitelist": [2,8],
"show_limited_vendors_only": true
}
Expand Down
12 changes: 7 additions & 5 deletions src/scripts/core/core_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function isSubscriberSetCookieActive() {
export function getHubOrigin() {
let origin = getConfigValue(OIL_CONFIG.ATTR_HUB_ORIGIN, 'https://unpkg.com');
if (origin) {
return origin.indexOf('http') !== -1 ? origin : location.protocol + origin;
return origin === '/' || origin.indexOf('http') !== -1 ? origin : location.protocol + origin;
}
return null;
}
Expand Down Expand Up @@ -203,10 +203,12 @@ export function getLanguageFromLocale(localeVariantName = 'en') {
* @returns {string, null} complete iframe orgin
*/
export function getHubLocation() {
if (getHubOrigin() && getHubPath()) {
return getHubOrigin() + getHubPath();
}
return null;
return getHubOrigin() + getHubPath();
}

export function getPoiListDirectory() {
let hubOrigin = getHubOrigin();
return hubOrigin.endsWith('/') ? hubOrigin.replace(/\/$/, '/poi-lists') : hubOrigin + '/poi-lists';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/poi-list/poi.group.list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchJsonData, getGlobalOilObject, setGlobalOilObject } from '../core/core_utils';
import { logError } from '../core/core_log';
import { getPoiGroupName, setIabVendorWhitelist, setIabVendorBlacklist, isPoiActive } from '../core/core_config';
import { getPoiGroupName, getPoiListDirectory, isPoiActive, setIabVendorBlacklist, setIabVendorWhitelist } from '../core/core_config';

/**
* IF POI is enabled: Gets the group list and sets IAB Vendor Whitelist/Blacklist
Expand All @@ -16,7 +16,7 @@ export function getGroupList() {
if (cachedGroupList || !isPoiActive()) {
resolve(cachedGroupList);
} else {
fetchJsonData(__webpack_public_path__ + 'poi-lists/' + groupName + '.json')
fetchJsonData(`${getPoiListDirectory()}/${groupName}.json`)
.then(response => {
cachedGroupList = response.companyList;
setGlobalOilObject('oilCachedGroupList', cachedGroupList);
Expand Down
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_hub_origin": "https://myServer.com",
"poi_hub_path": "/path/to/my/hub.html"
}
</script>
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_hub_origin": "/",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
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_hub_origin": "https://myServer.com/",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
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_hub_origin": "//myServer.com",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
100 changes: 74 additions & 26 deletions test/specs/core/core_config.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import {
gdprApplies,
getAdvancedSettingsPurposesDefault,
getConfigValue,
getCookieExpireInDays,
getCustomPurposes,
getDefaultToOptin,
getHubLocation,
getHubOrigin,
getHubPath,
getIabVendorBlacklist,
getIabVendorWhitelist,
getLanguageFromLocale,
getLocale,
getLocaleUrl,
getLocaleVariantName,
getLanguageFromLocale,
getPoiGroupName,
getPoiListDirectory,
getPublicPath,
setLocale,
gdprApplies,
getShowLimitedVendors,
setGdprApplies,
getShowLimitedVendors
setLocale
} from '../../../src/scripts/core/core_config';
import { loadFixture } from '../../test-utils/utils_fixtures';
import * as CoreLog from '../../../src/scripts/core/core_log';
Expand All @@ -25,7 +28,6 @@ import { OilVersion } from '../../../src/scripts/core/core_utils';

describe('core_config', () => {

const DEFAULT_FALLBACK_BACKEND_URL = 'https://oil-backend.herokuapp.com/oil/api/userViewLocales/enEN_01';
const EXPECTED_PUBLIC_PATH = '//www/';
const EXPECTED_PUBLIC_PATH_WITH_SLASH = '//www/i-forgot-the-trailing-slash/';

Expand Down Expand Up @@ -63,7 +65,7 @@ describe('core_config', () => {

});

describe('getLocaleVariantName', function() {
describe('getLocaleVariantName', function () {

it('returns default enEN_01 when locale in config empty', function () {
let result = getLocaleVariantName();
Expand All @@ -86,24 +88,23 @@ describe('core_config', () => {
expect(getLocaleVariantName()).toEqual('floo');
});

it ('returns default enEN_01 when locale is defined without locale id', function () {
it('returns default enEN_01 when locale is defined without locale id', function () {
AS_OIL = {
CONFIG: {
locale: {
}
locale: {}
}
};
expect(getLocaleVariantName()).toEqual('enEN_01');
});
});

describe('getLanguageFromLocale', function() {
describe('getLanguageFromLocale', function () {

it('retrieves substring from parameter', function() {
it('retrieves substring from parameter', function () {
expect(getLanguageFromLocale('foo_bar')).toEqual('fo');
});

it('returns "en" when parameter is null', function(){
it('returns "en" when parameter is null', function () {
expect(getLanguageFromLocale()).toEqual('en');
})

Expand Down Expand Up @@ -156,46 +157,46 @@ describe('core_config', () => {

});

describe('getPublicPath', function() {
describe('getPublicPath', function () {

it('returns publicPath from configuration', function() {
it('returns publicPath from configuration', function () {
loadFixture('config/given.config.with.publicPath.html');
expect(getPublicPath()).toEqual(EXPECTED_PUBLIC_PATH);
});

it('adds slash when missing to publicPath', function() {
it('adds slash when missing to publicPath', function () {
loadFixture('config/given.config.with.publicPath.noslash.html');
expect(getPublicPath()).toEqual(EXPECTED_PUBLIC_PATH_WITH_SLASH);
});

it('returns undefined when no publicPath in config', function() {
it('returns undefined when no publicPath in config', function () {
expect(getPublicPath()).toBeFalsy();
});

});

describe('gdprApplies', function() {
describe('gdprApplies', function () {

it('returns true when gdpr_applies_globally and gdpr_applies not in config', function() {
it('returns true when gdpr_applies_globally and gdpr_applies not in config', function () {
expect(gdprApplies()).toBeTruthy();
});

it('returns false when gdpr_applies_globally is false and setGdprApplies is not invoked with true', function() {
it('returns false when gdpr_applies_globally is false and setGdprApplies is not invoked with true', function () {
loadFixture('config/given.config.with.gdpr.not.applies.html');
expect(gdprApplies()).toBeFalsy();
});

it('returns true when set after initialisation', function() {
it('returns true when set after initialisation', function () {
loadFixture('config/given.config.with.gdpr.not.applies.html');
setGdprApplies(true);
expect(gdprApplies()).toBeTruthy();
});

});

describe('setGdprApplies', function() {
describe('setGdprApplies', function () {

it('sets gdprApplies in configuration', function() {
it('sets gdprApplies in configuration', function () {
loadFixture('config/given.config.with.gdpr.not.applies.html');
expect(gdprApplies()).toBeFalsy();
setGdprApplies(true);
Expand All @@ -206,17 +207,64 @@ describe('core_config', () => {

});

describe('getShowLimitedVendors', function() {
it('returns false by default', function() {
describe('getShowLimitedVendors', function () {

it('returns false by default', function () {
expect(getShowLimitedVendors()).toEqual(false);
});

it('returns true when show_limited_vendors_only in configuration', function() {
it('returns true when show_limited_vendors_only in configuration', function () {
loadFixture('config/given.config.with.advanced.settings.show.limited.vendors.html');
expect(getShowLimitedVendors()).toBeTruthy();
});

});

describe('getHubOrigin', () => {

it('returns complete configured hub origin', () => {
loadFixture('config/given.config.with.poiHubOrigin.and.poiHubPath.html');
expect(getHubOrigin()).toEqual('https://myServer.com');
});

it('returns complete configured hub origin if it is "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.being.slash.html');
expect(getHubOrigin()).toEqual('/');
});

it('returns configured hub origin with added protocol it missed', () => {
loadFixture('config/given.config.with.poiHubOrigin.without.protocol.html');
expect(getHubOrigin()).toEqual('http://myServer.com');
});

});

describe('getHubLocation', () => {

it('returns correct hub location depending on configured hub origin and hub path', () => {
loadFixture('config/given.config.with.poiHubOrigin.and.poiHubPath.html');
expect(getHubLocation()).toEqual('https://myServer.com/path/to/my/hub.html');
});

});

describe('getPoiListDirectory', () => {

it('returns correct poi list directory depending on configured hub origin ending with "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.ending.with.slash.html');
expect(getPoiListDirectory()).toEqual('https://myServer.com/poi-lists');
});

it('returns correct poi list directory depending on configured hub origin not ending with "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.and.poiHubPath.html');
expect(getPoiListDirectory()).toEqual('https://myServer.com/poi-lists');
});

it('returns correct poi list directory depending on configured hub origin being "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.being.slash.html');
expect(getPoiListDirectory()).toEqual('/poi-lists');
});

});

});