mongodb-expressions
Version:
MongoDB expressions for fire.js
108 lines (105 loc) • 3.13 kB
JavaScript
var vows = require('vows')
var assert = require('assert')
var FireRuntime = require('fire').Runtime
var configRuntime = require('./util').configRuntime
var dropCollection = require('./util').dropCollection
require('./runtimeExtensions.js')
vows.describe('Mongo.Initializers.Test').addBatch({
"When I insert two documents in a collection": {
topic: function() {
dropCollection(function() {
var self = this
var runtime = new FireRuntime()
var testExpressionName = "test_MongoTestInitializer"
runtime.registerWellKnownExpressionDefinition({
name: testExpressionName,
json: {
"@Mongo.Insert(points)": {
x:100,
y:200
},
" @Mongo.Insert(points)": {
x:200,
y:300
},
"@Mongo.Find(points)": null
}
});
configRuntime(runtime, function(initError) {
if(initError) {
self.callback(initError, null)
} else {
var contextBase = {
_resultCallback: function(res) {
self.callback(null, res)
},
_loopCallback: function() {},
_inputExpression: function() {},
_variables: {},
_errorCallback: function(err) {
self.callback(err, null)
}
};
runtime._testOnly_runExpressionByName(testExpressionName, contextBase ,null)
}
})
},this,"points") // Drop database
},
"and retrieve them the result should be two documents": function(err, result) {
assert.isNull(err)
assert.instanceOf(result, Array)
assert.lengthOf(result, 2)
},
"and load another runtime with NODE_ENV in test": {
topic: function() {
var self = this
var runtime = new FireRuntime()
runtime.environmentName = "test"
configRuntime(runtime, function(initError) {
self.callback(null, {
initError: initError
})
})
},
"no initialization errors should occurr": function(err, result) {
assert.isNull(result.initError)
},
"when I execute Mongo.Find over the same collection that I inserted two documents": {
topic: function() {
var self = this
var runtime = new FireRuntime()
var testExpressionName = "test_MongoTestInitializerCheck"
runtime.registerWellKnownExpressionDefinition({
name: testExpressionName,
json: {
"@Mongo.Find(points)": null
}
});
configRuntime(runtime, function(initError) {
if(initError) {
self.callback(initError, null)
}else {
var contextBase = {
_resultCallback: function(res) {
self.callback(null, res)
},
_loopCallback: function() {},
_inputExpression: function() {},
_variables: {},
_errorCallback: function(err) {
self.callback(err, null)
}
};
runtime._testOnly_runExpressionByName(testExpressionName, contextBase ,null)
}
})
},
"the result should be zero documents since the database was dropped by the test initializer": function(err, result) {
assert.isNull(err)
assert.instanceOf(result, Array)
assert.lengthOf(result, 0)
}
}
}
}
}).export(module);