Skip to content

Commit

Permalink
Adding career matches and assessment results methods
Browse files Browse the repository at this point in the history
  • Loading branch information
efleming committed Jan 26, 2015
1 parent 3b39df0 commit 1471986
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,39 @@ module.exports = {

getPersonalityTraits: function(assessmentId, callBack){
this.get("/assessments/" + assessmentId + "/personality_traits", String(), callBack);
},

getCareerMatches: function(assessmentId, params, callBack){
var url = "/assessments/" + assessmentId + "/matches/careers?x=1"

url = this.appendParams(url, params);

this.get(url, String(), callBack);
},

getResults: function(assessmentId, data, params, callBack){
var url = "/assessments/" + assessmentId + "?x=1"

if(data != undefined){
url += "&data=" + data.join(",");
}

url = this.appendParams(url, params);

this.get(url, String(), callBack);
},

appendParams: function(url, params){
if(params["imagePack"] != undefined){
url += "&image_pack=" + params["imagePack"];
}
if(params["numberOfMatches"] != undefined){
url += "&number_of_matches=" + params["numberOfMatches"];
}
if(params["experienceLevels"] != undefined){
url += "&experience_levels=" + params["experienceLevels"];
}
return url;
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "traitify",
"version": "2.0.1",
"version": "2.1.0",
"description": "A small library providing access to traitify's api",
"main": "index.js",
"scripts": {
Expand Down
73 changes: 63 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ describe('#Traitify', function() {

var responseData = {
"personality_types":[
{"personality_type":{
"name":"Very Cool"
},
"score":100}
{"personality_type":{
"name":"Very Cool"
},
"score":100}
]
};

Expand All @@ -57,10 +57,10 @@ describe('#Traitify', function() {

var responseData = {
"personality_traits":[
{"personality_trait":{
"name":"Cool Trait"
},
"score":100}
{"personality_trait":{
"name":"Cool Trait"
},
"score":100}
]
};

Expand All @@ -75,7 +75,7 @@ describe('#Traitify', function() {
it('Gets Assessment Slides', function(done) {
var responseData = {
"slides":[
{"caption":"Very Cool"}
{"caption":"Very Cool"}
]
};
nockApiHelper("get", "/assessments/fakeAssessmentId/slides", responseData, function(){
Expand All @@ -89,7 +89,7 @@ describe('#Traitify', function() {
it("Sets Assessment's Slide", function(done) {
var responseData = {
"slides":[
{"caption":"Very Cool"}
{"caption":"Very Cool"}
]
};
nockApiHelper("put", "/assessments/fakeAssessmentId/slides/fakeSlideId", responseData, function(){
Expand All @@ -99,4 +99,57 @@ describe('#Traitify', function() {
});
});
});

it('Gets Career Matches', function(done) {

var responseData = [
{
"career": {
"experience_level": {
"id": 3
}
},
"score": 79.5084891538157
}
];

nockApiHelper("get", "/assessments/fakeAssessmentId/matches/careers?x=1", responseData, function(){
traitify.getCareerMatches("fakeAssessmentId", {}, function(data){
data[0].score.should.equal(79.5084891538157);
data[0].career.experience_level.id.should.equal(3);
done();
});
});
});

it('Gets Assessment Results', function(done) {

var responseData = {
"id": "fakeAssessmentId",
"personality_types": [
{
"personality_type": {
"id": "55071620-bca6-4f15-b466-de8733a834a8"
},
"score": 61.49495
}
],
"personality_traits": [
{
"personality_trait": {
"name": "Leader",
},
"score": 76.2712
}
]
};

nockApiHelper("get", "/assessments/fakeAssessmentId?x=1&data=traits,types", responseData, function(){
traitify.getResults("fakeAssessmentId", ["traits","types"], {}, function(data){
data.personality_types[0].score.should.equal(61.49495);
done();
});
});
});

});

0 comments on commit 1471986

Please sign in to comment.