2016-08-11 31 views
0

我正在編寫一個非常基本的驗收測試,該測試針對具有管理員權限和非管理員權限的路由。我的測試表明,如果我第一次來到應用程序,我沒有看到登錄功能。在我的應用程序,我使用password認證如下:無法使用Emberfire模擬會話

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

在後餘燼仔細一看,replaceFirebaseAppService試圖當它被我的應用程序註冊爲torii-adapter:application更換註冊的牌坊適配器在torii-adapter:firebase

我最終什麼事做在我自己的助手已基本複製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 helper 
import { stubValidSession } from 'app/tests/helpers/torii'; 

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

希望,節省了別人一些時間。