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';
|
2018-12-07 14:54:29 +00:00
|
|
|
const should = require('./init.js');
|
|
|
|
const assert = require('assert');
|
2017-05-10 19:00:24 +00:00
|
|
|
|
2018-12-07 14:54:29 +00:00
|
|
|
const jdb = require('../');
|
|
|
|
const ModelBuilder = jdb.ModelBuilder;
|
2017-05-10 19:00:24 +00:00
|
|
|
|
|
|
|
describe('exclude properties ', function() {
|
|
|
|
it('from base model', function(done) {
|
2018-12-07 14:54:29 +00:00
|
|
|
const ds = new ModelBuilder();
|
2017-05-12 18:47:50 +00:00
|
|
|
// create a base model User which has name and password properties. id property gets
|
|
|
|
// internally created for the User Model
|
2018-12-07 14:54:29 +00:00
|
|
|
const User = ds.define('User', {name: String, password: String});
|
|
|
|
let properties = User.definition.properties;
|
2017-05-12 18:47:50 +00:00
|
|
|
// User should have id, name & password properties
|
2018-06-12 07:13:32 +00:00
|
|
|
assert(('id' in properties) && ('password' in properties) && ('name' in properties),
|
2017-05-12 18:47:50 +00:00
|
|
|
'User should have id, name & password properties');
|
|
|
|
// Create sub model Customer with vip as property. id property gets automatically created here as well.
|
|
|
|
// Customer will inherit name, password and id from base User model.
|
|
|
|
// With excludeBaseProperties, 'password' and 'id' gets excluded from base User model
|
|
|
|
// With idInjection: false - id property of sub Model Customer gets excluded. At the end
|
|
|
|
// User will have these 2 properties: name (inherited from User model) and vip (from customer Model).
|
2018-12-07 14:54:29 +00:00
|
|
|
const Customer = User.extend('Customer', {vip: {type: String}},
|
2017-05-12 18:47:50 +00:00
|
|
|
{idInjection: false, excludeBaseProperties: ['password', 'id']});
|
|
|
|
// Customer should have these properties: name(from UserModel) & vip
|
2017-05-10 19:00:24 +00:00
|
|
|
properties = Customer.definition.properties;
|
2017-05-12 18:47:50 +00:00
|
|
|
assert(('name' in properties) && ('vip' in properties),
|
|
|
|
'Customer should have name and vip properties');
|
|
|
|
// id or password properties should not be found in the properties list
|
|
|
|
assert(!(('id' in properties) || ('password' in properties)),
|
|
|
|
'Customer should not have id or password properties');
|
2017-05-10 19:00:24 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|