UNPKG

2.06 kBJavaScriptView Raw
1// Copyright IBM Corp. 2017,2019. All Rights Reserved.
2// Node module: loopback-datasource-juggler
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6// This test written in mocha+should.js
7'use strict';
8const should = require('./init.js');
9const assert = require('assert');
10
11const jdb = require('../');
12const ModelBuilder = jdb.ModelBuilder;
13
14describe('exclude properties ', function() {
15 it('from base model', function(done) {
16 const ds = new ModelBuilder();
17 // create a base model User which has name and password properties. id property gets
18 // internally created for the User Model
19 const User = ds.define('User', {name: String, password: String});
20 let properties = User.definition.properties;
21 // User should have id, name & password properties
22 assert(('id' in properties) && ('password' in properties) && ('name' in properties),
23 'User should have id, name & password properties');
24 // Create sub model Customer with vip as property. id property gets automatically created here as well.
25 // Customer will inherit name, password and id from base User model.
26 // With excludeBaseProperties, 'password' and 'id' gets excluded from base User model
27 // With idInjection: false - id property of sub Model Customer gets excluded. At the end
28 // User will have these 2 properties: name (inherited from User model) and vip (from customer Model).
29 const Customer = User.extend('Customer', {vip: {type: String}},
30 {idInjection: false, excludeBaseProperties: ['password', 'id']});
31 // Customer should have these properties: name(from UserModel) & vip
32 properties = Customer.definition.properties;
33 assert(('name' in properties) && ('vip' in properties),
34 'Customer should have name and vip properties');
35 // id or password properties should not be found in the properties list
36 assert(!(('id' in properties) || ('password' in properties)),
37 'Customer should not have id or password properties');
38 done();
39 });
40});