Skip to content

Commit

Permalink
Do some e2e tests for multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelayori committed Apr 27, 2024
1 parent 95c5c45 commit 2e5230b
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public void testGetQuestions() throws IOException, InterruptedException, JSONExc
ApiKey apiKey = player.getApiKey();

HttpResponse<String> 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);
Expand All @@ -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<String> response = sendRequest("GET", "/api/questions", Map.of("id", "notnumeric"),
Map.of("apiKey", apiKey.getKeyToken()));
HttpResponse<String> 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
Expand Down Expand Up @@ -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<String> 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() {
Expand Down

0 comments on commit 2e5230b

Please sign in to comment.