loopback/test/hidden-properties.test.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

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
var loopback = require('../');
2014-11-21 02:35:36 +00:00
describe('hidden properties', function() {
beforeEach(function(done) {
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-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());
Category.hasMany(Product);
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());
Category.create({
name: 'my category'
}, function(err, category) {
category.products.create({
name: 'pencil',
secret: 'a secret'
}, done);
});
});
afterEach(function(done) {
var Product = this.Product;
this.Category.destroyAll(function() {
Product.destroyAll(done);
});
});
2014-11-21 02:35:36 +00:00
it('should hide a property remotely', function(done) {
request(this.app)
.get('/products')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
var product = res.body[0];
assert.equal(product.secret, undefined);
done();
});
});
2014-11-21 02:35:36 +00:00
it('should hide a property of nested models', function(done) {
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);
var category = res.body[0];
var product = category.products[0];
assert.equal(product.secret, undefined);
done();
});
});
});