jest.unmock('./../ticket');

import axios from 'axios';
import moment from 'moment';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import AxiosMockAdapter from 'axios-mock-adapter';
import * as ticketActions from './../ticket';
import * as ticketTypes from './../../constants/ticket';
import {initialState} from './../../reducers/ticket';
import {getAPIUrl} from './../../../utilities/api';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('ticket actions', () => {
    it('should return action to add ticket', () => {
        const text = 'Super ticket';
        const expectedAction = {
            type: ticketTypes.ADD,
            payload: text
        }

        expect(ticketActions.addTicket(text)).toEqual(expectedAction);
    });

    it('should return action to update ticket', () => {
        const myTicket = {
            id: 3,
            title: 'Super Ticket 2.0'
        };

        const expectedAction = {
            type: ticketTypes.UPDATE,
            payload: myTicket
        }

        expect(ticketActions.updateTicket(myTicket)).toEqual(expectedAction);
    });

    it('should return action to delete ticket', () => {
        const ticketId = 47234;
        const expectedAction = {
            type: ticketTypes.DELETE,
            payload: ticketId
        }

        expect(ticketActions.deleteTicket(ticketId)).toEqual(expectedAction);
    });

    describe('fetchTickets async action', () => {
        it('should return actions fetch pending and fulfilled', () => {
            const store = mockStore({
                tickets: initialState
            });

            const response = {
                data: {
                    tickets: [{
                        id: 1,
                        title: 'My Super Ticket'
                    }]
                }
            };

            const axiosAdapter = new AxiosMockAdapter(axios);

            axiosAdapter.onGet(getAPIUrl('/tickets')).reply(200, response);

            const now = moment();
            const nowThunk = () => now;

            const expectedActions = [{
                type: ticketTypes.FETCH_PENDING
            },{
                type: ticketTypes.FETCH_FULFILLED,
                payload: response,
                fetchedAt: nowThunk()
            }];

            return store.dispatch(
                ticketActions.fetchTickets({}, nowThunk)
            ).then(() => {
                expect(store.getActions()).toEqual(expectedActions);
            });
        });

        it('should return actions fetch pending and rejected', () => {
            const store = mockStore({
                tickets: initialState
            });

            const axiosAdapter = new AxiosMockAdapter(axios);

            axiosAdapter.onGet(getAPIUrl('/tickets')).reply(500, {});

            const expectedActions = [{
                type: ticketTypes.FETCH_PENDING
            },{
                type: ticketTypes.FETCH_REJECTED,
                payload: {}
            }];

            return store.dispatch(
                ticketActions.fetchTickets({}, () => null)
            ).catch(() => {
                expect(store.getActions()).toEqual(expectedActions);
            });
        });
    });

});

@@ -1702,36 +1702,8 @@
 = %7B%0A
-                data: %7B%0A    
     
@@ -1750,23 +1750,15 @@
     
- 
-   
 id: 1,%0A
-    
     
@@ -1818,32 +1818,10 @@
     
-    %7D%5D%0A                
 %7D
+%5D
 %0A   
@@ -2426,32 +2426,53 @@
          expect(
+%0A                    
 store.getActions
@@ -2465,32 +2465,49 @@
 ore.getActions()
+%0A                
 ).toEqual(expect
@@ -3242,32 +3242,32 @@
             %7D);%0A
-
         %7D);%0A    
@@ -3257,24 +3257,559 @@
 %0A        %7D);
+%0A%0A        it('should not return any action', () =%3E %7B%0A            const store = mockStore(%7B%0A                tickets: %7B%0A                    ...initialState,%0A                    isFetching: true%0A                %7D%0A            %7D);%0A            %0A            const expectedActions = %5B%5D;%0A%0A            return store.dispatch(%0A                ticketActions.fetchTickets(%7B%7D, () =%3E null)%0A            ).catch(() =%3E %7B%0A                expect(%0A                    store.getActions()%0A                ).toEqual(expectedActions);%0A            %7D);%0A        %7D)
 %0A    %7D);%0A%0A%7D)

Add new ticket action test and fix axios adapter response