"ember-cli-simple-auth-testing": "0.8.0",
Hi I have a protected route under which all routes that needs authentication is nested.
On authentication I populate current user to get extra information of current user like rights.
_populateCurrentUser(){
var self = this;
const user_id = this.get('session.secure.user.id');
const user_type = userType(parseInt(self.get('session.secure.user.type')));
return self.store.find(user_type,user_id).then(function(user){
self.set('session.currentUser',user);
if(Ember.isEmpty(user)){
self.transitionTo('login');
}
},function(err){
console.log("There was some error getting currentUser"+err);
});
}
I call the above _populateCurrentUser() in before model of protected route.
beforeModel(transition,queryParams) {
var self = this;
self._super(transition,queryParams);
if (self.session.isAuthenticated) {
return this._populateCurrentUser();
}
},
for testing purpose I need to populate the session.secure.user.id
test('I can create a story',function(assert){
var user = server.create('writer');
var sessionWriter = {
secure: {
user:{
id: 1,
type: 'writer'
}
}
};
authenticateSession(this.application,sessionWriter);
The above authenticateSession does not add the session sessionWriter and hence my _populateCurrentUser() fails as self.get('session.secure.user....
is empty.
Aucun commentaire:
Enregistrer un commentaire