Created
July 24, 2018 10:50
-
-
Save kocur4d/8a527f550e3cd1cd3344258814e14553 to your computer and use it in GitHub Desktop.
Revisions
-
kocur4d created this gist
Jul 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ // SAGA export const disconnectPage = function*(pageId) { const accessToken = yield call(ensureAccessTokenSaga) const { success, data, error } = yield call(disconnectFacebookPage(pageId), accessToken) if(success === true) { yield put(dataRequest({ key: 'facebook_page_settings:pages', fetcher: fetchFacebookPages, })) } } //TEST import { disconnectPage } from './disconnectFacebookPage.js' import { runSaga } from 'redux-saga' import * as api from 'auth-actions' import * as credentials from '../../../../apis/credentials.js' import { DATA_REQUEST } from 'fetch-data-wrapper' let sandbox let stubbedFetchFacebookPages let dispatched = [] describe('fetchDataSaga', () => { const config = { dispatch: action => dispatched.push(action), getState: () => ({ state: 'test' }), } beforeEach(() => { sandbox = sinon.sandbox.create() stubbedFetchFacebookPages = sandbox.stub(credentials, 'fetchFacebookPages') sandbox.stub(api, 'ensureAccessTokenSaga').callsFake(() => '12345' ) sandbox.stub(credentials, 'disconnectFacebookPage').callsFake(() => () => ({ success: true, })) }) afterEach(() => { sandbox.restore() dispatched = [] }) it('dispatches correct actions on success', async () => { const params = { pageId: 'abcd' } await runSaga( config, disconnectPage, params, ).done expect(dispatched).to.eql([ { type: DATA_REQUEST, key: 'facebook_page_settings:pages', fetcher: stubbedFetchFacebookPages }, ]) }) })