Skip to content

Commit

Permalink
Intentiq id add url params (#5771)
Browse files Browse the repository at this point in the history
* Add new url params from config

* Add intentIqIdSystem_spec.js tests class
  • Loading branch information
yuvalgg authored Sep 24, 2020
1 parent 8b9b86a commit 6ea04f9
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/intentIqIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const intentIqIdSubmodule = {
}

// use protocol relative urls for http or https
const url = `https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=${configParams.partner}&pt=17&dpn=1`;
let url = `https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=${configParams.partner}&pt=17&dpn=1`;
url += configParams.pcid ? '&pcid=' + encodeURIComponent(configParams.pcid) : '';
url += configParams.pai ? '&pai=' + encodeURIComponent(configParams.pai) : '';

const resp = function (callback) {
const callbacks = {
success: response => {
Expand Down
143 changes: 143 additions & 0 deletions test/spec/modules/intentIqIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { expect } from 'chai';
import {intentIqIdSubmodule} from 'modules/intentIqIdSystem.js';
import * as utils from 'src/utils.js';
import {server} from 'test/mocks/xhr.js';

const partner = 10;
const pai = '11';
const pcid = '12';
const defaultConfigParams = {partner: partner};
const paiConfigParams = {partner: partner, pai: pai};
const pcidConfigParams = {partner: partner, pcid: pcid};
const allConfigParams = {partner: partner, pai: pai, pcid: pcid};
const responseHeader = {'Content-Type': 'application/json'}

describe('IntentIQ tests', function () {
let logErrorStub;

beforeEach(function () {
logErrorStub = sinon.stub(utils, 'logError');
});

afterEach(function () {
logErrorStub.restore();
});

it('should log an error if no configParams were passed when getId', function () {
let submodule = intentIqIdSubmodule.getId();
expect(logErrorStub.calledOnce).to.be.true;
expect(submodule).to.be.undefined;
});

it('should log an error if partner configParam was not passed when getId', function () {
let submodule = intentIqIdSubmodule.getId({});
expect(logErrorStub.calledOnce).to.be.true;
expect(submodule).to.be.undefined;
});

it('should log an error if partner configParam was not a numeric value', function () {
let submodule = intentIqIdSubmodule.getId({partner: '10'});
expect(logErrorStub.calledOnce).to.be.true;
expect(submodule).to.be.undefined;
});

it('should call the IntentIQ endpoint with only partner', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the IntentIQ endpoint with only partner, pai', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(paiConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1&pai=11');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the IntentIQ endpoint with only partner, pcid', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(pcidConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1&pcid=12');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should call the IntentIQ endpoint with partner, pcid, pai', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(allConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1&pcid=12&pai=11');
request.respond(
200,
responseHeader,
JSON.stringify({})
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should not throw Uncaught TypeError when IntentIQ endpoint returns empty response', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1');
request.respond(
204,
responseHeader,
''
);
expect(callBackSpy.calledOnce).to.be.true;
expect(request.response).to.equal('');
expect(logErrorStub.calledOnce).to.not.be.true;
});

it('should log an error and continue to callback if ajax request errors', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1');
request.respond(
503,
responseHeader,
'Unavailable'
);
expect(callBackSpy.calledOnce).to.be.true;
});

it('should log an error and continue to callback if ajax request errors', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = intentIqIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&dpi=10&pt=17&dpn=1');
request.respond(
503,
responseHeader,
'Unavailable'
);
expect(callBackSpy.calledOnce).to.be.true;
});
});

0 comments on commit 6ea04f9

Please sign in to comment.