-
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.
Merge pull request #42 from appscot/improve_bug_tests
Improve bug tests
- Loading branch information
Showing
8 changed files
with
183 additions
and
94 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
62 changes: 62 additions & 0 deletions
62
test/integration-orientdb/bugs/40-object_instead_id/40-object_instead_id.js
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,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); | ||
}); | ||
|
||
|
||
}); | ||
}); |
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,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
56
test/integration-orientdb/tests/bugs/40-object_instead_id.js
This file was deleted.
Oops, something went wrong.