Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Fix bugs in givenUser/WithRole when combined withUserModel helper#69
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -92,7 +92,8 @@ _beforeEach.givenModel = function(modelName, attrs, optionalHandler) { | ||
| beforeEach(function(done) { | ||
| if(modelName === '__USERMODEL__') { | ||
| modelName = this.userModel ? this.userModel : 'user'; | ||
| modelName = this.userModel ? this.userModel : 'User'; | ||
| modelKey = modelName; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to use the camelCase of Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure why camelCase would be better. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brijs | ||
| } | ||
| var test = this; | ||
| @@ -146,17 +147,18 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) { | ||
| } | ||
| _beforeEach.givenUser(attrs, function (done) { | ||
| var test = this; | ||
| test.app.models.Role.findOrCreate({name: role}, function (err, result) { | ||
| test.app.models.Role.findOrCreate(role, function (err, result) { | ||
| if(err) { | ||
| console.error(err.message); | ||
| if(err.details) console.error(err.details); | ||
| return done(err); | ||
| } | ||
| test.userRole = result; | ||
| test.app.models.roleMapping.create( | ||
| {principalId: test.user.id, | ||
| principalType: test.app.models.roleMapping.USER, | ||
| var userModelName = test.userModel ? test.userModel : 'User'; | ||
| test.app.models.RoleMapping.create( | ||
| {principalId: test[userModelName].id, | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should use | ||
| principalType: test.app.models.RoleMapping.USER, | ||
| roleId: result.id}, | ||
| function (err, result) { | ||
| if(err) { | ||
| @@ -194,7 +196,7 @@ _beforeEach.givenUserWithRole = function (attrs, role, optionalHandler) { | ||
| _beforeEach.givenLoggedInUser = function(credentials, optionalHandler) { | ||
| _beforeEach.givenUser(credentials, function(done) { | ||
| var test = this; | ||
| this.app.models[this.userModel].constructor.login(credentials, function(err, token) { | ||
| this.app.models[this.userModel].login(credentials, function(err, token) { | ||
| if(err) { | ||
| done(err); | ||
| } else { | ||
| @@ -217,7 +219,7 @@ _beforeEach.givenLoggedInUser = function(credentials, optionalHandler) { | ||
| _beforeEach.givenLoggedInUserWithRole = function(credentials, role, optionalHandler){ | ||
| _beforeEach.givenUserWithRole(credentials, role, function(done) { | ||
| var test = this; | ||
| this.app.models[this.userModel].constructor.login(credentials, function(err, token) { | ||
| this.app.models[this.userModel].login(credentials, function(err, token) { | ||
| if(err) { | ||
| done(err); | ||
| } else { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use
loopback.getModelByType(Loopback.User)to lookup the actual user model.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clarkorz can you please clarify further. In this case we are interested in simply getting the name(ie string, to use as a key to lookup subsequently) of the
Usermodel, and don't really need the actual Model or the Type.