Closed digitalplaywright closed 10 years ago
Can you provide a backtrace?
Also you should just run the normal Ember.SimpleAuth.setup
with the correct store configuration - there should also be no need for the invalidate
etc.
So I followed your recommendation and set store in Ember.SimpleAuth.setup in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/app/initializers/auth.js
var attribtues = {
crossOriginWhitelist: [window.ENV.server],
routeAfterLogin: "index",
routeAfterLogout: "login"
};
if(Ember.testing == true){
var attributes = Ember.merge({store: Ember.SimpleAuth.Stores.Ephemeral });
}
Em.SimpleAuth.setup(container, application,attributes);
return Em.SimpleAuth.Authenticators.OAuth2.reopen({
serverTokenEndpoint: window.ENV.server + "/oauth/token"
});
The error above went away, but there an error is still remaining so I can't know if it is a full fix before that one is fixed.
The other error is triggered in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js on
var session = app.__container__.lookup('ember-simple-auth:session');
return session.authenticate('authenticator:application', {
email: userPayload.email,
accessToken: userPayload.accessToken,
}).then(wait);
I am getting another error 'TypeError: Cannot call method 'authenticate' of undefined' with the stack trace (does not look that useful):
at Test.QUnitAdapter.Test.Adapter.extend.exception (http://localhost:8000/vendor/ember/ember.js:42781:5)
at superWrapper [as exception] (http://localhost:8000/vendor/ember/ember.js:1292:16)
at Ember.RSVP.onerrorDefault (http://localhost:8000/vendor/ember/ember.js:17180:28)
at Object.__exports__.default.trigger (http://localhost:8000/vendor/ember/ember.js:8977:13)
at Promise._onerror (http://localhost:8000/vendor/ember/ember.js:9701:16)
at publishRejection (http://localhost:8000/vendor/ember/ember.js:10108:17)
at http://localhost:8000/vendor/ember/ember.js:18379:7
at Object.DeferredActionQueues.flush (http://localhost:8000/vendor/ember/ember.js:6127:24)
This is starting to look like a user error on my part, but the lookup above on session works in developer mode in the browser so any tips you have on how to fix this is very helpful. Am I missing a dependency in testing? Should this lookup not work in testing?
That means that nothing is registered for 'authenticator:application'
. Probably you're not registering that in the test env?
As far as I know I am registering the same in testing as production, because I am using the same initializers. However, maybe there is a problem in the way I call authenticate to begin with. Is there a recommended way to authenticate through a method call in testing?
What I am doing in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js is not very pretty
function signInUser(app, userPayload) {
userPayload = $.extend({
email: 'test_user@example.com',
accessToken: 'please',
}, userPayload || {});
var session = app.__container__.lookup('ember-simple-auth:session');
return session.authenticate('authenticator:application', {
email: userPayload.email,
accessToken: userPayload.accessToken,
})
}
The recommended way would be to trigger your route action with valid credentials (e.g. LoginControllerMixin
's authenticate
action) and stub the server response.
Do you know of an example showing how to do this? I know of several developers that are having trouble with this particular aspect so I don't know where to get help and I am yet to bridge the gap to a working example test using mocking with ember simple auth.
Have a look at this for example: https://github.com/ugisozols/ember-simple-auth-rails-demo/blob/master/test/javascripts/integration/login_test.js. When you stub the server response and wrap that in a test helper you probably have what you are looking for.
I'm closing this as it doesn't seem to be an issues with Ember.SimpleAuth. Please ask further questions on stack overflow.com so this is only used for issues.
I submitted a question on the subject here:
There was no ember-simple-auth tag so I am not sure how to notify you of this question other than commenting here.
As recommended I am trying to use the Ephemeral storage during testing to make sure that there is no conflict between a non-testing and testing session, and to mock API calls. However, I get this error:
when setEphemeralSessionStore is called on https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/acceptance/login-test.js#L6
where setEphemeralSessionStore is defined in https://github.com/digitalplaywright/eak-simple-auth/blob/testing-experiment/tests/helpers/signin.js#L17
Can you see if there is a bug or if I am doing something wrong?