I'm trying to upgrade an Ember CLI app to use Simple Auth 1.0. My acceptance tests no longer work. I have configured the test suite to run against a Rails server which is a copy of my API. To log in I was doing this:
visit("/")
fillIn(".identification-field", "[email protected]");
fillIn(".password-field", "testpassword");
click(".btn.login-submit");
andThen(function(){
equal(currentSession(application).get('user_email'), "[email protected]");
});
This worked with simple-auth 0.7.3 but not with 1.0.0. I have added additional methods my application route to setup the session as follows:
_populateCurrentUser: function() {
var user_id = this.get('session.data.user_id');
var user_email = this.get('session.data.user_email');
var _this = this;
return this.store.find('user', user_id).then(function(user){
_this.get('currentUser').set('content', user);
// Below is for backward-compatibility
_this.get('session').set('currentUser', user);
_this.get('session').set('user_id', user_id);
_this.get('session').set('user_email', user_email);
user;
});
}
sessionAuthenticated: function(){
this._populateCurrentUser();
this._super();
}
beforeModel: function() {
if (this.get('session.isAuthenticated')) {
return this._populateCurrentUser();
}
}
This is based on the following guide: http://miguelcamba.com/blog/2015/06/18/how-to-inject-the-current-user-using-ember-simple-auth/
This works perfectly when I run the app but breaks my test suite. Now when I log in the session does not seem to be populated - The _populateCurrentUser method fails because this.get('session.data.user_id') is undefined.
Can anyone help with this? Perhaps it is due to the automatic use of the ephemeral session store in 1.0 but if so I am not sure how to get around this?
Many thanks
With Ember Simple Auth 1.0 the session data that the authenticator resolves with is stored in data.authenticated
so you'd need to change var user_id = this.get('session.data.user_id');
to var user_id = this.get('session.data.authenticated.user_id');
etc.