Skip to content

Instantly share code, notes, and snippets.

@kocur4d
Created July 24, 2018 10:50
Show Gist options
  • Save kocur4d/8a527f550e3cd1cd3344258814e14553 to your computer and use it in GitHub Desktop.
Save kocur4d/8a527f550e3cd1cd3344258814e14553 to your computer and use it in GitHub Desktop.
// 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 },
])
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment