From d0242935af5503a259afdb4f651d9d6bfce4b6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz=20Cancillo?= Date: Sun, 28 Apr 2024 13:48:59 +0200 Subject: [PATCH] Otro intento --- webapp/src/components/Login.test.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/webapp/src/components/Login.test.js b/webapp/src/components/Login.test.js index 76f5ccb5..5ef10fef 100644 --- a/webapp/src/components/Login.test.js +++ b/webapp/src/components/Login.test.js @@ -24,6 +24,23 @@ describe('Login Component', () => { test('login with valid normal (not "admin") credentials', async () => { const setLogged = jest.fn(); + // Mock para la petición POST de login exitosa + axios.post.mockResolvedValueOnce({ + data: { + createdAt: new Date().toISOString() + } + }); + + // Mock para la petición GET de obtener todos los usuarios + axios.get.mockResolvedValueOnce({ + data: [] // Puedes ajustar esto según lo que necesites en tu test + }); + + // Mock para la petición POST de createUserRank exitosa + axios.post.mockResolvedValueOnce({ + data: {} // Puedes ajustar esto según lo que necesites en tu test + }); + await act(async () => { render(); }); @@ -36,13 +53,6 @@ describe('Login Component', () => { expect(usernameInput).toBeInTheDocument(); expect(passwordInput).toBeInTheDocument(); - // Mock the axios.post & axios.get requests to simulate successful responses - mockAxios.onPost('http://localhost:8000/login').reply(200, { data: { createdAt: '2024-01-01T12:34:56Z' }}); - mockAxios.onPost('http://localhost:8002/login').reply(200, { data: { createdAt: '2024-01-01T12:34:56Z' }}); - - mockAxios.onGet('http://localhost:8000/getAllUsers').reply(200, { data: []}); - mockAxios.onPost('http://localhost:8000/createUserRank').reply(200); - await act(async () => { // Simulate user input fireEvent.change(usernameInput, { target: { value: 'admin' } });