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

Intentiq id add url params #5771

Merged
merged 5 commits into from
Sep 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});