Skip to content

Commit 93ad397

Browse files
committed
Merge pull request #15 from BlockScore/4.0.1
4.0.1
2 parents d897d58 + c33a587 commit 93ad397

File tree

3 files changed

+94
-50
lines changed

3 files changed

+94
-50
lines changed

lib/main.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
var https = require('https');
44
var fs = require('fs');
55

6+
// http://underscorejs.org/docs/underscore.html#section-118
7+
function isObject(obj) {
8+
var type = typeof obj;
9+
return type === 'function' || type === 'object' && !!obj;
10+
};
11+
612
function setup_response_handler(req, callback) {
713
if (typeof callback !== "function") {
814
//console.log("missing callback");
@@ -120,10 +126,14 @@ module.exports = function(api_key) {
120126
},
121127
question_sets: {
122128
create: function(person_id, cb) {
123-
if (!(person_id && typeof person_id === 'string')) {
129+
var data;
130+
if (person_id && typeof person_id === 'string') {
131+
data = { person_id: person_id };
132+
} else if(person_id && isObject(person_id) && 'person_id' in person_id){
133+
data = person_id;
134+
} else {
124135
return cb(new Error("person_id required"));
125136
}
126-
var data = { person_id: person_id };
127137
post("/question_sets", data, cb);
128138
},
129139
score: function(data, cb) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"watchlist scanning",
1717
"watchlists"
1818
],
19-
"version": "4.0.0",
19+
"version": "4.0.1",
2020
"homepage": "https://github.com/blockscore/blockscore-node",
2121
"repository": {
2222
"type": "git",

test/people.js

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -48,61 +48,95 @@ vows.describe("People API").addBatch({
4848
},
4949
},
5050
'create question set': {
51-
topic: function(create_err, person) {
52-
blockscore.question_sets.create(person.id, this.callback);
53-
},
54-
'got newly created question set': function(err, response) {
55-
assert.ifError(err);
56-
assert.ok(response.person_id);
57-
assert.ok(response.id);
58-
assert.ok(Array.isArray(response.questions));
59-
assert.ok(Array.isArray(response.questions[0].answers));
51+
topic: function(create_err, person){
52+
// pass our person on to our different question set topics
53+
this.callback(create_err, person);
6054
},
61-
'retrieve question set': {
62-
topic: function(err, create_response) {
63-
var self = this;
64-
blockscore.question_sets.retrieve(create_response.id, function(err, response) {
65-
self.callback(err, response, create_response);
66-
});
55+
'without a time limit': {
56+
topic: function(create_err, person) {
57+
blockscore.question_sets.create(person.id, this.callback);
6758
},
68-
'check question set is same as when created': function(err, retrieve_response, create_response) {
59+
'got newly created question set': function(err, response) {
6960
assert.ifError(err);
70-
assert.deepEqual(retrieve_response, create_response);
61+
assert.ok(response.person_id);
62+
assert.ok(response.id);
63+
assert.ok(Array.isArray(response.questions));
64+
assert.ok(Array.isArray(response.questions[0].answers));
65+
},
66+
'retrieve question set': {
67+
topic: function(err, create_response) {
68+
var self = this;
69+
blockscore.question_sets.retrieve(create_response.id, function(err, response) {
70+
self.callback(err, response, create_response);
71+
});
72+
},
73+
'check question set is same as when created': function(err, retrieve_response, create_response) {
74+
assert.ifError(err);
75+
assert.deepEqual(retrieve_response, create_response);
76+
}
77+
},
78+
'score question set': {
79+
topic: function(err, response) {
80+
var data = {
81+
id: response.id,
82+
answers: [
83+
{
84+
question_id: 1,
85+
answer_id: 1
86+
},
87+
{
88+
question_id: 2,
89+
answer_id: 1
90+
},
91+
{
92+
question_id: 3,
93+
answer_id: 1
94+
},
95+
{
96+
question_id: 4,
97+
answer_id: 1
98+
},
99+
{
100+
question_id: 5,
101+
answer_id: 1
102+
}
103+
]
104+
};
105+
blockscore.question_sets.score(data, this.callback);
106+
},
107+
'Got score': function(err, response) {
108+
assert.ifError(err);
109+
assert.ok(response.id);
110+
assert.ok(typeof response.score == 'number');
111+
}
71112
}
72113
},
73-
'score question set': {
74-
topic: function(err, response) {
75-
var data = {
76-
id: response.id,
77-
answers: [
78-
{
79-
question_id: 1,
80-
answer_id: 1
81-
},
82-
{
83-
question_id: 2,
84-
answer_id: 1
85-
},
86-
{
87-
question_id: 3,
88-
answer_id: 1
89-
},
90-
{
91-
question_id: 4,
92-
answer_id: 1
93-
},
94-
{
95-
question_id: 5,
96-
answer_id: 1
97-
}
98-
]
99-
};
100-
blockscore.question_sets.score(data, this.callback);
114+
'with a time limit': {
115+
topic: function(create_err, person) {
116+
blockscore.question_sets.create({
117+
person_id: person.id,
118+
time_limit: 42
119+
}, this.callback);
101120
},
102-
'Got score': function(err, response) {
121+
'got newly created question set': function(err, response) {
103122
assert.ifError(err);
123+
assert.ok(response.person_id);
104124
assert.ok(response.id);
105-
assert.ok(typeof response.score == 'number');
125+
assert.ok(Array.isArray(response.questions));
126+
assert.ok(Array.isArray(response.questions[0].answers));
127+
assert.equal(response.time_limit, 42);
128+
},
129+
'retrieve question set': {
130+
topic: function(err, create_response) {
131+
var self = this;
132+
blockscore.question_sets.retrieve(create_response.id, function(err, response) {
133+
self.callback(err, response, create_response);
134+
});
135+
},
136+
'check question set is same as when created': function(err, retrieve_response, create_response) {
137+
assert.ifError(err);
138+
assert.deepEqual(retrieve_response, create_response);
139+
}
106140
}
107141
}
108142
}

0 commit comments

Comments
 (0)