Skip to content

Commit

Permalink
Merge pull request #138 from Arquisoft/fixes-friends
Browse files Browse the repository at this point in the history
Arreglado error de duplicación al agregar amigo
  • Loading branch information
iyanfdezz authored Apr 24, 2024
2 parents f69f88c + f4377d1 commit a806370
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 2 additions & 0 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ app.post("/adduser", async (req, res) => {
app.get("/users", async (req, res) => {
try {
const users = await User.find();
console.log(users);
res.status(200).json(users);
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
Expand Down Expand Up @@ -219,6 +220,7 @@ app.get("/friends", async (req, res) => {
}
// Devuelve la lista de amigos
res.status(200).json({ friends: user.friends });

} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand Down
17 changes: 7 additions & 10 deletions webapp/e2e/steps/add-friend.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ defineFeature(feature, (test) => {
});
let username;
let password;
let userCountBefore;
test("The user can add a friend", ({ given, when, then }) => {
given("A logged-in user and another user", async () => {
await expect(page).toClick("a", { text: "Regístrate" });
username="friend";
username="Friend";
password="Friend123";
await page.waitForSelector('#register-username');
await page.type('#register-username', username);
Expand Down Expand Up @@ -59,23 +60,19 @@ defineFeature(feature, (test) => {
//await page.waitForNavigation({ waitUntil: "networkidle0" });
await page.waitForTimeout(1000);

const userRowsBefore = await page.$$('[data-testid^="user-row-"]');
userCountBefore = userRowsBefore.length;

await page.waitForSelector('[data-testid^="add-friend-button-"]');
await page.click('[data-testid^="add-friend-button-"]');

});

then("The user should disappear from the Users page", async () => {
await page.waitForTimeout(1000);

const userRowsBefore = await page.$$('[data-testid^="user-row-"]');
const userCountBefore = userRowsBefore.length;

await page.waitForSelector('[data-testid^="add-friend-button-"]');
const addFriendButtons = await page.$$('[data-testid^="add-friend-button-"]');
await addFriendButtons[0].click();

await page.waitForTimeout(1000);

await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });

const userRowsAfter = await page.$$('[data-testid^="user-row-"]');
const userCountAfter = userRowsAfter.length;

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@
"home": "Back to Home"
},
"userspage": {
"list": "User List",
"list": "Application users",
"user": "User",
"actions": "Actions",
"friend": "Friend",
"friend": "Already friends",
"addFriend": "Add Friend",
"loading": "Loading users...",
"error": "Error loading users: "
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@
"home": "Volver al inicio"
},
"userspage": {
"list": "Lista de usuarios",
"list": "Usuarios de la aplicación",
"user": "Usuario",
"actions": "Acciones",
"friend": "Amigo",
"friend": "Ya sois amigos",
"addFriend": "Añadir amigo",
"loading": "Cargando usuarios ...",
"error": "Error al cargar los usuarios: "
Expand Down
4 changes: 0 additions & 4 deletions webapp/src/pages/Social/UsersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ const UsersPage = () => {
throw new Error("Error al agregar amigo");
}

// Agregar el usuario a la lista de amigos localmente
setUsers((prevFriends) => [...prevFriends, user]);
// Actualizar el estado de isFriend del usuario
setUsers((prevUsers) => {
return prevUsers.map((u) => {
if (u._id === user._id) {
Expand All @@ -116,7 +113,6 @@ const UsersPage = () => {
});
} catch (error) {
console.error("Error al agregar amigo:", error);
// Manejar el error según sea necesario
}
};

Expand Down

0 comments on commit a806370

Please sign in to comment.