This repository was 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
givenLoggedInUser() function throws error #59
Copy link
Copy link
Open
Description
I am trying to use loopback-testing to test an API end-point that requires an auth token. When I try to use the provided API:
var lt = require('loopback-testing');
var app = require('../../../server/server.js');
describe('Test', function(){
lt.beforeEach.withApp(app);
lt.beforeEach.givenLoggedInUser({email:"[email protected]",password:"test"});
I get this error:
AssertionError: cannot get model of name user from app.models
Expected :true
Actual :[undefined]
I believe it's because the code is trying to access app.models['user'] instead of app.models['User']:
)
I already have a test auth token I auto-generate during server bootup. So I have worked around the issue by creating a new function in helpers.js:
_beforeEach.withAuthToken = function(authTokenId) {
var authToken = { id: authTokenId };
beforeEach(function() {
this.loggedInAccessToken = authToken;
});
}
And I can call it like this instead:
var lt = require('loopback-testing');
var app = require('../../../server/server.js');
describe('Test', function(){
lt.beforeEach.withApp(app);
lt.beforeEach.withAuthToken("{some auth token}");
This resolved the issue for me but this is just a work-around and I don't understand the library well enough yet to know what the appropriate fix is.
Thanks for the help
Metadata
Metadata
Assignees
Labels
No labels