Skip to content

Commit

Permalink
Merge pull request #42 from appscot/improve_bug_tests
Browse files Browse the repository at this point in the history
Improve bug tests
  • Loading branch information
dmarcelino committed Feb 18, 2015
2 parents 235d8da + 59c95a6 commit deec3d2
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 94 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ test-integration-orientdb:
@echo "Running waterline-orientdb integration tests..."
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--timeout 15000 --globals Associations \
test/integration-orientdb/*.js test/integration-orientdb/tests/**/*.js
--timeout 15000 --globals Associations,CREATE_TEST_WATERLINE,DELETE_TEST_WATERLINE \
test/integration-orientdb/*.js test/integration-orientdb/tests/**/*.js \
test/integration-orientdb/bugs/*.js test/integration-orientdb/bugs/**/*.js

test-unit:
@echo "\n\nRunning waterline-orientdb unit tests..."
Expand Down
24 changes: 12 additions & 12 deletions test/integration-orientdb/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ var fixtures = {

FriendFixture: require('./fixtures/hasManyThrough.friend.fixture'),
FollowsFixture: require('./fixtures/hasManyThrough.follows.fixture'),
OwnsFixture: require('./fixtures/hasManyThrough.owns.fixture'),

// bug fixtures below
Profile40Fixture: require('./fixtures/bugs/40.profile.fixture'),
SubprofileFixture: require('./fixtures/bugs/40.subprofile.fixture'),
ProfileconnectionFixture: require('./fixtures/bugs/40.profileconnection.fixture')
OwnsFixture: require('./fixtures/hasManyThrough.owns.fixture')
};


Expand Down Expand Up @@ -86,15 +81,19 @@ after(function(done) {

function dropCollection(item, next) {
if(!Adapter.hasOwnProperty('drop')) return next();

ontology.collections[item].drop(function(err) {
if(err) return next(err);

// TODO: this is causing OrientDB.ConnectionError [2]: write EPIPE
// ontology.collections[item].drop(function(err) {
// if(err) return next(err);
next();
});
// });
}

async.each(Object.keys(ontology.collections), dropCollection, function(err) {
if(err) return done(err);
if(err) {
console.log('ERROR:', err);
done(err);
}

ontology.collections[Object.keys(ontology.collections)[0]].getServer(function(server){
server.drop({
Expand All @@ -103,7 +102,8 @@ after(function(done) {
})
.then(function(err){
waterline.teardown(done);
});
})
.catch(done);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var assert = require('assert'),
_ = require('lodash'),
utils = require('../../../../lib/utils');

var self = this;

describe('Bug #40: Returning object instead of id', function() {
before(function (done) {
var fixtures = {
Profile40Fixture: require('./40.profile.fixture'),
SubprofileFixture: require('./40.subprofile.fixture'),
ProfileconnectionFixture: require('./40.profileconnection.fixture')
};
CREATE_TEST_WATERLINE(self, 'test_bug_40', fixtures, done);
});
after(function (done) {
DELETE_TEST_WATERLINE('test_bug_40', done);
});

describe('find a profile', function() {
/////////////////////////////////////////////////////
// TEST SETUP
////////////////////////////////////////////////////

var profileRecord, subprofileRecord;

before(function(done) {
self.collections.Profile40.create({ alias: 'juanito', birthday: "1-01-1980" }, function(err, profile) {
if(err) { return done(err); }
profileRecord = profile;
self.collections.Subprofile.create({ name: 'juan' }, function(err, subprofile) {
if(err) { return done(err); }
subprofileRecord = subprofile;

profileRecord.profiles.add(subprofileRecord.id);
profileRecord.save(function(err){
if(err) { return done(err); }
done();
});
});
});
});


/////////////////////////////////////////////////////
// TEST METHODS
////////////////////////////////////////////////////

it('should return a profile with a subprofile', function(done) {
self.collections.Profile40.find()
.populate('profiles')
.then(function(profiles){
assert.equal(profiles.length, 1);
assert.equal(profiles[0].id, profileRecord.id);
done();
})
.catch(done);
});


});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/**
* Dependencies
*/

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({
module.exports = {

identity: 'profile40',
connection: 'associations',
schema: false,

attributes: {
Expand All @@ -22,4 +16,4 @@ module.exports = Waterline.Collection.extend({

}

});
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/**
* Dependencies
*/

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({
module.exports = {

identity: 'profileconnection',
connection: 'associations',
schema: false,

attributes: {
Expand All @@ -32,4 +26,4 @@ module.exports = Waterline.Collection.extend({
}
}

});
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/**
* Dependencies
*/

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({
module.exports = {

identity: 'subprofile',
connection: 'associations',
schema: false,

attributes: {
Expand All @@ -19,4 +13,4 @@ module.exports = Waterline.Collection.extend({
}
}

});
};
100 changes: 100 additions & 0 deletions test/integration-orientdb/bugs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Module Dependencies
*/
var Waterline = require('waterline');
var _ = require('lodash');
var async = require('async');
var Adapter = require('../../../');

var config = require('../../test-connection.json');
config.database = 'waterline-test-orientdb';
config.options = config.options || {};
config.options.storage = "memory";

var instancesMap = {};

/////////////////////////////////////////////////////
// TEST SETUP
////////////////////////////////////////////////////

global.CREATE_TEST_WATERLINE = function(context, dbName, fixtures, cb){
cb = cb || _.noop;

var waterline, ontology;

var localConfig = _.cloneDeep(config);
localConfig.database = dbName;

// context variable
context.collections = {};

waterline = new Waterline();

Object.keys(fixtures).forEach(function(key) {
fixtures[key].connection = dbName;
waterline.loadCollection(Waterline.Collection.extend(fixtures[key]));
});

var Connections = {
'test': localConfig
};
Connections.test.adapter = 'wl_tests';

var connections = {};
connections[dbName] = _.clone(Connections.test);

waterline.initialize({ adapters: { wl_tests: Adapter }, connections: connections }, function(err, _ontology) {
if(err) return cb(err);

ontology = _ontology;

Object.keys(_ontology.collections).forEach(function(key) {
var globalName = key.charAt(0).toUpperCase() + key.slice(1);
context.collections[globalName] = _ontology.collections[key];
});

instancesMap[dbName] = {
waterline: waterline,
ontology: ontology,
config: localConfig
};

cb();
});
};


global.DELETE_TEST_WATERLINE = function(dbName, cb){
cb = cb || _.noop;

if(!instancesMap[dbName]) { return cb(new Error('Waterline instance not found for ' + dbName + '! Did you use the correct db name?')); };

var ontology = instancesMap[dbName].ontology;
var waterline = instancesMap[dbName].waterline;
var localConfig = instancesMap[dbName].config;

function dropCollection(item, next) {
if(!Adapter.hasOwnProperty('drop')) return next();

ontology.collections[item].drop(function(err) {
if(err) return next(err);
next();
});
}

async.each(Object.keys(ontology.collections), dropCollection, function(err) {
if(err) return cb(err);

ontology.collections[Object.keys(ontology.collections)[0]].getServer(function(server){
server.drop({
name: localConfig.database,
storage: localConfig.options.storage
})
.then(function(){
waterline.teardown(cb);
})
.catch(cb);
});
});

};
56 changes: 0 additions & 56 deletions test/integration-orientdb/tests/bugs/40-object_instead_id.js

This file was deleted.

0 comments on commit deec3d2

Please sign in to comment.