loopback-datasource-juggler/test/exclude-base-props.test.js

38 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-05-10 19:00:24 +00:00
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback-datasource-juggler
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
// This test written in mocha+should.js
'use strict';
var should = require('./init.js');
var assert = require('assert');
var jdb = require('../');
var ModelBuilder = jdb.ModelBuilder;
describe('exclude properties ', function() {
it('from base model', function(done) {
var ds = new ModelBuilder();
// this excludes id property from 'base: Model' We still need to pass in idInjection: false since User model tries to
// add id again to the model.
var User = ds.define('User', {name: String, password: String},
{idInjection: false, excludeBaseProperties: ['id']});
// User will have these properties: name, password
var properties = User.definition.properties;
2017-05-11 16:59:39 +00:00
assert(('name', 'password' in properties));
// id should not be found in the properties list
assert(!('id' in properties));
2017-05-10 19:00:24 +00:00
// this excludes id property from the base model and and password property coming from base 'User' model since customer is
// extended from User.
var Customer = User.extend('Customer', {vip: {type: String}},
{idInjection: false, excludeBaseProperties: ['password']});
2017-05-11 16:59:39 +00:00
// Customer will have these properties: name(from UserModel) & vip
2017-05-10 19:00:24 +00:00
properties = Customer.definition.properties;
2017-05-11 16:59:39 +00:00
assert(('name', 'vip' in properties));
// id and password properties should not be found in the properties list
assert(!('id', 'password' in properties));
2017-05-10 19:00:24 +00:00
done();
});
});