loopback/test/data-source.test.js

80 lines
3.3 KiB
JavaScript
Raw Normal View History

2013-06-07 19:57:51 +00:00
describe('DataSource', function() {
2013-06-11 18:07:49 +00:00
var memory;
beforeEach(function(){
2013-07-16 17:49:25 +00:00
memory = loopback.createDataSource({
connector: loopback.Memory
2013-06-11 18:07:49 +00:00
});
assertValidDataSource(memory);
2013-06-11 18:07:49 +00:00
});
2013-06-07 19:57:51 +00:00
2013-06-08 00:37:30 +00:00
describe('dataSource.createModel(name, properties, settings)', function() {
2013-07-16 20:46:33 +00:00
it("Define a model and attach it to a `DataSource`", function() {
2013-06-11 16:01:44 +00:00
var Color = memory.createModel('color', {name: String});
assert.isFunc(Color, 'find');
assert.isFunc(Color, 'findById');
assert.isFunc(Color, 'findOne');
2013-06-11 16:01:44 +00:00
assert.isFunc(Color, 'create');
assert.isFunc(Color, 'updateOrCreate');
assert.isFunc(Color, 'upsert');
assert.isFunc(Color, 'findOrCreate');
assert.isFunc(Color, 'exists');
assert.isFunc(Color, 'destroyAll');
assert.isFunc(Color, 'count');
assert.isFunc(Color, 'include');
assert.isFunc(Color, 'relationNameFor');
assert.isFunc(Color, 'hasMany');
assert.isFunc(Color, 'belongsTo');
assert.isFunc(Color, 'hasAndBelongsToMany');
assert.isFunc(Color.prototype, 'save');
assert.isFunc(Color.prototype, 'isNewRecord');
assert.isFunc(Color.prototype, 'destroy');
assert.isFunc(Color.prototype, 'updateAttribute');
assert.isFunc(Color.prototype, 'updateAttributes');
assert.isFunc(Color.prototype, 'reload');
2013-06-07 19:57:51 +00:00
});
});
2014-06-05 07:45:09 +00:00
describe.skip('PersistedModel Methods', function() {
2014-05-03 04:19:14 +00:00
it("List the enabled and disabled methods", function() {
2014-06-05 07:45:09 +00:00
var TestModel = loopback.PersistedModel.extend('TestPersistedModel');
2014-05-03 04:19:14 +00:00
TestModel.attachTo(loopback.memory());
2013-06-12 22:44:38 +00:00
// assert the defaults
// - true: the method should be remote enabled
// - false: the method should not be remote enabled
// -
2014-05-03 04:19:14 +00:00
existsAndShared(TestModel, '_forDB', false);
existsAndShared(TestModel, 'create', true);
existsAndShared(TestModel, 'updateOrCreate', true);
existsAndShared(TestModel, 'upsert', true);
existsAndShared(TestModel, 'findOrCreate', false);
existsAndShared(TestModel, 'exists', true);
existsAndShared(TestModel, 'find', true);
existsAndShared(TestModel, 'findOne', true);
existsAndShared(TestModel, 'destroyAll', false);
existsAndShared(TestModel, 'count', true);
existsAndShared(TestModel, 'include', false);
existsAndShared(TestModel, 'relationNameFor', false);
existsAndShared(TestModel, 'hasMany', false);
existsAndShared(TestModel, 'belongsTo', false);
existsAndShared(TestModel, 'hasAndBelongsToMany', false);
// existsAndShared(TestModel.prototype, 'updateAttributes', true);
existsAndShared(TestModel, 'save', false, true);
existsAndShared(TestModel, 'isNewRecord', false, true);
existsAndShared(TestModel, '_adapter', false, true);
existsAndShared(TestModel, 'destroy', false, true);
existsAndShared(TestModel, 'reload', false, true);
2013-06-07 19:57:51 +00:00
function existsAndShared(Model, name, isRemoteEnabled, isProto) {
var scope = isProto ? Model.prototype : Model;
2014-05-03 04:19:14 +00:00
var fn = scope[name];
var actuallyEnabled = Model.getRemoteMethod(name);
2014-05-03 04:19:14 +00:00
assert(fn, name + ' should be defined!');
assert(actuallyEnabled === isRemoteEnabled, name + ' ' + (isRemoteEnabled ? 'should' : 'should not') + ' be remote enabled');
2013-06-07 19:57:51 +00:00
}
});
});
2013-08-16 23:39:13 +00:00
});