Skip to content

Commit

Permalink
Fleshing out client object with functions for
Browse files Browse the repository at this point in the history
constructQuery()
getDatabaseNames()
getDocument()
putDocument()
ensureDatabaseExists()
  • Loading branch information
Chris Sainty committed Dec 5, 2011
1 parent cd5cba0 commit cc1171d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
34 changes: 33 additions & 1 deletion lib/client.js
Expand Up @@ -15,7 +15,39 @@ function Client (options) {
}
}

Client.prototype.queryIndex = function(indexName, query, callback){
Client.prototype.constructQuery = function(path) {
var self = this;
return self.server_url + path;
}

Client.prototype.getDatabaseNames = function(callback) {
var self = this;
request(self.constructQuery('/databases'), function(error, response, body){
callback(JSON.parse(body));
});
}

Client.prototype.getDocument = function(id, callback){
callback(null);
}

Client.prototype.putDocument = function(id, doc, callback){
var self = this;
request.put({
'uri': self.constructQuery('/docs/' + id),
'json': doc
}, function(error, response, bdoy) {
callback(response.statusCode === 200);
});
}

Client.prototype.ensureDatabaseExists = function(name, callback) {
var docId = 'Raven/Databases/' + name;
var doc = { 'Settings' : { "Raven/DataDir" : "~/Tenants/" + name } };
callback(null);
}

Client.prototype.queryIndex = function(indexName, query, callback) {
var self = this;
callback(indexName);
}
Expand Down
51 changes: 50 additions & 1 deletion test/client.test.js
@@ -1,8 +1,57 @@
var util = require('util');
var should = require('should');
var raven = require('../lib/client');
var server = raven('http://localhost:8080');
var databaseNames;

describe('Client', function() {
describe('#queryIndex()', function(){
describe('constructQuery()', function() {
it('should prepend server name to queries', function(){
server.constructQuery('/databases').should.equal('http://localhost:8080/databases');
})
})

describe('getDatabaseNames()', function() {
it('should return an array of database names', function(done){
server.getDatabaseNames(function (result){
should.exist(result);
result.should.be.an.instanceof(Array);
databaseNames = result;
done();
})
})
})

describe('putdocument()', function() {
it('should return true when saving a document', function (done) {
server.putDocument('docs-1', { 'message': 'Testing.1.2.3' }, function(result){
should.exist(result);
result.should.be.true;
done();
})
})
})

describe('getDocument()', function(){
it('should return null if document is not found', function (done) {
server.getDocument('invalidKey', function(result) {
should.not.exist(result);
done();
});
})
it('should return the correct document')
})

describe('ensureDatabaseExists()', function() {
it('should create a database that does not exist', function(done){
server.ensureDatabaseExists('node-raven', done);
})
it('should not error when a database already exists', function(done){
server.ensureDatabaseExists('node-raven', done);
})
})

describe('queryIndex()', function(){
it('should return results', function(done) {
server.queryIndex('test', '', function(result) {
result.should.equal('test');
Expand Down

0 comments on commit cc1171d

Please sign in to comment.