Skip to content

Commit

Permalink
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_es6c
Browse files Browse the repository at this point in the history
 into webapp_interface
  • Loading branch information
marco-qg committed Apr 29, 2024
2 parents 43ce04f + b10c335 commit 4fe11ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
22 changes: 6 additions & 16 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,20 @@ const AddUser = () => {
setError('Las contraseñas no coinciden.');
} else {
try {
const isAvailable = await checkUsernameAvailability(username, password);
if (isAvailable != false) {
try {
await axios.post(`${apiEndpoint}/login`, { username, password });
setError('Usuario ya registrado.');
return;
setOpenSnackbar(false);
} catch (error) {
await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
}

await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
}
}
};

const checkUsernameAvailability = async (username, password) => {
try {
const response = await axios.post(`${apiEndpoint}/check-username`, { username });
return response.data;
} catch (error) {
console.error("Error al comprobar la disponibilidad del nombre de usuario:", error);
return false;
}
}

const handleCloseSnackbar = () => {
setOpenSnackbar(false);
};
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('AddUser component', () => {
const usernameInput = screen.getByLabelText(/Usuario/i);
const passwordInput = screen.getAllByLabelText(/Contraseña/i)[0];
const confirmPasswordInput = screen.getByLabelText(/Repetir contraseña/i);
const addUserButton = document.getElementsByClassName('inner')[0]
const addUserButton = document.getElementsByClassName('inner')[0];

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);
Expand All @@ -38,6 +38,14 @@ describe('AddUser component', () => {
await waitFor(() => {
expect(screen.getByText(/Usuario añadido correctamente/i)).toBeInTheDocument();
});

/*
fireEvent.click(addUserButton);
// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Usuario ya registrado./i)).toBeInTheDocument();
});
*/
});

it('try to add user but not introduce name', async () => {
Expand Down
4 changes: 1 addition & 3 deletions webapp/src/components/game/GameConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ const GameConfiguration = () => {
console.log(numPreguntas);
console.log(numRes);

await generateGameId();
gameId = await generateGameId();
await getQuestions();
//isApiCalledRef = true//ASK - is this necessary?
navigation("/firstGame", {state: {questions, gameId}})
}

gameId = generateGameId();

function formatearTopics() {
let topicsFormated = '';

Expand Down

0 comments on commit 4fe11ff

Please sign in to comment.