import applicationReducer from './application';
import { Constants as ApplicationConstants } from '../actions/application';

describe('application reducer', () => {
  const initialState = () => ({ matchingUsers: [], currentPage: 1 });

  describe('initial state', () => {
    it('returns empty state', () => {
      const state = applicationReducer(initialState, {});

      expect(state).toEqual(initialState);
    });
  });

  describe('SEARCH_FOR_ACCOUNT_USERS', () => {
    it('updates the currentPage', () => {
      const page = 2;
      const action = {
        type: ApplicationConstants.SEARCH_FOR_ACCOUNT_USERS,
        params: { page }
      };

      const state = applicationReducer(initialState, action);

      expect(state.currentPage).toEqual(page);
    });

    describe('when no page is given', () => {
      it('defaults the currentPage to 1', () => {
        const action = {
          type: ApplicationConstants.SEARCH_FOR_ACCOUNT_USERS,
          params: {}
        };

        const state = applicationReducer(initialState, action);

        expect(state.currentPage).toEqual(1);
      });
    });
  });

  describe('SEARCH_FOR_ACCOUNT_USERS_DONE', () => {
    it('updates matchingUsers', () => {
      const matchingUsers = [
        { id: 1, name: 'Student 1' },
        { id: 2, name: 'Student 2' },
        { id: 3, name: 'Student 3' },
      ];
      const action = {
        type: ApplicationConstants.SEARCH_FOR_ACCOUNT_USERS_DONE,
        payload: { matching_users: matchingUsers },
      };

      const state = applicationReducer(initialState, action);

      expect(state.matchingUsers).toEqual(matchingUsers);
    });

    it('updates previousPageAvailable', () => {
      const previousPageAvailable = true;
      const action = {
        type: ApplicationConstants.SEARCH_FOR_ACCOUNT_USERS_DONE,
        payload: { previous_page_available: previousPageAvailable },
      };

      const state = applicationReducer(initialState, action);

      expect(state.previousPageAvailable).toEqual(previousPageAvailable);
    });

    it('updates nextPage', () => {
      const nextPageAvailable = true;
      const action = {
        type: ApplicationConstants.SEARCH_FOR_ACCOUNT_USERS_DONE,
        payload: { next_page_available: nextPageAvailable },
      };

      const state = applicationReducer(initialState, action);

      expect(state.nextPageAvailable).toEqual(nextPageAvailable);
    });
  });
});

@@ -354,16 +354,18 @@
 ialState
+()
 , %7B%7D);%0A%0A
@@ -404,16 +404,18 @@
 ialState
+()
 );%0A    %7D
@@ -697,32 +697,34 @@
 cer(initialState
+()
 , action);%0A%0A    
@@ -1037,32 +1037,34 @@
 cer(initialState
+()
 , action);%0A%0A    
@@ -1569,32 +1569,34 @@
 cer(initialState
+()
 , action);%0A%0A    
@@ -1959,32 +1959,34 @@
 cer(initialState
+()
 , action);%0A%0A    
@@ -2348,16 +2348,18 @@
 ialState
+()
 , action

Fix bug in reducer test