У меня с ошибкой завершается первый тесткейс, но приложение работает как надо, в чём проблема: import configureMockStore from 'redux-mock-store';
import { thunk } from 'redux-thunk';
import { loginThunk, LOGIN_SUCCESS, LOGIN_FAILURE } from '../actions';

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

global.fetch = jest.fn();

describe('Login Thunk', () => {
    afterEach(() => {
        fetch.mockClear();
    });

    it('dispatches LOGIN_SUCCESS when login is successful', async () => {
        fetch.mockResolvedValueOnce({
            status: 200,
            json: () => Promise.resolve({ accessToken: 'someAccessToken', refreshToken: 'someRefreshToken', username: 'validUser' })
        });
    
        const expectedActions = [{ type: LOGIN_SUCCESS, payload: 'validUser' }];
        const store = mockStore({});
    
        await store.dispatch(loginThunk('validUser', 'validPass'));
    
        expect(store.getActions()).toEqual(expectedActions);
    });
    

    it('dispatches LOGIN_FAILURE when login fails', async () => {
        fetch.mockResolvedValueOnce({
            status: 401,
            json: () =>
                Promise.resolve({ message: 'Invalid username or password' })
        });

        const expectedActions = [
            { type: LOGIN_FAILURE, payload: 'Invalid username or password' }
        ];
        const store = mockStore({});

        await store.dispatch(loginThunk('invalidUser', 'invalidPass'));

        expect(store.getActions()).toEqual(expectedActions);
    });

    it('dispatches LOGIN_FAILURE on network error', async () => {
        fetch.mockRejectedValueOnce(new Error('Network error'));

        const expectedActions = [
            { type: LOGIN_FAILURE, payload: 'Network error' }
        ];
        const store = mockStore({});

        await store.dispatch(loginThunk('user', 'pass'));

        expect(store.getActions()).toEqual(expectedActions);
    });
});
actions.js import { fetchWithAuth } from './api.js';

export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
export const FETCH_CARDS_SUCCESS = 'FETCH_CARDS_SUCCESS';
export const FETCH_CARDS_FAILURE = 'FETCH_CARDS_FAILURE';

export const loginSuccess = (username) => ({
    type: LOGIN_SUCCESS,
    payload: username
});

export const loginFailure = (error) => ({
    type: LOGIN_FAILURE,
    payload: error
});


export const loginThunk = (username, password) => {
    return async (dispatch) => {
        try {
            const response = await fetch('http://localhost:5000/login', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ username, password })
            });

            if (response.status === 200) {
                const data = await response.json();
                localStorage.setItem('accessToken', data.accessToken);
                localStorage.setItem('refreshToken', data.refreshToken);
                dispatch(loginSuccess(data.username));
            } else {
                const { message } = await response.json();
                dispatch(loginFailure(message));
            }
        } catch {
            dispatch(loginFailure('Network error'));
        }
    };
};
export const fetchCardsSuccess = (cards) => ({
    type: FETCH_CARDS_SUCCESS,
    payload: cards
});

export const fetchCardsFailure = (error) => ({
    type: FETCH_CARDS_FAILURE,
    payload: error
});

export const fetchCards = (searchTerm = '') => {
    return async (dispatch) => {
        try {
            const response = await fetchWithAuth(
                `http://localhost:5000/api/cards?search=${encodeURIComponent(searchTerm)}`
            );

            if (!response.ok) {
                throw new Error('Failed to fetch cards');
            }

            const data = await response.json();
            dispatch(fetchCardsSuccess(data));
        } catch (error) {
            console.error(error);
            dispatch(fetchCardsFailure(error.message));
        }
    };
};

export const logout = () => {
    return (dispatch) => {
        localStorage.removeItem('accessToken');
        localStorage.removeItem('refreshToken');
        localStorage.removeItem('username');
        dispatch({ type: 'LOGOUT' });
    };
}; loginpage.jsx import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { loginThunk } from '../../Redux/actions.js';
import logo from '../../../img/LogoSpring.svg';
import style from './AuthIn.module.css';

export const LoginPage = () => {
    const [username, setUsername] = useState('');
    const [password, setPassword] = useState('');
    const dispatch = useDispatch();
    const navigate = useNavigate();

    const handleSubmit = async (e) => {
        e.preventDefault();
        try {
            await dispatch(loginThunk(username, password));
            navigate('/');
        } catch (error) {
            console.error('Login error:', error);
            alert('Invalid username or password');
        }
    };

    return (
        <div className={style.form_login_wrapper}>
            <img
                className={style.header__logo}
                alt="Spring Framework Logo"
                src={logo}
            />
            <h1 className={style.form_title}>Welcome back!</h1>
            <form onSubmit={handleSubmit} className={style.form_login}>
                <input
                    className={style.form_login_input}
                    type="text"
                    placeholder="Username"
                    value={username}
                    onChange={(e) => setUsername(e.target.value)}
                />
                <input
                    className={style.form_login_input}
                    type="password"
                    placeholder="Password"
                    value={password}
                    onChange={(e) => setPassword(e.target.value)}
                />
                <button type="submit" className={style.form_button_submit}>
                    Login
                </button>
                <button onClick={() => navigate('/signup')} className={style.switch_form_button}>
                Сreate an account
            </button>
            </form>
        </div>
    );
};