loopback/test/hidden-properties.test.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

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();
});
});
});