-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new url params from config * Add intentIqIdSystem_spec.js tests class
- Loading branch information
Showing
2 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |