This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
3 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ describe('helpers', function () { | |
it('should have an xxx-test-model property', function () { | ||
assert(this['xxx-test-model']); | ||
assert(this['xxx-test-model'].id); | ||
assert(this['xxx-test-model'] instanceof testModel); | ||
}); | ||
}); | ||
|
||
|
@@ -109,4 +110,42 @@ describe('helpers', function () { | |
}); | ||
}); | ||
}); | ||
|
||
describe('helpers.beforeEach.givenUser', function() { | ||
describe('with default user model', function() { | ||
testApp.model(loopback.User, {dataSource: 'db'}); | ||
helpers.beforeEach.givenUser({ email: '[email protected]', password: '000000' }); | ||
it('should create an user of User type', function () { | ||
assert(this['user'] instanceof loopback.User); | ||
}); | ||
}); | ||
describe('with custom User model', function() { | ||
var Account = loopback.User.extend('Account'); | ||
testApp.model(Account, {dataSource: 'db'}); | ||
helpers.beforeEach.withApp(testApp, { User: 'Account' }); | ||
helpers.beforeEach.givenUser({ email: '[email protected]', password: '000000' }); | ||
it('should create an user of Account type', function () { | ||
assert(this.user instanceof Account); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('helpers.beforeEach.givenAnUnauthenticatedToken', function() { | ||
describe('with default AccessToken model', function() { | ||
testApp.model(loopback.AccessToken, {dataSource: 'db'}); | ||
helpers.beforeEach.givenAnUnauthenticatedToken({}); | ||
it('should create an accessToken of AccessToken type', function () { | ||
assert(this.accessToken instanceof loopback.AccessToken); | ||
}); | ||
}); | ||
describe('with custom AccessToken model', function() { | ||
var Token = loopback.AccessToken.extend('Token'); | ||
testApp.model(Token, {dataSource: 'db'}); | ||
helpers.beforeEach.withApp(testApp, { AccessToken: 'Token' }); | ||
helpers.beforeEach.givenAnUnauthenticatedToken({}); | ||
it('should create an accessToken of Token type', function () { | ||
assert(this.accessToken instanceof Token); | ||
}); | ||
}); | ||
}); | ||
}); |