Merge pull request #2551 from strongloop/fix/global-registry-in-fixtures
test: use local registry in test fixtures
This commit is contained in:
commit
ea21169da0
|
@ -268,7 +268,7 @@ module.exports = function(ACL) {
|
||||||
* @return {Object[]} An array of ACLs
|
* @return {Object[]} An array of ACLs
|
||||||
*/
|
*/
|
||||||
ACL.getStaticACLs = function getStaticACLs(model, property) {
|
ACL.getStaticACLs = function getStaticACLs(model, property) {
|
||||||
var modelClass = loopback.findModel(model);
|
var modelClass = this.registry.findModel(model);
|
||||||
var staticACLs = [];
|
var staticACLs = [];
|
||||||
if (modelClass && modelClass.settings.acls) {
|
if (modelClass && modelClass.settings.acls) {
|
||||||
modelClass.settings.acls.forEach(function(acl) {
|
modelClass.settings.acls.forEach(function(acl) {
|
||||||
|
@ -361,7 +361,7 @@ module.exports = function(ACL) {
|
||||||
acls = acls.concat(dynACLs);
|
acls = acls.concat(dynACLs);
|
||||||
resolved = self.resolvePermission(acls, req);
|
resolved = self.resolvePermission(acls, req);
|
||||||
if (resolved && resolved.permission === ACL.DEFAULT) {
|
if (resolved && resolved.permission === ACL.DEFAULT) {
|
||||||
var modelClass = loopback.findModel(model);
|
var modelClass = self.registry.findModel(model);
|
||||||
resolved.permission = (modelClass && modelClass.settings.defaultPermission) || ACL.ALLOW;
|
resolved.permission = (modelClass && modelClass.settings.defaultPermission) || ACL.ALLOW;
|
||||||
}
|
}
|
||||||
if (callback) callback(null, resolved);
|
if (callback) callback(null, resolved);
|
||||||
|
|
|
@ -144,7 +144,7 @@ module.exports = function(Change) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Change.findOrCreateChange = function(modelName, modelId, callback) {
|
Change.findOrCreateChange = function(modelName, modelId, callback) {
|
||||||
assert(loopback.findModel(modelName), modelName + ' does not exist');
|
assert(this.registry.findModel(modelName), modelName + ' does not exist');
|
||||||
callback = callback || utils.createPromiseCallback();
|
callback = callback || utils.createPromiseCallback();
|
||||||
var id = this.idForModel(modelName, modelId);
|
var id = this.idForModel(modelName, modelId);
|
||||||
var Change = this;
|
var Change = this;
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
"principalType": "ROLE",
|
"principalType": "ROLE",
|
||||||
"principalId": "$owner",
|
"principalId": "$owner",
|
||||||
"permission": "ALLOW",
|
"permission": "ALLOW",
|
||||||
"property": "updateAttributes"
|
"property": "patchAttributes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"principalType": "ROLE",
|
"principalType": "ROLE",
|
||||||
|
|
|
@ -397,6 +397,9 @@ describe('AccessToken', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('app.enableAuth()', function() {
|
describe('app.enableAuth()', function() {
|
||||||
|
beforeEach(function setupAuthWithModels() {
|
||||||
|
app.enableAuth({ dataSource: ds });
|
||||||
|
});
|
||||||
beforeEach(createTestingToken);
|
beforeEach(createTestingToken);
|
||||||
|
|
||||||
it('prevents remote call with 401 status on denied ACL', function(done) {
|
it('prevents remote call with 401 status on denied ACL', function(done) {
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"sources": [
|
"sources": [
|
||||||
"../common/models",
|
"../common/models",
|
||||||
"./models"
|
"./models",
|
||||||
|
"../../../../common/models"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ACL": {
|
"ACL": {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
var loopback = require('../../../..');
|
var loopback = require('../../../..');
|
||||||
var boot = require('loopback-boot');
|
var boot = require('loopback-boot');
|
||||||
var app = module.exports = loopback();
|
var app = module.exports = loopback({ localRegistry: true });
|
||||||
var errorHandler = require('strong-error-handler');
|
var errorHandler = require('strong-error-handler');
|
||||||
boot(app, __dirname);
|
boot(app, __dirname);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// License text available at https://opensource.org/licenses/MIT
|
// License text available at https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
var loopback = require('../../../../index');
|
var loopback = require('../../../../index');
|
||||||
var app = module.exports = loopback();
|
var app = module.exports = loopback({ localRegistry: true });
|
||||||
var models = require('./models');
|
var models = require('./models');
|
||||||
var TestModel = models.TestModel;
|
var TestModel = models.TestModel;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"sources": [
|
"sources": [
|
||||||
"../common/models",
|
"../common/models",
|
||||||
"./models"
|
"./models",
|
||||||
|
"../../../../common/models"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"User": {
|
"User": {
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"sources": [
|
"sources": [
|
||||||
"../common/models",
|
"../common/models",
|
||||||
"./models"
|
"./models",
|
||||||
|
"../../../../common/models"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ACL": {
|
"ACL": {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
var loopback = require('../../../../index');
|
var loopback = require('../../../../index');
|
||||||
var boot = require('loopback-boot');
|
var boot = require('loopback-boot');
|
||||||
var app = module.exports = loopback();
|
var app = module.exports = loopback({ localRegistry: true });
|
||||||
var errorHandler = require('strong-error-handler');
|
var errorHandler = require('strong-error-handler');
|
||||||
|
|
||||||
boot(app, __dirname);
|
boot(app, __dirname);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "post",
|
"name": "Post",
|
||||||
"base": "PersistedModel",
|
"base": "PersistedModel",
|
||||||
"properties": {
|
"properties": {
|
||||||
"title": {
|
"title": {
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"sources": [
|
"sources": [
|
||||||
"../common/models",
|
"../common/models",
|
||||||
"./models"
|
"./models",
|
||||||
|
"../../../../common/models"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Email": {
|
"Email": {
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
"public": true,
|
"public": true,
|
||||||
"relations": {
|
"relations": {
|
||||||
"posts": {
|
"posts": {
|
||||||
"model": "post",
|
"model": "Post",
|
||||||
"type": "hasMany",
|
"type": "hasMany",
|
||||||
"foreignKey": "userId"
|
"foreignKey": "userId"
|
||||||
}
|
}
|
||||||
|
@ -51,7 +52,7 @@
|
||||||
"dataSource": "db",
|
"dataSource": "db",
|
||||||
"public": true
|
"public": true
|
||||||
},
|
},
|
||||||
"post": {
|
"Post": {
|
||||||
"dataSource": "db",
|
"dataSource": "db",
|
||||||
"public": true
|
"public": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
var loopback = require('../../../../index');
|
var loopback = require('../../../../index');
|
||||||
var boot = require('loopback-boot');
|
var boot = require('loopback-boot');
|
||||||
var app = module.exports = loopback();
|
var app = module.exports = loopback({ localRegistry: true });
|
||||||
var errorHandler = require('strong-error-handler');
|
var errorHandler = require('strong-error-handler');
|
||||||
app.enableAuth();
|
app.enableAuth();
|
||||||
boot(app, __dirname);
|
boot(app, __dirname);
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var loopback = require('../');
|
var loopback = require('../');
|
||||||
var ACL = loopback.ACL;
|
var ACL = loopback.ACL;
|
||||||
var Change = loopback.Change;
|
|
||||||
var defineModelTestsWithDataSource = require('./util/model-tests');
|
var defineModelTestsWithDataSource = require('./util/model-tests');
|
||||||
var PersistedModel = loopback.PersistedModel;
|
var PersistedModel = loopback.PersistedModel;
|
||||||
|
|
||||||
|
@ -74,7 +73,10 @@ describe.onServer('Remote Methods', function() {
|
||||||
var User, Post, dataSource, app;
|
var User, Post, dataSource, app;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
User = PersistedModel.extend('user', {
|
app = loopback({ localRegistry: true, loadBuiltinModels: true });
|
||||||
|
app.set('remoting', { errorHandler: { debug: true, log: false }});
|
||||||
|
|
||||||
|
User = app.registry.createModel('user', {
|
||||||
id: { id: true, type: String, defaultFn: 'guid' },
|
id: { id: true, type: String, defaultFn: 'guid' },
|
||||||
'first': String,
|
'first': String,
|
||||||
'last': String,
|
'last': String,
|
||||||
|
@ -87,7 +89,7 @@ describe.onServer('Remote Methods', function() {
|
||||||
trackChanges: true,
|
trackChanges: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
Post = PersistedModel.extend('post', {
|
Post = app.registry.createModel('post', {
|
||||||
id: { id: true, type: String, defaultFn: 'guid' },
|
id: { id: true, type: String, defaultFn: 'guid' },
|
||||||
title: String,
|
title: String,
|
||||||
content: String,
|
content: String,
|
||||||
|
@ -95,12 +97,10 @@ describe.onServer('Remote Methods', function() {
|
||||||
trackChanges: true,
|
trackChanges: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
dataSource = loopback.createDataSource({
|
dataSource = app.dataSource('db', { connector: 'memory' });
|
||||||
connector: loopback.Memory,
|
|
||||||
});
|
|
||||||
|
|
||||||
User.attachTo(dataSource);
|
app.model(User, { dataSource: 'db' });
|
||||||
Post.attachTo(dataSource);
|
app.model(Post, { dataSource: 'db' });
|
||||||
|
|
||||||
User.hasMany(Post);
|
User.hasMany(Post);
|
||||||
|
|
||||||
|
@ -112,22 +112,16 @@ describe.onServer('Remote Methods', function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loopback.remoteMethod(
|
User.remoteMethod('login', {
|
||||||
User.login,
|
|
||||||
{
|
|
||||||
accepts: [
|
accepts: [
|
||||||
{ arg: 'username', type: 'string', required: true },
|
{ arg: 'username', type: 'string', required: true },
|
||||||
{ arg: 'password', type: 'string', required: true },
|
{ arg: 'password', type: 'string', required: true },
|
||||||
],
|
],
|
||||||
returns: { arg: 'sessionId', type: 'any', root: true },
|
returns: { arg: 'sessionId', type: 'any', root: true },
|
||||||
http: { path: '/sign-in', verb: 'get' },
|
http: { path: '/sign-in', verb: 'get' },
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
app = loopback();
|
|
||||||
app.set('remoting', { errorHandler: { debug: true, log: false }});
|
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
app.model(User);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Model.destroyAll(callback)', function() {
|
describe('Model.destroyAll(callback)', function() {
|
||||||
|
@ -549,7 +543,7 @@ describe.onServer('Remote Methods', function() {
|
||||||
it('Get the Change Model', function() {
|
it('Get the Change Model', function() {
|
||||||
var UserChange = User.getChangeModel();
|
var UserChange = User.getChangeModel();
|
||||||
var change = new UserChange();
|
var change = new UserChange();
|
||||||
assert(change instanceof Change);
|
assert(change instanceof app.registry.getModel('Change'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,10 @@ describe('users - integration', function() {
|
||||||
lt.beforeEach.withApp(app);
|
lt.beforeEach.withApp(app);
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
// HACK: [rfeng] We have to reset the relations as they are polluted by
|
|
||||||
// other tests
|
|
||||||
app.models.User.hasMany(app.models.post);
|
|
||||||
app.models.User.hasMany(app.models.AccessToken,
|
|
||||||
{ options: { disableInclude: true }});
|
|
||||||
app.models.AccessToken.belongsTo(app.models.User);
|
|
||||||
app.models.User.destroyAll(function(err) {
|
app.models.User.destroyAll(function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
app.models.post.destroyAll(function(err) {
|
app.models.Post.destroyAll(function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
app.models.blog.destroyAll(function(err) {
|
app.models.blog.destroyAll(function(err) {
|
||||||
|
|
Loading…
Reference in New Issue