From b7827bce0686994ccef2c599032d483f11e19d04 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Tue, 16 Apr 2024 17:00:16 +0200 Subject: [PATCH] Tests de stats fixed --- statsservice/stats-service.js | 2 +- statsservice/stats-service.test.js | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/statsservice/stats-service.js b/statsservice/stats-service.js index bb2cc557..a5756df9 100644 --- a/statsservice/stats-service.js +++ b/statsservice/stats-service.js @@ -93,7 +93,7 @@ app.post("/saveGame", async (req, res) => { app.get("/stats", async (req, res) => { try { var data = await Stats.findOne({ - username: req.query.user, + username: req.query.username, gamemode: req.query.gamemode, }); if (!data) { diff --git a/statsservice/stats-service.test.js b/statsservice/stats-service.test.js index b839ce27..12356f9a 100644 --- a/statsservice/stats-service.test.js +++ b/statsservice/stats-service.test.js @@ -15,8 +15,8 @@ const responseExample = { totalCorrectQuestions: 150, totalIncorrectQuestions: 50, ratioCorrect: 0.75, - avgTime: 45 -} + avgTime: 45, +}; async function addStat(responseExample) { const newStat = new Stats(responseExample); @@ -43,14 +43,15 @@ describe("Stats Service", () => { const response = await request(app).get( `/stats/?username=${username}&gamemode=exampleGamemode` ); + expect(response.status).toBe(200); - - expect(response.body).toHaveProperty("nGamesPlayed", 10) - expect(response.body).toHaveProperty("avgPoints", 75.5) - expect(response.body).toHaveProperty("totalPoints", 755) - expect(response.body).toHaveProperty("totalCorrectQuestions", 150) - expect(response.body).toHaveProperty("totalIncorrectQuestions", 50) - expect(response.body).toHaveProperty("ratioCorrect", 0.75) + + expect(response.body).toHaveProperty("nGamesPlayed", 10); + expect(response.body).toHaveProperty("avgPoints", 75.5); + expect(response.body).toHaveProperty("totalPoints", 755); + expect(response.body).toHaveProperty("totalCorrectQuestions", 150); + expect(response.body).toHaveProperty("totalIncorrectQuestions", 50); + expect(response.body).toHaveProperty("ratioCorrect", 0.75); expect(response.body).toHaveProperty("avgTime", 45); }); @@ -71,13 +72,14 @@ describe("Stats Service", () => { ); expect(response.status).toBe(400); - expect(response.body).toHaveProperty("error", "Error al obtener el ranking: No se encontraron estadísticas"); + expect(response.body).toHaveProperty( + "error", + "Error al obtener el ranking: No se encontraron estadísticas" + ); }); it("should return status 400 for incomplete game data", async () => { - const response = await request(app).get( - `/stats/?username=${username}` - ); + const response = await request(app).get(`/stats/?username=${username}`); expect(response.status).toBe(400); }); });