More tests

This commit is contained in:
Ritchie 2013-06-11 11:07:49 -07:00
parent 935cd5cc77
commit 5df77ac4d0
2 changed files with 115 additions and 109 deletions

View File

@ -1,8 +1,14 @@
describe('DataSource', function() {
var memory;
beforeEach(function(){
memory = asteroid.createDataSource({
connector: asteroid.Memory
});
});
describe('dataSource.createModel(name, properties, settings)', function() {
it("Define a model and attach it to a `DataSource`.", function() {
var memory = asteroid.createDataSource({connector: asteroid.Memory});
var Color = memory.createModel('color', {name: String});
assert.isFunc(Color, 'all');
assert.isFunc(Color, 'create');
@ -28,129 +34,129 @@ describe('DataSource', function() {
});
});
describe('dataSource.discover(options, fn)', function() {
it("Discover an object containing properties and settings for an existing data source.", function(done) {
/* example -
oracle.discover({owner: 'MYORG'}, function(err, tables) {
var productSchema = tables.PRODUCTS;
var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
});
*/
done(new Error('test not implemented'));
});
});
// describe('dataSource.discover(options, fn)', function() {
// it("Discover an object containing properties and settings for an existing data source.", function(done) {
// /* example -
// oracle.discover({owner: 'MYORG'}, function(err, tables) {
// var productSchema = tables.PRODUCTS;
// var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
// });
//
// */
// done(new Error('test not implemented'));
// });
// });
//
// describe('dataSource.discoverSync(options)', function() {
// it("Synchronously discover an object containing properties and settings for an existing data source tables or collections.", function(done) {
// /* example -
// var tables = oracle.discover({owner: 'MYORG'});
// var productSchema = tables.PRODUCTS;
// var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
//
// */
// done(new Error('test not implemented'));
// });
// });
describe('dataSource.discoverSync(options)', function() {
it("Synchronously discover an object containing properties and settings for an existing data source tables or collections.", function(done) {
/* example -
var tables = oracle.discover({owner: 'MYORG'});
var productSchema = tables.PRODUCTS;
var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
*/
done(new Error('test not implemented'));
});
});
describe('dataSource.discoverModels(options, fn) ', function() {
it("Discover a set of models based on tables or collections in a data source.", function(done) {
/* example -
oracle.discoverModels({owner: 'MYORG'}, function(err, models) {
var ProductModel = models.Product;
});
*/
done(new Error('test not implemented'));
});
});
describe('dataSource.discoverModelsSync(options)', function() {
it("Synchronously Discover a set of models based on tables or collections in a data source.", function(done) {
/* example -
var models = oracle.discoverModels({owner: 'MYORG'});
var ProductModel = models.Product;
*/
done(new Error('test not implemented'));
});
});
// describe('dataSource.discoverModels(options, fn) ', function() {
// it("Discover a set of models based on tables or collections in a data source.", function(done) {
// /* example -
// oracle.discoverModels({owner: 'MYORG'}, function(err, models) {
// var ProductModel = models.Product;
// });
//
// */
// done(new Error('test not implemented'));
// });
// });
//
// describe('dataSource.discoverModelsSync(options)', function() {
// it("Synchronously Discover a set of models based on tables or collections in a data source.", function(done) {
// /* example -
// var models = oracle.discoverModels({owner: 'MYORG'});
// var ProductModel = models.Product;
// */
// done(new Error('test not implemented'));
// });
// });
describe('dataSource.enable(operation)', function() {
it("Enable a data source operation", function(done) {
/* example -
// all rest data source operations are
// disabled by default
var rest = asteroid.createDataSource({
connector: require('asteroid-rest'),
url: 'http://maps.googleapis.com/maps/api'
enableAll: true
});
it("Enable a data source operation", function() {
// enable an operation
twitter.enable('find');
memory.disable('find');
// enable remote access
twitter.enableRemote('find')
var find = memory.getOperation('find');
*/
done(new Error('test not implemented'));
assert.equal(find.name, 'find');
assert.equal(find.enabled, false);
assert.equal(find.remoteEnabled, false);
memory.enable('find');
assert.equal(find.name, 'find');
assert.equal(find.enabled, true);
assert.equal(find.remoteEnabled, false);
memory.enableRemote('find');
assert.equal(find.remoteEnabled, true);
});
});
describe('dataSource.disable(operation)', function() {
it("Disable a data source operation", function(done) {
/* example -
// all rest data source operations are
// disabled by default
var oracle = asteroid.createDataSource({
connector: require('asteroid-oracle'),
host: '...',
...
});
// disable an operation completely
oracle.disable('destroyAll');
// or only disable it as a remote method
oracle.disableRemote('destroyAll');
*/
done(new Error('test not implemented'));
it("Disable a data source operation", function() {
var find = memory.getOperation('all');
assert.equal(find.name, 'all');
assert.equal(find.enabled, true);
assert.equal(find.remoteEnabled, true);
memory.disableRemote('all');
assert.equal(find.name, 'all');
assert.equal(find.enabled, true);
assert.equal(find.remoteEnabled, false);
memory.disable('all');
assert.equal(find.name, 'all');
assert.equal(find.enabled, false);
assert.equal(find.remoteEnabled, false);
});
});
describe('dataSource.operations()', function() {
it("List the enabled and disabled operations.", function(done) {
/* example -
console.log(oracle.operations());
it("List the enabled and disabled operations.", function() {
existsAndShared('_forDB', false);
existsAndShared('create', true);
existsAndShared('updateOrCreate', false);
existsAndShared('upsert', false);
existsAndShared('findOrCreate', false);
existsAndShared('exists', true);
existsAndShared('find', true);
existsAndShared('all', true);
existsAndShared('findOne', true);
existsAndShared('destroyAll', false);
existsAndShared('count', true);
existsAndShared('include', false);
existsAndShared('relationNameFor', false);
existsAndShared('hasMany', false);
existsAndShared('belongsTo', false);
existsAndShared('hasAndBelongsToMany', false);
existsAndShared('save', true);
existsAndShared('isNewRecord', false);
existsAndShared('_adapter', false);
existsAndShared('destroy', true);
existsAndShared('updateAttribute', true);
existsAndShared('updateAttributes', true);
existsAndShared('reload', true);
{
find: {
allowRemote: true,
accepts: [...],
returns: [...]
enabled: true
},
...
function existsAndShared(name, isRemoteEnabled) {
var op = memory.getOperation(name);
console.log(op.name, op.remoteEnabled, isRemoteEnabled);
assert(op.remoteEnabled === isRemoteEnabled, name + ' ' + (isRemoteEnabled ? 'should' : 'should not') + ' be remote enabled');
}
var memory = asteroid.createDataSource({
connector: asteroid.Memory
});
{
"dependencies": {
"asteroid-oracle": "latest"
}
}
var CoffeeShop = asteroid.createModel('coffee-shop', {
location: 'GeoPoint'
});
CoffeeShop.attach(oracle);
var here = new GeoPoint({lat: 10.32424, long: 5.84978});
CoffeeShop.all({where: {location: {near: here}}}, function(err, nearbyShops) {
console.info(nearbyShops); // [CoffeeShop, ...]
});
*/
done(new Error('test not implemented'));
});
});
});

View File

@ -5,10 +5,10 @@
assert = require('assert');
asteroid = require('../');
memoryConnector = asteroid.Memory;
app = null;
beforeEach(function () {
app = asteroid();
memoryDataSource = asteroid.createDataSource({connector: memoryConnector});
});
assertValidDataSource = function (dataSource) {