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
|
|
|
{},
|
2016-04-01 09:14:26 +00:00
|
|
|
{ hidden: ['secret'] }
|
2014-05-03 04:19:14 +00:00
|
|
|
);
|
|
|
|
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({
|
2016-04-01 09:14:26 +00:00
|
|
|
name: 'my category',
|
2014-04-11 18:40:53 +00:00
|
|
|
}, function(err, category) {
|
|
|
|
category.products.create({
|
|
|
|
name: 'pencil',
|
2016-04-01 09:14:26 +00:00
|
|
|
secret: 'a secret',
|
2014-04-11 18:40:53 +00:00
|
|
|
}, 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)
|
|
|
|
.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-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);
|
2014-04-11 18:40:53 +00:00
|
|
|
var category = res.body[0];
|
|
|
|
var product = category.products[0];
|
|
|
|
assert.equal(product.secret, undefined);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-03-21 19:18:00 +00:00
|
|
|
});
|