From 147198699e281ea0f0aa1aa9f7ab0619c6d66c59 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Mon, 26 Jan 2015 12:32:24 -0500 Subject: [PATCH] Adding career matches and assessment results methods --- index.js | 33 +++++++++++++++++++++++ package.json | 2 +- test/index.js | 73 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 97 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index d9b953f..fc2d9c5 100644 --- a/index.js +++ b/index.js @@ -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; } }; diff --git a/package.json b/package.json index 8926390..6021beb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/index.js b/test/index.js index f890275..544caf3 100644 --- a/test/index.js +++ b/test/index.js @@ -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} ] }; @@ -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} ] }; @@ -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(){ @@ -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(){ @@ -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(); + }); + }); +}); + });