Skip to content

Commit

Permalink
No van los tests de stats y groupdetails
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 16, 2024
1 parent b7827bc commit 38f054d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 81 deletions.
6 changes: 3 additions & 3 deletions statsservice/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ app.post("/saveGame", async (req, res) => {
);
}

res.json({ message: "Partida guardada exitosamente" });
res.status(200).json({ message: "Partida guardada exitosamente" });
}
} catch (error) {
res.status(400).json({ error: "Error al guardar juego" + error.message });
Expand All @@ -99,7 +99,7 @@ app.get("/stats", async (req, res) => {
if (!data) {
res.status(400).json({ error: "User not found" });
} else {
res.json(data);
res.status(200).json(data);
}
} catch (error) {
res
Expand All @@ -126,7 +126,7 @@ app.get("/ranking", async (req, res) => {
throw new Error("No se encontraron estadísticas");
}

res.json(data);
res.status(200).json(data);
} catch (error) {
res
.status(400)
Expand Down
26 changes: 13 additions & 13 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ app.post("/adduser", async (req, res) => {
expiresIn: "1h",
});

res.json({
res.status(200).json({
username: newUser.username,
createdAt: newUser.createdAt,
token: token,
Expand All @@ -93,7 +93,7 @@ app.post("/adduser", async (req, res) => {
app.get("/users", async (req, res) => {
try {
const users = await User.find();
res.json(users);
res.status(200).json(users);
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand All @@ -117,7 +117,7 @@ app.get("/users/search", async (req, res) => {
username: { $ne: un, $nin: currentUserFriends },
});

res.json(users);
res.status(200).json(users);
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand All @@ -143,7 +143,7 @@ app.post("/users/add-friend", async (req, res) => {
user.friends.push(friendUsername);
await user.save();

res.json({ message: "Friend added successfully" });
res.status(200).json({ message: "Friend added successfully" });
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand Down Expand Up @@ -171,7 +171,7 @@ app.post("/users/remove-friend", async (req, res) => {
user.friends = user.friends.filter((friend) => friend !== friendUsername);
await user.save();

res.json({ message: "Friend removed successfully" });
res.status(200).json({ message: "Friend removed successfully" });
} catch (error) {
console.error("Error removing friend:", error);
res.status(500).json({ error: "Internal Server Error" });
Expand All @@ -189,7 +189,7 @@ app.get("/friends", async (req, res) => {
return res.status(404).json({ error: "User not found" });
}
// Devuelve la lista de amigos
res.json({ friends: user.friends });
res.status(200).json({ friends: user.friends });
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand All @@ -202,7 +202,7 @@ app.get("/userInfo", async (req, res) => {
{ username: username },
{ username: 1, createdAt: 1, games: 1 }
);
res.json(user);
res.status(200).json(user);
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand All @@ -220,7 +220,7 @@ app.get("/userGames", async (req, res) => {
if (!user) {
return res.status(404).json({ error: "Usuario no encontrado" });
}
res.json(user.games);
res.status(200).json(user.games);
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand All @@ -244,7 +244,7 @@ app.post("/saveGameList", async (req, res) => {

await user.save();

res.json({ message: "Partida guardada exitosamente" });
res.status(200).json({ message: "Partida guardada exitosamente" });
} catch (error) {
res.status(400).json({ error: "Error al guardar partida en la lista: " + error.message });
}
Expand All @@ -253,7 +253,7 @@ app.post("/saveGameList", async (req, res) => {
app.get('/group/list', async (req, res) => {
try {
const allGroups = await Group.find();
res.json({ groups: allGroups });
res.status(200).json({ groups: allGroups });
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
Expand All @@ -269,7 +269,7 @@ app.get('/group/:groupName', async (req, res) => {
return res.status(404).json({ error: 'Group not found' });
}

res.json({ group });
res.status(200).json({ group });
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand Down Expand Up @@ -301,7 +301,7 @@ app.post('/group/add', async (req, res) => {
createdAt:Date.now() });
await newGroup.save();

res.json({ message: 'Group created successfully' });
res.status(200).json({ message: 'Group created successfully' });
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand Down Expand Up @@ -330,7 +330,7 @@ app.post('/group/join', async (req, res) => {
group.members.push(username);
await group.save();

res.json({ message: 'User joined the group successfully' });
res.status(200).json({ message: 'User joined the group successfully' });
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand Down
4 changes: 1 addition & 3 deletions webapp/src/pages/Ranking/Ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const Ranking = () => {
fetch(gatewayUrl + `/ranking?gamemode=${gamemode}&filterBy=${filterBy}`)
.then((response) => response.json())
.then((data) => {
if (!data.ok) {
throw new Error(data.message || "Ha ocurrido un error");
}

setRanking(data);
setIsLoading(false);
})
Expand Down
10 changes: 4 additions & 6 deletions webapp/src/pages/Social/GroupDetails.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { useParams } from "react-router-dom";
import {
Container,
Box,
Expand All @@ -19,7 +19,6 @@ import Nav from "../../components/Nav/Nav.js";
import Footer from "../../components/Footer/Footer.js";
import { useTranslation } from "react-i18next";
import Perfil from "../../components/Profile/Profile.js";
import { set } from "date-fns";

const GroupDetails = () => {
const { t } = useTranslation();
Expand All @@ -29,7 +28,6 @@ const GroupDetails = () => {
const { groupName } = useParams();
const apiEndpoint =
process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000";
const navigate = useNavigate();

useEffect(() => {
fetchGroupDetails();
Expand All @@ -41,9 +39,9 @@ const GroupDetails = () => {
const response = await fetch(
`${apiEndpoint}/group/${encodeURIComponent(groupName)}`
);
if (!response.ok) {
throw new Error("Network response was not ok");
}
// if (!response.status === 200) {
// throw new Error("Network response was not ok");
// }
const data = await response.json();
setGroup(data.group);
setError(null);
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const Stats = () => {

const fetchStats = (mode) => {
setIsLoading(true);
fetch(gatewayUrl + `/stats?user=${username}&gamemode=${mode}`)
fetch(gatewayUrl + `/stats?username=${username}&gamemode=${mode}`)
.then((response) => response.json())
.then((data) => {
if (!data.ok) {
console.log(data);
if (!data._id) {
throw new Error(data.message || "Ha ocurrido un error");
}
setStats(data);
Expand Down Expand Up @@ -152,6 +153,7 @@ const Stats = () => {
{t("pages.stats.wisebattery")}
</Button>
<Button
data-testid="calculator-button"
className={gamemode === "calculadora" ? "active" : ""}
onClick={() => handleGamemodeChange("calculadora")}
>
Expand Down
Loading

0 comments on commit 38f054d

Please sign in to comment.