Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arreglado error de duplicación al agregar amigo #138

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading