验收测试中的Ember Simple Auth 1.0

亚当

我正在尝试升级Ember CLI应用程序以使用简单身份验证1.0。我的验收测试不再起作用。我已将测试套件配置为可在Rails服务器上运行,该服务器是我的API的副本。要登录,我正在这样做:

visit("/")
fillIn(".identification-field", "[email protected]");
fillIn(".password-field", "testpassword");
click(".btn.login-submit");

andThen(function(){
  equal(currentSession(application).get('user_email'), "[email protected]");
});

这适用于简单身份验证0.7.3,但不适用于1.0.0。我在应用程序路由中添加了其他方法来设置会话,如下所示:

_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();
  }
}

这基于以下指南:http : //miguelcamba.com/blog/2015/06/18/how-to-inject-the-current-user-using-ember-simple-auth/

当我运行该应用程序但破坏了我的测试套件时,这可以完美工作。现在,当我登录会话时,似乎未填充会话-_populateCurrentUser方法失败,因为未定义this.get('session.data.user_id')。

有人能帮忙吗?也许是由于在1.0中自动使用了临时会话存储,但是如果是这样,我不确定如何解决这个问题?

非常感谢

马可

使用Ember Simple Auth 1.0时,身份验证者用来解析的会话数据存储在其中,data.authenticated因此您需要更改var user_id = this.get('session.data.user_id');var user_id = this.get('session.data.authenticated.user_id');etc。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章