无法与Emberfire进行模拟会话

时间:2016-08-11 23:50:07

标签: ember.js firebase emberfire

我正在针对具有管理和非管理功能的路线编写一个非常基本的验收测试。我的测试断言,如果我第一次来到应用程序,我就看不到登录的功能了。在我的应用程序中,我使用password身份验证,如下所示:

this.get('session').open('firebase', {
  provider: 'password',
  email: email,
  password: password
});

我发现当我未在应用程序中进行身份验证时,然后运行验收测试,它会通过。但是,如果我然后登录应用程序,然后运行测试,我的断言失败,因为会话恢复,当我认为它不应该。这是测试:

import { test } from 'qunit';
import moduleForAcceptance from 'app/tests/helpers/module-for-acceptance';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import replaceAppRef from '../helpers/replace-app-ref';
import replaceFirebaseAppService from '../helpers/replace-firebase-app-service';
import stubFirebase from '../helpers/stub-firebase';
import unstubFirebase from '../helpers/unstub-firebase';
import { emptyApplication } from '../helpers/create-test-ref';

moduleForAcceptance('Acceptance | index', {
  beforeEach: function() {
    stubFirebase();
    application = startApp();
    replaceFirebaseAppService(application, { });
    replaceAppRef(application, emptyApplication());
  },
  afterEach: function() {
    unstubFirebase();
    destroyApp(application);
  }
});

test('empty app - not authenticated', function(assert) {
  visit('/');
  andThen(function() {
    assert.equal(currentURL(), page.url, 'on the correct page');

    // this works if there's no session - fails otherwise
    assert.notOk(page.something.isVisible, 'cannot do something');
  });
});

我认为replaceFirebaseAppService应该覆盖torii-adapter,但它似乎并不存在。任何帮助将不胜感激。

我正在使用:

Ember      : 2.7.0
Ember Data : 2.7.0
Firebase   : 3.2.1
EmberFire  : 2.0.1
jQuery     : 2.2.4

1 个答案:

答案 0 :(得分:1)

在仔细观察Emberfire后,replaceFirebaseAppService正在尝试更换我的应用程序注册为torii-adapter:firebase时在torii-adapter:application注册的torii适配器。

我最终做的是基本上在我自己的帮手中复制replaceFirebaseAppService

import stubFirebase from '../helpers/stub-firebase';
import startApp from '../helpers/start-app';
import replaceAppRef from '../helpers/replace-app-ref';
import createOfflineRef from './create-offline-ref';

export default function startFirebaseApp(fixtures = { }) {
  stubFirebase();
  let application = startApp();

  // override default torii-adapter
  const mock = { };
  application.register('service:firebaseMock', mock, {
    instantiate: false,
    singleton: true
  });
  application.inject('torii-provider:application', 'firebaseApp', 'service:firebaseMock');
  application.inject('torii-adapter:application', 'firebaseApp', 'service:firebaseMock');

  // setup any fixture data and return instance
  replaceAppRef(application, createOfflineRef(fixtures));
  return application;
}

这可以防止torii适配器解析我使用我的应用程序时可能遇到的任何会话数据。然后我可以使用提供的torii助手来模拟我需要它的会话:

// torii helper
import { stubValidSession } from 'app/tests/helpers/torii';

// mock a valid session
stubValidSession(application, { });

希望能节省一些时间。