text: import configureMockStore from 'redux-mock-store';
  import thunk from 'redux-thunk';
  import {
    startAddExpense,
    addExpense,
    editExpense,
    removeExpense,
    setExpenses,
    startSetExpenses,
    startRemoveExpense,
    startEditExpense,
  } from '../../actions/expenses';
  import expenses from '../fixtures/expenses';
  import database from '../../firebase/firebase';
  
  const uid = 'testUid';
  const defaultAuthState = {
    auth: {
      uid,
    },
  };
  const createMockStore = configureMockStore([thunk]);
  
  beforeEach((done) => {
    const expensesData = {};
  
    expenses.forEach(({ id, description, note, amount, createAt }) => {
      expensesData[id] = {
        description,
        note,
        amount,
        createAt,
      };
    });
    database
      .ref(`users/${uid}/expenses`)
      .set(expensesData)
      .then(() => {
        done();
      });
  });
  
  test('should setup add expense action object with parameters', () => {
    const action = addExpense(expenses[2]);
    expect(action).toEqual({
      type: 'ADD_EXPENSE',
      expense: expenses[2],
    });
  });
  
  it('should add expense to database and store', (done) => {
    const store = createMockStore(defaultAuthState);
    const expenseData = {
      description: 'Mouse',
      amount: 3000,
      note: 'hello',
      createAt: 1000,
    };
    store
      .dispatch(startAddExpense(expenseData))
      .then(() => {
        const actions = store.getActions();
        expect(actions[0]).toEqual({
          type: 'ADD_EXPENSE',
          expense: {
            id: expect.any(String),
            ...expenseData,
          },
        });
  
        return database.ref(`users/${uid}/expenses/${actions[0].expense.id}`).once('value');
      })
      .then((snapshot) => {
        expect(snapshot.val()).toEqual(expenseData);
        done();
      });
  });
  
  it('should add expense to database and store with default parameters', (done) => {
    const store = createMockStore(defaultAuthState);
    const expenseDefault = { description: '', note: '', amount: 0, createAt: 0 };
  
    store
      .dispatch(startAddExpense())
      .then(() => {
        const actions = store.getActions();
        expect(actions[0]).toEqual({
          type: 'ADD_EXPENSE',
          expense: {
            id: expect.any(String),
            ...expenseDefault,
          },
        });
  
        return database.ref(`users/${uid}/expenses/${actions[0].expense.id}`).once('value');
      })
      .then((snapshot) => {
        expect(snapshot.val()).toEqual(expenseDefault);
        done();
      });
  });
  
  test('should setup remove expense action object', () => {
    const action = removeExpense('123abc');
    expect(action).toEqual({
      type: 'REMOVE_EXPENSE',
      id: '123abc',
    });
  });
  
  test('should remove expense from firebase database', (done) => {
    const store = createMockStore(defaultAuthState);
    const id = expenses[0].id;
    store
      .dispatch(startRemoveExpense({ id }))
      .then(() => {
        const actions = store.getActions();
        expect(actions[0]).toEqual({
          type: 'REMOVE_EXPENSE',
          id,
        });
  
        return database.ref(`users/${uid}/expenses/${id}`).once('value');
      })
      .then((snapshot) => {
        expect(snapshot.val()).toBeFalsy();
        done();
      });
  });
  
  test('should setup edit expense action object', () => {
    const action = editExpense({ id: '123abc' }, { note: 'note123' });
    expect(action).toEqual({
      type: 'EDIT_EXPENSE',
      id: '123abc',
      updates: {
        note: 'note123',
      },
    });
  });
  
  test('should edit expense from firebase database', (done) => {
    const store = createMockStore(defaultAuthState);
    const id = expenses[0].id;
    const updates = {
      description: 'New description!',
    };
    store
      .dispatch(startEditExpense({ id }, updates))
      .then(() => {
        const actions = store.getActions();
        expect(actions[0]).toEqual({
          type: 'EDIT_EXPENSE',
          id,
          updates,
        });
  
        return database.ref(`users/${uid}/expenses/${id}`).once('value');
      })
      .then((snapshot) => {
        expect(snapshot.val().description).toBe(updates.description);
        done();
      });
  });
  
  test('should setup set expense action object with data', () => {
    const action = setExpenses(expenses);
    expect(action).toEqual({
      type: 'SET_EXPENSES',
      expenses,
    });
  });
  
  test('should fetch the expenses from firebase', (done) => {
    const store = createMockStore(defaultAuthState);
    store.dispatch(startSetExpenses()).then(() => {
      const actions = store.getActions();
      expect(actions[0]).toEqual({
        type: 'SET_EXPENSES',
        expenses,
      });
      done();
    });
  });
  