From 2e5230ba79935a98879c8f294f3adde51ebc17bf Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 27 Apr 2024 15:49:04 +0200 Subject: [PATCH] Do some e2e tests for multiplayer --- src/test/java/com/uniovi/Wiq_UnitTests.java | 29 +++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/uniovi/Wiq_UnitTests.java b/src/test/java/com/uniovi/Wiq_UnitTests.java index a9ffdc02..7f285984 100644 --- a/src/test/java/com/uniovi/Wiq_UnitTests.java +++ b/src/test/java/com/uniovi/Wiq_UnitTests.java @@ -796,7 +796,7 @@ public void testGetQuestions() throws IOException, InterruptedException, JSONExc ApiKey apiKey = player.getApiKey(); HttpResponse response = sendRequest("GET", "/api/questions", Map.of(), - Map.of("apiKey", apiKey.getKeyToken())); + Map.of("apiKey", apiKey.getKeyToken(), "lang", "es")); Assertions.assertEquals(200, response.statusCode()); JSONObject json = parseJsonResponse(response); @@ -806,18 +806,18 @@ public void testGetQuestions() throws IOException, InterruptedException, JSONExc @Test @Order(50) - public void testGetQuestionsInvalidId() throws IOException, InterruptedException, JSONException { + void testGetQuestionsInvalidId() throws IOException, InterruptedException, JSONException { insertSomeQuestions();; Player player = playerService.getUsersByRole("ROLE_USER").get(0); ApiKey apiKey = player.getApiKey(); - HttpResponse response = sendRequest("GET", "/api/questions", Map.of("id", "notnumeric"), - Map.of("apiKey", apiKey.getKeyToken())); + HttpResponse response = sendRequest("GET", "/api/questions", Map.of(), + Map.of("apiKey", apiKey.getKeyToken(), "id", "notnumeric")); Assertions.assertEquals(200, response.statusCode()); JSONObject json = parseJsonResponse(response); Assertions.assertTrue(json.has("questions")); - Assertions.assertTrue(json.getJSONArray("questions").length() > 0); + Assertions.assertEquals(0, json.getJSONArray("questions").length()); } @Test @@ -874,6 +874,25 @@ public void testGetQuestionById() throws IOException, InterruptedException, JSON Assertions.assertEquals(question.getStatement(), questionJson.getString("statement")); } + @Test + @Order(53) + public void testGetQuestionByStatement() throws IOException, InterruptedException, JSONException { + insertSomeQuestions();; + Player player = playerService.getUsersByRole("ROLE_USER").get(0); + ApiKey apiKey = player.getApiKey(); + Question question = questionService.getAllQuestions().get(0); + + HttpResponse response = sendRequest("GET", "/api/questions", Map.of(), + Map.of("apiKey", apiKey.getKeyToken(), + "statement", question.getStatement())); + + Assertions.assertEquals(200, response.statusCode()); + JSONObject json = parseJsonResponse(response); + JSONObject questionJson = json.getJSONArray("questions").getJSONObject(0); + Assertions.assertEquals(question.getId(), questionJson.getLong("id")); + Assertions.assertEquals(question.getStatement(), questionJson.getString("statement")); + } + @Test @Order(54) void PlayerServiceImpl_addNewPlayer_UsedEmail() {