Skip to content

Commit

Permalink
Merge branch 'id5-8732-retrieve-truelink' into 'master'
Browse files Browse the repository at this point in the history
id-8734 Provision publisher TrueLinkID

See merge request id5-sync/id5-api.js!188
  • Loading branch information
abazylewicz-id5 committed May 7, 2024
2 parents a12ea9c + 736c7bb commit 10eaf73
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/id5Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ export class Id5Instance {
/** @type {TrueLinkAdapter} */
_trueLinkAdapter

/** @type {string} */
_publisherTrueLinkId

/**
* Public API. These methods will remain mostly unchanged and represent what the partners can use on their side
*/
Expand Down Expand Up @@ -272,6 +275,14 @@ export class Id5Instance {
return Object.assign({abTestingControlGroup: !this.exposeUserId()}, exposedExt);
}

/**
* Return the publisher TrueLinkId, if partner has it enabled and integrated with TrueLink
* @return {string} publisher TrueLinkId
*/
getPublisherTrueLinkId() {
return this._isExposed === false ? undefined : this._publisherTrueLinkId;
}

/**
* Return true if the userId provided is from cache
* @return {boolean}
Expand Down Expand Up @@ -664,6 +675,7 @@ export class Id5Instance {
this._userId = userId;
this._userIdAvailablePromiseResolver(userId);
this._ext = response.ext;
this._publisherTrueLinkId = response.publisherTrueLinkId;
this._fromCache = fromCache;
this._log.info('User id updated', {hasChanged, fromCache});

Expand Down
26 changes: 26 additions & 0 deletions test/spec/id5Instance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,32 @@ describe('Id5Instance', function () {
});
});
});

it(`correctly exposes the publisherTrueLinkId`, function (done) {
// given
const publisherTrueLinkId = 'publisherTLID';
const TEST_RESPONSE = {
'universal_uid': 'whateverID',
'publisherTrueLinkId': publisherTrueLinkId
};
const config = new Config({...defaultInitBypassConsent()}, NO_OP_LOGGER);
const metrics = sinon.createStubInstance(Id5CommonMetrics);
const instanceUnderTest = new Id5Instance(config, null, null, metrics, null, NO_OP_LOGGER, multiplexingInstanceStub, null, new TrueLinkAdapter());
instanceUnderTest.bootstrap();

instanceUnderTest.onAvailable(function () {
// then
expect(instanceUnderTest.getUserId()).to.eq('whateverID');
expect(instanceUnderTest.getPublisherTrueLinkId()).to.eq(publisherTrueLinkId);
done();
});

// when
multiplexingInstanceStub.emit(ApiEvent.USER_ID_READY, {
isFromCache: false,
responseObj: TEST_RESPONSE
});
})
});

describe('cleanup', function () {
Expand Down

0 comments on commit 10eaf73

Please sign in to comment.