-
Notifications
You must be signed in to change notification settings - Fork 20
Allow another name convention for User model and AccessToken model #26
base: master
Are you sure you want to change the base?
Allow another name convention for User model and AccessToken model #26
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
@ritch could you please review and land? I did a superficial review and did not find any issues, but you know the code better than I do. |
ok to test |
helpers.beforeEach.withApp(testApp, { userModel: Account }); | ||
helpers.beforeEach.givenUser({ email: '[email protected]', password: '000000' }); | ||
it('should create an user of Account type', function () { | ||
assert(this['account'] instanceof Account); |
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.
nitpick: this.account
@clarkorz, can you recommit and make @ritch merge into master. I have same problem. thanks! |
@ritch I have switched to a more simpler approach. Could you review again? |
@@ -207,11 +213,11 @@ _beforeEach.givenLoggedInUserWithRole = function(credentials, role, optionalHand | |||
} | |||
|
|||
_beforeEach.givenAnUnauthenticatedToken = function(attrs, optionalHandler) { | |||
_beforeEach.givenModel('accessToken', attrs, optionalHandler); | |||
_beforeEach.givenModel('AccessToken', attrs, optionalHandler); |
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.
Shouldn't it be options.AccessToken?
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.
@justin-lau this
doesn't point to the test object. 'AccessToken'
is the key of options
, it will be use to retrieve the configured model name in _beforeEach#givenModel()
.
Could someone resolve this please? I use a different naming convention for the model overrides in my application. |
If project doesn't extend built-in models **User** and **AccessToken** as **user** and **accessToken**, `givenModel()` can NOT find these models by keys `user` and `accessToken` via `app.models[key]`. By capitalizing the keys, `givenModel()` can always find the proper built-in model. Note: When `user` model extends `User` model, it will register both `user` and `User` to `app.models`. Signed-off-by: Clark Wang <[email protected]> Allow to specify user and accessToken models Add an options param to `lt.beforeEach.withApp()`, allow to specify the user model and/or accessToken model that will be used in the tests. Signed-off-by: Clark Wang <[email protected]> refactor according to @ritch's notes Signed-off-by: Clark Wang <[email protected]> use a simple approach Signed-off-by: Clark Wang <[email protected]> remove unused dep Signed-off-by: Clark Wang <[email protected]> pass tests Signed-off-by: Clark Wang <[email protected]> fix missing dep upgrade to use lodash string util methods Signed-off-by: Clark Wang <[email protected]>
8a472d8
to
63a1727
Compare
@ritch could you please review and land? |
roleMapping is also referenced by name on line 141 and 143. It would be nice if the model names loopback-testing uses could be overridden at runtime when importing the module. I might fork this later and implement something like that to get this working for me without needing the extra model extensions. |
See #57 for a potential fix for this. |
If project doesn't extend built-in models User and
AccessToken as user and accessToken,
givenModel()
can NOT find these models by keys
user
andaccessToken
viaapp.models[key]
.By classify the modelName,
givenModel()
can always find theproper built-in model.
Note: When
user
model extendsUser
model, it will registerboth
user
andUser
toapp.models
.FYI: This doesn't fix the case of extending User model withother name (e.g. Account), and AccessToken also.
Signed-off-by: Clark Wang [email protected]