Skip to content

Commit

Permalink
Tests de stats fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 16, 2024
1 parent a4350d6 commit b7827bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion statsservice/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 15 additions & 13 deletions statsservice/stats-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});

Expand All @@ -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);
});
});

0 comments on commit b7827bc

Please sign in to comment.