Skip to content

Commit

Permalink
Merge pull request prebid#8 from Teavaro/refactor-update-trustpid-acr…
Browse files Browse the repository at this point in the history
…onyms

refactor: Update trustpid acronyms logic
  • Loading branch information
jkthomas authored Mar 28, 2022
2 parents a3ea3bb + 1e10661 commit 565c5d0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 79 deletions.
35 changes: 8 additions & 27 deletions modules/trustpidSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export const storage = getStorageManager({gvlid: null, moduleName: MODULE_NAME})
* @param event
*/
function messageHandler(event) {
let msg;
try {
if (event && event.data && typeof event.data === 'string' && event.data) {
msg = JSON.parse(event.data);
if (event && event.data && typeof event.data === 'string') {
const msg = JSON.parse(event.data);
if (msg.msgType === 'MNOSELECTOR' && msg.body && msg.body.url) {
let URL = msg.body.url.split('//');
let domainURL = URL[1].split('/');
Expand All @@ -35,7 +34,7 @@ function messageHandler(event) {
}
}
} catch (e) {
logError(e);
logInfo(`${LOG_PREFIX}: Unsupported message caught. Origin: ${event.origin}, data: ${event.data}.`);
}
}

Expand All @@ -44,31 +43,13 @@ function messageHandler(event) {
* @param domain
*/
function getDomainAcronym(domain) {
let acronym = '';
const prefix = '-';
switch (domain) {
case 'tmi.mno.link':
acronym = 'ndye';
break;
case 'tmi.vodafone.de':
acronym = 'pqnx';
break;
case 'tmi.telekom.de':
acronym = 'avgw';
break;
case 'tmi.tmid.es':
acronym = 'kjws';
break;
case 'uat.mno.link':
acronym = 'xxxx';
break;
case 'es.tmiservice.orange.com':
acronym = 'aplw';
break;
default:
return 'none';
const acronym = window.FC_CONF?.TELCO_ACRONYM?.[domain];
if (!acronym) {
logInfo(`${LOG_PREFIX}: No acronym found for domain: ${domain}`);
return;
}
return mnoAcronym = prefix + acronym;
mnoAcronym = prefix + acronym;
}

// Set a listener to handle the iframe response message.
Expand Down
27 changes: 2 additions & 25 deletions modules/trustpidSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,7 @@ trustpid User Id Module.
First, make sure to add the trustpid submodule to your Prebid.js package with:

```
gulp build --modules=userId,adfBidAdapter,trustpidSystem
```

The following configuration parameters are available:

```
pbjs.setConfig({
userSync: {
userIds: [
{
name: 'trustpid',
params: {
maxDelayTime: 1000,
},
bidders: ["adf"],
storage: {
type: "html5",
name: "trustpid",
expires: 1, //days
},
}
],
}
});
gulp build --modules=userId,adfBidAdapter,ixBidAdapter,prebidServerBidAdapter,trustpidSystem
```

## Parameter Descriptions
Expand All @@ -38,7 +15,7 @@ pbjs.setConfig({
| name | Required | String | The name of the module | `"trustpid"`
| params | Required | Object | Object with configuration parameters for trustpid User Id submodule | - |
| params.maxDelayTime | Required | Integer | Max amount of time (in seconds) before looking into storage for data | 2500 |
| bidders | Required | Array of Strings | An array of bidder codes to which this user ID may be sent. Currently required and supporting AdformOpenRTB | `["adf"]` |
| bidders | Required | Array of Strings | An array of bidder codes to which this user ID may be sent. Currently required and supporting AdformOpenRTB | [`"adf"`, `"adformPBS"`, `"ix"`] |
| storage | Required | Object | Local storage configuration object | - |
| storage.type | Required | String | Type of the storage that would be used to store user ID. Must be `"html5"` to utilise HTML5 local storage. | `"html5"` |
| storage.name | Required | String | The name of the key in local storage where the user ID will be stored. | `"trustpid"` |
Expand Down
16 changes: 8 additions & 8 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ Example showing `localStorage` for user id data for some submodules
pbjs.setConfig({
userSync: {
userIds: [
{
name: 'trustpid',
{
name: "trustpid",
params: {
maxDelayTime: 2500
maxDelayTime: 2500,
},
bidders: ['adform'],
bidders: ["adf", "adformPBS", "ix"],
storage: {
type: 'html5',
name: 'trustpid',
expires: 60
}
type: "html5",
name: "trustpid",
expires: 1, // expiration days
},
}, {
name: "unifiedId",
params: {
Expand Down
61 changes: 42 additions & 19 deletions test/spec/modules/trustpidSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ describe('trustpid System', () => {
});

describe('trustpid getId()', () => {
before(() => {
window.FC_CONF = {
TELCO_ACRONYM: {
'domain.with.acronym': 'acronymValue',
}
};
});

afterEach(() => {
storage.removeDataFromLocalStorage(connectDataKey);
storage.removeDataFromLocalStorage(connectDomainKey);
});

after(() => {
window.FC_CONF = {};
})

it('it should return object with key callback', () => {
expect(trustpidSubmodule.getId()).to.have.property('callback');
});
Expand Down Expand Up @@ -58,41 +70,41 @@ describe('trustpid System', () => {

it('returns {id: {trustpid: data.trustpid}} if we have the right data stored in the localstorage ', () => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
const response = trustpidSubmodule.getId();
expect(response).to.have.property('id');
expect(response.id).to.have.property('trustpid');
expect(response.id.trustpid).to.be.equal('umidValue-xxxx');
expect(response.id.trustpid).to.be.equal('umidValue-acronymValue');
});

it('returns {trustpid: data.trustpid} if we have the right data stored in the localstorage right after the callback is called', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
const response = trustpidSubmodule.getId();
expect(response).to.have.property('callback');
expect(response.callback.toString()).contain('result(callback)');

if (typeof response.callback === 'function') {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
response.callback(function (result) {
expect(result).to.not.be.null;
expect(result).to.have.property('trustpid');
expect(result.trustpid).to.be.equal('umidValue-xxxx');
expect(result.trustpid).to.be.equal('umidValue-acronymValue');
done()
})
}
});

it('returns null if domains don\'t match', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('differentDomainValue'));
Expand All @@ -115,7 +127,7 @@ describe('trustpid System', () => {

it('returns {trustpid: data.trustpid} if we have the right data stored in the localstorage right after 500ms delay', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};

Expand All @@ -125,21 +137,21 @@ describe('trustpid System', () => {

if (typeof response.callback === 'function') {
setTimeout(() => {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
}, 500);
response.callback(function (result) {
expect(result).to.not.be.null;
expect(result).to.have.property('trustpid');
expect(result.trustpid).to.be.equal('umidValue-xxxx');
expect(result.trustpid).to.be.equal('umidValue-acronymValue');
done()
})
}
});

it('returns null if we have the data stored in the localstorage after 500ms delay and the max (waiting) delay is only 200ms ', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};

Expand All @@ -149,7 +161,7 @@ describe('trustpid System', () => {

if (typeof response.callback === 'function') {
setTimeout(() => {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
}, 500);
response.callback(function (result) {
Expand Down Expand Up @@ -191,22 +203,33 @@ describe('trustpid System', () => {
});

describe('trustpid messageHandler for acronyms', () => {
before(() => {
window.FC_CONF = {
TELCO_ACRONYM: {
'domain1': 'abcd',
'domain2': 'efgh',
'domain3': 'ijkl',
}
};
});

afterEach(() => {
storage.removeDataFromLocalStorage(connectDataKey);
storage.removeDataFromLocalStorage(connectDomainKey);
});

after(() => {
window.FC_CONF = {};
})

const domains = [
{domain: 'tmi.mno.link', acronym: 'ndye'},
{domain: 'tmi.vodafone.de', acronym: 'pqnx'},
{domain: 'tmi.telekom.de', acronym: 'avgw'},
{domain: 'tmi.tmid.es', acronym: 'kjws'},
{domain: 'uat.mno.link', acronym: 'xxxx'},
{domain: 'es.tmiservice.orange.com', acronym: 'aplw'},
{domain: 'domain1', acronym: 'abcd'},
{domain: 'domain2', acronym: 'efgh'},
{domain: 'domain3', acronym: 'ijkl'},
];

domains.forEach(({domain, acronym}) => {
it(`correctly sets trustpid value and acronym to ${acronym} for ${domain} domain`, (done) => {
it(`correctly sets trustpid value and acronym to ${acronym} for ${domain}`, (done) => {
const idGraph = {
'domain': domain,
'umid': 'umidValue',
Expand Down

0 comments on commit 565c5d0

Please sign in to comment.