Skip to content

Commit

Permalink
Add another test for range.
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Sep 16, 2014
1 parent 737ee61 commit 036dd9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ server.route({
path: '/api/data',
handler: function (request, reply) {
db.getRange(server.nameSpace + ':sqr', server.nameSpace + 'sqr:' + '\xff', function(e, v) {
if (e && e.notFound) {
reply().code(404);
return;
}
reply(v);
});
}
Expand Down
23 changes: 21 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var server = require('..');
server.nameSpace = 'test';
var req = request(server.listener);
var db = require('../db');
var key = 'testkey' + Math.random();

describe('App routes', function() {
it('Should reply as expected on an unknown key', function(done) {
Expand All @@ -22,7 +23,6 @@ describe('App routes', function() {
});
});
it('Should give back the expected value on a known key', function(done) {
var key = 'testkey' + Math.random();
db.set(server.nameSpace + ':sqr:' + key, {key: key}, function() {
req
.get('/api/data/' + key)
Expand All @@ -36,7 +36,6 @@ describe('App routes', function() {
});
});
it('Should save a value on POSTing, and give it back on GET', function(done) {
var key = 'testkey' + Math.random();
req
.post('/api/data/' + key)
.send({key: key})
Expand All @@ -50,4 +49,24 @@ describe('App routes', function() {
});
});
});
it('Should return a range on /api/data', function(done) {
req
.get('/api/data')
.end(function(r, res) {
res.statusCode.should.equal(200);
// Should have a length.
var all = JSON.parse(res.text);
// See if the latest key is in there.
var isthere = false;
all.forEach(function(n) {
if (n.key === server.nameSpace + ':sqr:' + key) {
isthere = true;
}
});
isthere.should.equal(true);
db.del(key, function(e) {
done(e);
});
});
});
});

0 comments on commit 036dd9f

Please sign in to comment.