mirror of
/repos/Prototyper.git
synced 2025-12-30 06:31:32 +01:00
fixing the rethink tests
This commit is contained in:
parent
7510025f4d
commit
485834a8be
@ -52,7 +52,6 @@ describe('mongoData', function () {
|
||||
return cb(null, col);
|
||||
}
|
||||
};
|
||||
var shareModel = {};
|
||||
var option_list = [
|
||||
{}, // no collection
|
||||
{query: 'q'}, // no collection
|
||||
@ -79,7 +78,7 @@ describe('mongoData', function () {
|
||||
query: {_id: '456789012345678901234567'}
|
||||
}
|
||||
];
|
||||
var mongoDataInstance = mongoData(config, db, shareModel);
|
||||
var mongoDataInstance = mongoData(config, db);
|
||||
var i;
|
||||
|
||||
function testArguments(options) {
|
||||
@ -162,7 +161,6 @@ describe('mongoData', function () {
|
||||
return cb(null, col);
|
||||
}
|
||||
};
|
||||
var shareModel = {};
|
||||
var option_list = [
|
||||
{}, // no collection
|
||||
{query: 'q'}, // no collection
|
||||
@ -193,7 +191,7 @@ describe('mongoData', function () {
|
||||
attribute: 'content_attribute'
|
||||
}
|
||||
];
|
||||
var mongoDataInstance = mongoData(config, db, shareModel);
|
||||
var mongoDataInstance = mongoData(config, db);
|
||||
var i;
|
||||
|
||||
function testArguments(options) {
|
||||
|
||||
@ -6,6 +6,9 @@ chai.config.includeStack = true; // defaults to false
|
||||
chai.config.showDiff = false; // defaults to false
|
||||
var expect = chai.expect;
|
||||
|
||||
var rethink = require('rethinkdb');
|
||||
var reConnection = null
|
||||
|
||||
var rethinkData = require(libPath + '/rethinkData.js');
|
||||
var config = {
|
||||
debug: function () {
|
||||
@ -18,28 +21,79 @@ var config = {
|
||||
//console.error(arguments);
|
||||
},
|
||||
error: function () {
|
||||
//console.error(arguments);
|
||||
console.error(arguments);
|
||||
}
|
||||
};
|
||||
|
||||
describe('rethinkData', function () {
|
||||
beforeEach(function(done){
|
||||
var config = {
|
||||
host: 'localhost',
|
||||
port: 28015,
|
||||
db: 'PrototyperTest'
|
||||
};
|
||||
rethink.connect(config, function connection_result(err, connection) {
|
||||
reConnection = connection
|
||||
if(err){
|
||||
return done(err)
|
||||
}
|
||||
rethink.dbList()
|
||||
.contains(config.db)
|
||||
.do(function (containsDb) {
|
||||
return rethink.branch(
|
||||
containsDb,
|
||||
{created: 0},
|
||||
rethink.dbCreate(config.db)
|
||||
);
|
||||
})
|
||||
.run(connection, function (err) {
|
||||
return done(err);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done){
|
||||
reConnection.close(done)
|
||||
})
|
||||
describe('getContent', function () {
|
||||
|
||||
var db = {
|
||||
tableList: function(){
|
||||
return this;
|
||||
},
|
||||
contains: function(){
|
||||
return this;
|
||||
},
|
||||
do: function(){
|
||||
return this;
|
||||
},
|
||||
run: function(c,callback){
|
||||
return callback(new Error());
|
||||
}
|
||||
};
|
||||
var shareModel = {};
|
||||
var r = {
|
||||
contains_collection: '',
|
||||
query: null,
|
||||
tableList: function () {
|
||||
return this;
|
||||
},
|
||||
contains: function(collection){
|
||||
this.contains_collection = collection
|
||||
this.query = null
|
||||
return this;
|
||||
},
|
||||
do: function () {
|
||||
return this;
|
||||
},
|
||||
run: function (c, callback) {
|
||||
if(this.query === null) {
|
||||
|
||||
// first time run
|
||||
switch (this.contains_collection) {
|
||||
default:
|
||||
return callback(new Error('default'));
|
||||
case 'test_error':
|
||||
return callback(new Error('test_error'));
|
||||
case 'col':
|
||||
return callback(null, {exists: true});
|
||||
}
|
||||
}
|
||||
// second time run
|
||||
switch (this.query.id) {
|
||||
case 'id':
|
||||
return callback(new Error('bad_di'))
|
||||
}
|
||||
},
|
||||
filter: function (query){
|
||||
this.query = query
|
||||
}
|
||||
};
|
||||
var option_list = [
|
||||
{}, // no collection
|
||||
{query: 'q'}, // no collection
|
||||
@ -66,11 +120,13 @@ describe('rethinkData', function () {
|
||||
query: {id: '456789012345678901234567'}
|
||||
}
|
||||
];
|
||||
var dataInstance = rethinkData(config, db, 'ok', shareModel);
|
||||
var i;
|
||||
|
||||
function testArguments(options) {
|
||||
return function (done) {
|
||||
var dataInstance = rethinkData(config,
|
||||
rethink,
|
||||
reConnection);
|
||||
dataInstance.getContent(options, function (err, result) {
|
||||
if (result === 'ok') {
|
||||
expect(result).to.equal('ok');
|
||||
@ -134,21 +190,22 @@ describe('rethinkData', function () {
|
||||
}
|
||||
|
||||
var col = {findOne: findOne};
|
||||
var db = {
|
||||
var r = {
|
||||
contains_collection: '',
|
||||
tableList: function(){
|
||||
return this;
|
||||
},
|
||||
contains: function(){
|
||||
contains: function(collection){
|
||||
this.contains_collection = collection
|
||||
return this;
|
||||
},
|
||||
do: function(){
|
||||
return this;
|
||||
},
|
||||
run: function(c,callback){
|
||||
return callback(new Error());
|
||||
return callback(new Error('db fails'));
|
||||
}
|
||||
};
|
||||
var shareModel = {};
|
||||
var option_list = [
|
||||
{}, // no collection
|
||||
{query: 'q'}, // no collection
|
||||
@ -179,14 +236,16 @@ describe('rethinkData', function () {
|
||||
attribute: 'content_attribute'
|
||||
}
|
||||
];
|
||||
var dataInstance = rethinkData(config, db, shareModel);
|
||||
var dataInstance = rethinkData(config, r, {});
|
||||
var i;
|
||||
|
||||
function testArguments(options) {
|
||||
return function (done) {
|
||||
dataInstance.getAttribute(options, function (err, result) {
|
||||
if (options.collection === 'ok') {
|
||||
//console.log('result',result,'err',err,'coll',coll);
|
||||
console.log('result',result);
|
||||
console.log('err',err);
|
||||
console.log('options',options);
|
||||
expect(result).to.equal(ok);
|
||||
expect(err).to.not.be.ok;
|
||||
done();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user