Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jindaxz committed Feb 4, 2025
1 parent ff1e16b commit d01d0a5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/actions/__tests__/authActions.js.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import httpService from '../../services/httpService';
import { loginUser } from '../authActions';
import { SET_CURRENT_USER, GET_ERRORS } from '../../constants/auth';
import jwtDecode from 'jwt-decode';

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

jest.mock('jwt-decode', () => jest.fn());

jest.mock('../../services/httpService');

describe('authActions', () => {
it('creates SET_CURRENT_USER when loginUser is successful', async () => {
const store = mockStore({});
const credentials = { email: '[email protected]', password: 'password' };
const token = 'fake-jwt-token';
const decodedToken = { id: '123' };
httpService.post.mockResolvedValue({ data: { token } });
jwtDecode.mockReturnValue(decodedToken);

const expectedActions = [
{ type: SET_CURRENT_USER, payload: decodedToken },
];

await store.dispatch(loginUser(credentials));
expect(store.getActions()).toEqual(expectedActions);
});

});

0 comments on commit d01d0a5

Please sign in to comment.