Skip to content

Instantly share code, notes, and snippets.

@kocur4d
Created July 24, 2018 10:50
Show Gist options
  • Select an option

  • Save kocur4d/8a527f550e3cd1cd3344258814e14553 to your computer and use it in GitHub Desktop.

Select an option

Save kocur4d/8a527f550e3cd1cd3344258814e14553 to your computer and use it in GitHub Desktop.

Revisions

  1. kocur4d created this gist Jul 24, 2018.
    60 changes: 60 additions & 0 deletions saga_test.js
    Original 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 },
    ])
    })
    })