More tests
This commit is contained in:
parent
935cd5cc77
commit
5df77ac4d0
|
@ -1,8 +1,14 @@
|
||||||
describe('DataSource', function() {
|
describe('DataSource', function() {
|
||||||
|
var memory;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
memory = asteroid.createDataSource({
|
||||||
|
connector: asteroid.Memory
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('dataSource.createModel(name, properties, settings)', function() {
|
describe('dataSource.createModel(name, properties, settings)', function() {
|
||||||
it("Define a model and attach it to a `DataSource`.", 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});
|
var Color = memory.createModel('color', {name: String});
|
||||||
assert.isFunc(Color, 'all');
|
assert.isFunc(Color, 'all');
|
||||||
assert.isFunc(Color, 'create');
|
assert.isFunc(Color, 'create');
|
||||||
|
@ -28,129 +34,129 @@ describe('DataSource', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dataSource.discover(options, fn)', function() {
|
// describe('dataSource.discover(options, fn)', function() {
|
||||||
it("Discover an object containing properties and settings for an existing data source.", function(done) {
|
// it("Discover an object containing properties and settings for an existing data source.", function(done) {
|
||||||
/* example -
|
// /* example -
|
||||||
oracle.discover({owner: 'MYORG'}, function(err, tables) {
|
// oracle.discover({owner: 'MYORG'}, function(err, tables) {
|
||||||
var productSchema = tables.PRODUCTS;
|
// var productSchema = tables.PRODUCTS;
|
||||||
var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
|
// var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
*/
|
// */
|
||||||
done(new Error('test not implemented'));
|
// 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() {
|
// describe('dataSource.discoverModels(options, fn) ', function() {
|
||||||
it("Synchronously discover an object containing properties and settings for an existing data source tables or collections.", function(done) {
|
// it("Discover a set of models based on tables or collections in a data source.", function(done) {
|
||||||
/* example -
|
// /* example -
|
||||||
var tables = oracle.discover({owner: 'MYORG'});
|
// oracle.discoverModels({owner: 'MYORG'}, function(err, models) {
|
||||||
var productSchema = tables.PRODUCTS;
|
// var ProductModel = models.Product;
|
||||||
var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings);
|
// });
|
||||||
|
//
|
||||||
*/
|
// */
|
||||||
done(new Error('test not implemented'));
|
// done(new Error('test not implemented'));
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
describe('dataSource.discoverModels(options, fn) ', function() {
|
// describe('dataSource.discoverModelsSync(options)', function() {
|
||||||
it("Discover a set of models based on tables or collections in a data source.", function(done) {
|
// it("Synchronously Discover a set of models based on tables or collections in a data source.", function(done) {
|
||||||
/* example -
|
// /* example -
|
||||||
oracle.discoverModels({owner: 'MYORG'}, function(err, models) {
|
// var models = oracle.discoverModels({owner: 'MYORG'});
|
||||||
var ProductModel = models.Product;
|
// var ProductModel = models.Product;
|
||||||
});
|
// */
|
||||||
|
// done(new Error('test not implemented'));
|
||||||
|
// });
|
||||||
*/
|
// });
|
||||||
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() {
|
describe('dataSource.enable(operation)', function() {
|
||||||
it("Enable a data source operation", function(done) {
|
it("Enable a data source operation", function() {
|
||||||
/* 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
|
|
||||||
});
|
|
||||||
|
|
||||||
// enable an operation
|
// enable an operation
|
||||||
twitter.enable('find');
|
memory.disable('find');
|
||||||
|
|
||||||
// enable remote access
|
var find = memory.getOperation('find');
|
||||||
twitter.enableRemote('find')
|
|
||||||
|
|
||||||
*/
|
assert.equal(find.name, 'find');
|
||||||
done(new Error('test not implemented'));
|
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() {
|
describe('dataSource.disable(operation)', function() {
|
||||||
it("Disable a data source operation", function(done) {
|
it("Disable a data source operation", function() {
|
||||||
/* example -
|
var find = memory.getOperation('all');
|
||||||
// all rest data source operations are
|
|
||||||
// disabled by default
|
assert.equal(find.name, 'all');
|
||||||
var oracle = asteroid.createDataSource({
|
assert.equal(find.enabled, true);
|
||||||
connector: require('asteroid-oracle'),
|
assert.equal(find.remoteEnabled, true);
|
||||||
host: '...',
|
|
||||||
...
|
memory.disableRemote('all');
|
||||||
});
|
|
||||||
// disable an operation completely
|
assert.equal(find.name, 'all');
|
||||||
oracle.disable('destroyAll');
|
assert.equal(find.enabled, true);
|
||||||
|
assert.equal(find.remoteEnabled, false);
|
||||||
// or only disable it as a remote method
|
|
||||||
oracle.disableRemote('destroyAll');
|
memory.disable('all');
|
||||||
*/
|
|
||||||
done(new Error('test not implemented'));
|
assert.equal(find.name, 'all');
|
||||||
|
assert.equal(find.enabled, false);
|
||||||
|
assert.equal(find.remoteEnabled, false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dataSource.operations()', function() {
|
describe('dataSource.operations()', function() {
|
||||||
it("List the enabled and disabled operations.", function(done) {
|
it("List the enabled and disabled operations.", function() {
|
||||||
/* example -
|
existsAndShared('_forDB', false);
|
||||||
console.log(oracle.operations());
|
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);
|
||||||
|
|
||||||
{
|
function existsAndShared(name, isRemoteEnabled) {
|
||||||
find: {
|
var op = memory.getOperation(name);
|
||||||
allowRemote: true,
|
console.log(op.name, op.remoteEnabled, isRemoteEnabled);
|
||||||
accepts: [...],
|
assert(op.remoteEnabled === isRemoteEnabled, name + ' ' + (isRemoteEnabled ? 'should' : 'should not') + ' be remote enabled');
|
||||||
returns: [...]
|
|
||||||
enabled: true
|
|
||||||
},
|
|
||||||
...
|
|
||||||
}
|
}
|
||||||
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'));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -5,10 +5,10 @@
|
||||||
assert = require('assert');
|
assert = require('assert');
|
||||||
asteroid = require('../');
|
asteroid = require('../');
|
||||||
memoryConnector = asteroid.Memory;
|
memoryConnector = asteroid.Memory;
|
||||||
|
app = null;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
app = asteroid();
|
app = asteroid();
|
||||||
memoryDataSource = asteroid.createDataSource({connector: memoryConnector});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assertValidDataSource = function (dataSource) {
|
assertValidDataSource = function (dataSource) {
|
||||||
|
|
Loading…
Reference in New Issue