Skip to content

Commit 01ecf61

Browse files
committed
Test case: userInfo as query params
1 parent ac7980e commit 01ecf61

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

mock/userInfo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"userType": "repeat",
3+
"uid": "uid-1467380754247-61161"
4+
}

test/search/userinfo.spec.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
describe('UserInfo as params', function () {
2+
3+
before(function(done){
4+
this.searchTest = fixture.load('mock/searchTestResponse.json');
5+
this.userInfo = fixture.load('mock/userInfo.json');
6+
7+
//setup document to hold search results
8+
document.body.innerHTML = __html__['index.html'];
9+
10+
//initialize search
11+
this.searchobj = new window.Unbxd.setSearch(window.config);
12+
13+
//stub search ajax call with mock response
14+
this.stub = sinon.stub(jQuery, 'ajax').yieldsTo('success',this.searchTest);
15+
//spy OnIntialResultLoad
16+
this.spyOnIntialResultLoad = sinon.spy(this.searchobj.options,
17+
'onIntialResultLoad');
18+
19+
//stub getUserId
20+
this.stubGetUserId = sinon.stub(this.searchobj,
21+
'getUserId');
22+
this.stubGetUserId.returns(this.userInfo.uid);
23+
//stub getUserType
24+
this.stubGetUserType = sinon.stub(this.searchobj,
25+
'getUserType');
26+
this.stubGetUserType.returns(this.userInfo.userType);
27+
28+
this.searchobj.callResults(this.searchobj.paintResultSet);
29+
done();
30+
});
31+
32+
after(function(){
33+
this.stub.restore();
34+
fixture.cleanup();
35+
});
36+
37+
it('Should pass user-info as query params', function(){
38+
var userInfoSent = {
39+
'uid': this.userInfo.uid,
40+
'user-type': this.userInfo.userType,
41+
'unbxd-url': document.URL,
42+
'unbxd-referrer': document.referrer,
43+
'api-key': this.searchobj.options.APIKey
44+
},
45+
userInfoInUrl = {},
46+
searchApi = jQuery.ajax.getCall(0).args[0].url,
47+
params;
48+
if(searchApi.indexOf('search.unbxdapi.com')){
49+
params = searchApi.split('?').length > 0 ? searchApi.split('?')[1] : '';
50+
params.split('&').forEach(function(param){
51+
var queryName = param.split('=')[0],
52+
queryValue = decodeURIComponent(param.split('=')[1]);
53+
54+
if(queryName in userInfoSent){
55+
userInfoInUrl[queryName] = queryValue;
56+
}
57+
});
58+
}
59+
expect(userInfoSent).to.deep.equal(userInfoInUrl);
60+
});
61+
62+
});

0 commit comments

Comments
 (0)