-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements GET /timer/all to retrieve all timers for a person. #78
- Loading branch information
Showing
16 changed files
with
178 additions
and
27 deletions.
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,18 @@ | ||
var ES = require('esta'); | ||
|
||
module.exports = function(req, reply) { | ||
var query = { | ||
"index": "time", | ||
"type": "timer", | ||
"field": "person", | ||
"text": req.auth.credentials.person.toString() // using issuer as the person | ||
}; | ||
ES.SEARCH(query, function(res) { | ||
if(res.hits.total > 0) { | ||
return reply(res); | ||
} | ||
else { | ||
return reply(res).code(404); | ||
} | ||
}); | ||
} |
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
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
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
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
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,128 @@ | ||
var test = require('tape'); | ||
var server = require("../../web.js"); | ||
var dir = __dirname.split('/')[__dirname.split('/').length-1]; | ||
var file = dir + __filename.replace(__dirname, '') + " -> "; | ||
var token; | ||
var records = 100; | ||
var countdown = records; | ||
|
||
var drop = require('./z_drop'); | ||
test(file+ "Teardown", function(t) { | ||
drop(function(res){ | ||
t.equal(res.acknowledged, true, file+"ALL Records DELETED!"); | ||
t.end(); | ||
}).end(); | ||
}); | ||
|
||
function create(t, callback) { | ||
var timer = { | ||
"desc" : "My Amazing Timer #"+countdown, | ||
"st" : new Date().toISOString() | ||
} | ||
var options = { | ||
method: "POST", | ||
url: "/timer/new", | ||
payload: timer, | ||
headers : { authorization : token } | ||
}; | ||
server.inject(options, function(res) { | ||
countdown--; | ||
// console.log(" >>> "+countdown + " res.created "+ T.created); | ||
if(countdown === 0) { | ||
var T = JSON.parse(res.payload); | ||
t.equal(res.statusCode, 200, records+ " New timers started! " + T.st); | ||
callback(res, t); | ||
} | ||
}); | ||
} | ||
|
||
function finish(res, t){ | ||
// console.log(res); | ||
var T = JSON.parse(res.payload); | ||
var tid = T._id; | ||
var options = { | ||
method: "GET", | ||
url: "/timer/"+tid, | ||
headers : { authorization : token } | ||
}; | ||
|
||
server.inject(options, function(res) { | ||
t.equal(res.statusCode, 200, "New timer retrieved!"+'\n'); | ||
server.stop(); | ||
t.end(); | ||
}); | ||
} | ||
|
||
|
||
|
||
// new anonymous person | ||
test(file + "Register new person to create a few timers", function(t) { | ||
var person = { | ||
"email" : "[email protected]", | ||
"password" : "EveryThingisAwesome", | ||
"firstname": "Jenny" | ||
} | ||
var options = { | ||
method : "POST", | ||
url : "/register", | ||
payload : person | ||
}; | ||
server.inject(options, function(res) { | ||
t.equal(res.statusCode, 200, "Session Created = "+res.result.created); | ||
token = res.headers.authorization; | ||
// can't create create functions inside a for loop so no anon callbacks! | ||
for(var i = 0; i < records; i++) { | ||
create(t, finish); | ||
} // end for | ||
}); | ||
}); | ||
|
||
test(file + "GET /timer/all to list all timers", function(t) { | ||
var options = { | ||
method: "GET", | ||
url: "/timer/all", | ||
headers : { authorization : token } | ||
}; | ||
setTimeout(function(){ | ||
server.inject(options, function(res) { | ||
// console.log(res.result); | ||
var T = JSON.parse(res.payload); | ||
t.equal(res.statusCode, 200, "Find all records for this person"); | ||
t.equal(T.hits.total, 100, "100 records found"); | ||
server.stop(); | ||
t.end(); | ||
}); | ||
},1000) | ||
}); | ||
|
||
test(file + "GET /timer/all should fail for Timmy no timers", function(t) { | ||
var person = { | ||
"email" : "[email protected]", | ||
"password" : "EveryThingisAwesome", | ||
"firstname": "Timmay!" | ||
} | ||
var options = { | ||
method : "POST", | ||
url : "/register", | ||
payload : person | ||
}; | ||
server.inject(options, function(res) { | ||
var newtoken = res.headers.authorization; | ||
var options = { | ||
method: "GET", | ||
url: "/timer/all", | ||
headers : { authorization : newtoken } | ||
}; | ||
setTimeout(function(){ | ||
server.inject(options, function(res) { | ||
console.log(res.result); | ||
var T = JSON.parse(res.payload); | ||
console.log(T); | ||
t.equal(res.statusCode, 404, "Timmay! has no timers..."); | ||
// t.equal(T.hits.total, 100, "100 records found"); | ||
server.stop(); | ||
t.end(); | ||
}); | ||
},1000) | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
var Joi = require('joi'); | ||
module.exports = { | ||
payload: { | ||
person : Joi.string(), // unique id | ||
email : Joi.string().email().required(), | ||
password : Joi.string().required().min(4), | ||
fn : Joi.string(), | ||
ln : Joi.string(), | ||
ct : Joi.forbidden() // don't allow people to set this! | ||
person : Joi.string(), // unique id | ||
email : Joi.string().email().required(), | ||
password : Joi.string().required().min(4), | ||
firstname : Joi.string(), | ||
lastname : Joi.string(), | ||
created : Joi.forbidden() // don't allow people to set this! | ||
} | ||
} |
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