2016-05-04 00:10:46 +00:00
|
|
|
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2014-03-21 19:18:00 +00:00
|
|
|
var loopback = require('../');
|
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
describe('hidden properties', function() {
|
|
|
|
beforeEach(function(done) {
|
2014-03-21 19:18:00 +00:00
|
|
|
var app = this.app = loopback();
|
2014-06-05 07:45:09 +00:00
|
|
|
var Product = this.Product = loopback.PersistedModel.extend('product',
|
2014-05-03 04:19:14 +00:00
|
|
|
{},
|
|
|
|
{hidden: ['secret']}
|
|
|
|
);
|
|
|
|
Product.attachTo(loopback.memory());
|
2014-11-21 01:46:21 +00:00
|
|
|
|
2014-06-05 07:45:09 +00:00
|
|
|
var Category = this.Category = loopback.PersistedModel.extend('category');
|
2014-05-03 04:19:14 +00:00
|
|
|
Category.attachTo(loopback.memory());
|
2014-04-11 18:40:53 +00:00
|
|
|
Category.hasMany(Product);
|
2014-11-21 01:46:21 +00:00
|
|
|
|
2014-05-03 04:19:14 +00:00
|
|
|
app.model(Product);
|
|
|
|
app.model(Category);
|
2014-03-21 19:53:04 +00:00
|
|
|
app.use(loopback.rest());
|
2014-11-21 01:46:21 +00:00
|
|
|
|
2014-04-11 18:40:53 +00:00
|
|
|
Category.create({
|
|
|
|
name: 'my category'
|
|
|
|
}, function(err, category) {
|
|
|
|
category.products.create({
|
|
|
|
name: 'pencil',
|
|
|
|
secret: 'a secret'
|
|
|
|
}, done);
|
|
|
|
});
|
2014-03-21 19:18:00 +00:00
|
|
|
});
|
|
|
|
|
2014-04-11 18:40:53 +00:00
|
|
|
afterEach(function(done) {
|
|
|
|
var Product = this.Product;
|
|
|
|
this.Category.destroyAll(function() {
|
|
|
|
Product.destroyAll(done);
|
|
|
|
});
|
2014-11-21 01:46:21 +00:00
|
|
|
});
|
2014-04-11 18:40:53 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
it('should hide a property remotely', function(done) {
|
|
|
|
request(this.app)
|
2016-08-02 08:59:21 +00:00
|
|
|
.get('/products')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) return done(err);
|
2016-05-06 20:50:01 +00:00
|
|
|
|
2016-08-02 08:59:21 +00:00
|
|
|
var product = res.body[0];
|
|
|
|
assert.equal(product.secret, undefined);
|
2016-05-06 20:50:01 +00:00
|
|
|
|
2016-08-02 08:59:21 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-03-21 19:18:00 +00:00
|
|
|
});
|
2014-04-11 18:40:53 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
it('should hide a property of nested models', function(done) {
|
2014-04-11 18:40:53 +00:00
|
|
|
var app = this.app;
|
|
|
|
request(app)
|
|
|
|
.get('/categories?filter[include]=products')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2014-11-21 02:35:36 +00:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) return done(err);
|
2016-05-06 20:50:01 +00:00
|
|
|
|
2014-04-11 18:40:53 +00:00
|
|
|
var category = res.body[0];
|
|
|
|
var product = category.products[0];
|
|
|
|
assert.equal(product.secret, undefined);
|
2016-05-06 20:50:01 +00:00
|
|
|
|
2014-04-11 18:40:53 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-03-21 19:18:00 +00:00
|
|
|
});
|