export function performSearch(
  { api, auth = false, dispatch, filters, page, results }
) {
  if (!filters || !Object.values(filters).length) {
    return Promise.resolve();
  }

  dispatch(searchStart({ filters, page, results }));
  return search({ page, api, auth, filters })
    .then((response) => dispatch(searchLoad({ page, filters, ...response })))
    .catch(() => dispatch(searchFail({ page, filters })));
}
  it('does not pass search state if the filters and state do not match', () => {
    const store = createStore();
    store.dispatch(searchStart({ filters }));
    const mismatchedState = store.getState();
    mismatchedState.search.filters.clientApp = 'nothing';
    const props = mapStateToProps(mismatchedState, ownProps);

    assert.deepEqual(props, {
      hasSearchParams: true,
      pathname: '/themes/ad-block/',
      queryParams: { page: 1 },
    });
  });
describe('SEARCH_STARTED', () => {
  const action = actions.searchStart(
    { filters: { query: 'foo' }, page: 5, results: [] });

  it('sets the type', () => {
    assert.equal(action.type, 'SEARCH_STARTED');
  });

  it('sets the query and existing results', () => {
    assert.deepEqual(action.payload,
      { filters: { query: 'foo' }, page: 5, results: [] });
  });
});
  it('passes the search state if the filters and state matches', () => {
    const store = createStore();
    store.dispatch(searchStart({ filters, results: [] }));
    const props = mapStateToProps(store.getState(), ownProps);

    assert.deepEqual(props, {
      count: 0,
      filters,
      hasSearchParams: true,
      loading: true,
      page: undefined,
      pathname: '/themes/ad-block/',
      queryParams: { page: 1 },
      results: [],
    });
  });