From 5aee1fe17e0f7179c7019f7a077916d1bbc7260d Mon Sep 17 00:00:00 2001 From: rashmihunt Date: Wed, 10 May 2017 12:00:24 -0700 Subject: [PATCH] test case to exclude base props --- test/exclude-base-props.test.js | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/exclude-base-props.test.js diff --git a/test/exclude-base-props.test.js b/test/exclude-base-props.test.js new file mode 100644 index 00000000..40135542 --- /dev/null +++ b/test/exclude-base-props.test.js @@ -0,0 +1,47 @@ +// 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; + + var notFound = true; + for (var p in properties) { + if (p == 'id') { + notFound = false; // id should not be found in the properties list + } + } + assert.equal(notFound, true); + + // 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']}); + // Customer will have these properties: name, vip + properties = Customer.definition.properties; + notFound = true; + for (p in properties) { + if (p == 'id' || p == 'password') { + notFound = false; // id and password properties should not be found in the properties list + } + } + assert.equal(notFound, true); + done(); + }); +});