2013-07-16 17:42:47 +00:00
|
|
|
describe('loopback', function() {
|
|
|
|
describe('loopback.createDataSource(options)', function(){
|
2013-06-11 16:01:44 +00:00
|
|
|
it('Create a data source with a connector.', function() {
|
2013-07-16 17:42:47 +00:00
|
|
|
var dataSource = loopback.createDataSource({
|
|
|
|
connector: loopback.Memory
|
2013-06-11 16:01:44 +00:00
|
|
|
});
|
2013-07-23 19:59:40 +00:00
|
|
|
assert(dataSource.connector);
|
2013-06-08 00:37:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-16 17:42:47 +00:00
|
|
|
describe('loopback.remoteMethod(Model, fn, [options]);', function() {
|
2013-06-11 16:01:44 +00:00
|
|
|
it("Setup a remote method.", function() {
|
2013-07-16 17:42:47 +00:00
|
|
|
var Product = loopback.createModel('product', {price: Number});
|
2013-06-11 16:01:44 +00:00
|
|
|
|
2013-06-07 19:57:51 +00:00
|
|
|
Product.stats = function(fn) {
|
2013-06-11 16:01:44 +00:00
|
|
|
// ...
|
2013-06-07 19:57:51 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 17:42:47 +00:00
|
|
|
loopback.remoteMethod(
|
2013-06-07 19:57:51 +00:00
|
|
|
Product.stats,
|
|
|
|
{
|
|
|
|
returns: {arg: 'stats', type: 'array'},
|
|
|
|
http: {path: '/info', verb: 'get'}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-06-11 16:01:44 +00:00
|
|
|
assert.equal(Product.stats.returns.arg, 'stats');
|
|
|
|
assert.equal(Product.stats.returns.type, 'array');
|
|
|
|
assert.equal(Product.stats.http.path, '/info');
|
|
|
|
assert.equal(Product.stats.http.verb, 'get');
|
|
|
|
assert.equal(Product.stats.shared, true);
|
2013-06-07 19:57:51 +00:00
|
|
|
});
|
|
|
|
});
|
2013-12-10 01:11:01 +00:00
|
|
|
|
|
|
|
describe('loopback.createModel(name, properties, options)', function () {
|
|
|
|
describe('options.base', function () {
|
|
|
|
it('should extend from options.base', function () {
|
|
|
|
var MyModel = loopback.createModel('MyModel', {}, {
|
|
|
|
foo: {
|
|
|
|
bar: 'bat'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var MyCustomModel = loopback.createModel('MyCustomModel', {}, {
|
|
|
|
base: 'MyModel',
|
|
|
|
foo: {
|
|
|
|
bat: 'baz'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert(MyCustomModel.super_ === MyModel);
|
|
|
|
assert.deepEqual(MyCustomModel.settings.foo, { bar: 'bat', bat: 'baz' });
|
|
|
|
assert(MyCustomModel.super_.modelName === MyModel.modelName);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-07-23 19:59:40 +00:00
|
|
|
});
|