loopback/test/memory.test.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

// Copyright IBM Corp. 2013,2018. All Rights Reserved.
2016-05-03 22:50:21 +00:00
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var assert = require('assert');
var loopback = require('../');
2014-11-21 02:35:36 +00:00
describe('Memory Connector', function() {
2013-07-16 20:39:03 +00:00
it('Create a model using the memory connector', function(done) {
// use the built in memory function
// to create a memory data source
var memory = loopback.memory();
// or create it using the standard
// data source creation api
2014-11-21 01:47:47 +00:00
memory = loopback.createDataSource({
connector: loopback.Memory,
2013-07-16 20:39:03 +00:00
});
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
// create a model using the
// memory data source
var properties = {
name: String,
price: Number,
2013-07-16 20:39:03 +00:00
};
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
var Product = memory.createModel('product', properties);
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
Product.create([
{name: 'apple', price: 0.79},
{name: 'pear', price: 1.29},
{name: 'orange', price: 0.59},
2013-07-16 20:39:03 +00:00
], count);
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
function count() {
2014-11-21 02:35:36 +00:00
Product.count(function(err, count) {
2013-07-16 20:39:03 +00:00
assert.equal(count, 3);
2013-07-16 20:39:03 +00:00
done();
});
}
});
2014-11-21 01:47:47 +00:00
});