Ember 验收测试中的简单 Auth 1.0

Ember Simple Auth 1.0 in Acceptance Tests

我正在尝试升级 Ember CLI 应用程序以使用 Simple Auth 1.0。我的验收测试不再有效。我已将测试套件配置为 运行 针对 Rails 服务器,该服务器是我的 API 的副本。要登录,我是这样做的:

visit("/")
fillIn(".identification-field", "test@email.com");
fillIn(".password-field", "testpassword");
click(".btn.login-submit");

andThen(function(){
  equal(currentSession(application).get('user_email'), "test@email.com");
});

这适用于 simple-auth 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'); 等。